Skip to content

Commit

Permalink
more work towards luacheck being able to be used in the automated builds
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed Mar 9, 2020
1 parent a0d097f commit c87df78
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
26 changes: 17 additions & 9 deletions library/lua/dfhack/workshops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local _ENV = mkmodule('dfhack.workshops')

local utils = require 'utils'

--luacheck:global
input_filter_defaults = {
item_type = -1,
item_subtype = -1,
Expand All @@ -24,7 +25,12 @@ input_filter_defaults = {
quantity = 1
}
local fuel={item_type=df.item_type.BAR,mat_type=df.builtin_mats.COAL}
jobs_furnace={

-- typedef for luacheck
local workshop_job = {} --as:{_type:workshop_job,name:string,items:'input_filter_defaults[]',job_fields:none}

--luacheck:global
jobs_furnace={ --as:workshop_job[][]
[df.furnace_type.Smelter]={
{
name="Melt metal object",
Expand Down Expand Up @@ -85,7 +91,8 @@ jobs_furnace={
}
},
}
jobs_workshop={
--luacheck:global
jobs_workshop={ --as:workshop_job[][]

[df.workshop_type.Jewelers]={
{
Expand Down Expand Up @@ -398,7 +405,7 @@ jobs_workshop={
},
},
[df.workshop_type.Leatherworks]={
defaults={item_type=SKIN_TANNED},
defaults={item_type=df.item_type.SKIN_TANNED},
{
name="construct leather bag",
items={{}},
Expand Down Expand Up @@ -475,7 +482,7 @@ local function matchIds(bid1,wid1,cid1,bid2,wid2,cid2)
return true
end
local function scanRawsReaction(buildingId,workshopId,customId)
local ret={}
local ret={} --as:df.reaction[]
for idx,reaction in ipairs(df.global.world.raws.reactions.reactions) do
for k,v in pairs(reaction.building.type) do
if matchIds(buildingId,workshopId,customId,v,reaction.building.subtype[k],reaction.building.custom[k]) then
Expand All @@ -495,7 +502,7 @@ end
local function addReactionJobs(ret,bid,wid,cid)
local reactions=scanRawsReaction(bid,wid or -1,cid or -1)
for idx,react in pairs(reactions) do
local job={name=react.name,
local job={name=react.name, --as:workshop_job
items={},job_fields={job_type=df.job_type.CustomReaction,reaction_name=react.code}
}
for reagentId,reagent in pairs(react.reagents) do
Expand All @@ -521,7 +528,8 @@ local function addSmeltJobs(ret,use_fuel)
for idx,ore in pairs(ores) do
print("adding:",ore.material.state_name.Solid)
printall(ore)
local job={name="smelt "..ore.material.state_name.Solid,job_fields={job_type=df.job_type.SmeltOre,mat_type=df.builtin_mats.INORGANIC,mat_index=idx},items={
local job={ --as:workshop_job
name="smelt "..ore.material.state_name.Solid,job_fields={job_type=df.job_type.SmeltOre,mat_type=df.builtin_mats.INORGANIC,mat_index=idx},items={
{item_type=df.item_type.BOULDER,mat_type=df.builtin_mats.INORGANIC,mat_index=idx,vector_id=df.job_item_vector_id.BOULDER}}}
if use_fuel then
table.insert(job.items,fuel)
Expand All @@ -531,8 +539,7 @@ local function addSmeltJobs(ret,use_fuel)
return ret
end
function getJobs(buildingId,workshopId,customId)
local ret={}
local c_jobs
local c_jobs = {} --as:workshop_job[]
if buildingId==df.building_type.Workshop then
c_jobs=jobs_workshop[workshopId]
elseif buildingId==df.building_type.Furnace then
Expand All @@ -551,10 +558,11 @@ function getJobs(buildingId,workshopId,customId)
c_jobs=utils.clone(c_jobs,true)
end

local ret = {} --as:c_jobs
addReactionJobs(c_jobs,buildingId,workshopId,customId)
for jobId,contents in pairs(c_jobs) do
if jobId~="defaults" then
local entry={}
local entry={} --as:workshop_job
entry.name=contents.name
local lclDefaults=utils.clone(input_filter_defaults,true)
if c_jobs.defaults ~=nil then
Expand Down
8 changes: 5 additions & 3 deletions library/lua/gui/buildings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ WORKSHOP_SPECIAL={
[df.building_type.Workshop]=true,[df.building_type.Furnace]=true,[df.building_type.Trap]=true,
[df.building_type.Construction]=true,[df.building_type.SiegeEngine]=true
}
--luacheck:defclass={prompt:string,frame_style:number,frame_inset:number,frame_title:string,none_caption:string,hide_none:bool,use_abstract:bool,use_workshops:bool,use_tool_workshop:bool,use_furnace:bool,use_construction:bool,use_siege:bool,use_trap:bool,use_custom:bool,building_filter:{_type:function,_anyfunc:true},on_select:{_type:function,_anyfunc:true},on_cancel:{_type:function,_anyfunc:true},on_close:{_type:function,_anyfunc:true},back_stack:'{_type:table,context_str:string,all_choices:table,edit_text:string,selected:number}[]'}
BuildingDialog = defclass(BuildingDialog, gui.FramedScreen)

BuildingDialog.focus_path = 'BuildingDialog'
Expand Down Expand Up @@ -229,16 +230,17 @@ function BuildingDialog:pushContext(name, choices)
end

self.context_str = name
self.subviews.list:setChoices(choices, 1)
self.subviews.list:setChoices(choices, 1) --hint:widgets.FilteredList
end

function BuildingDialog:onGoBack()
local save = table.remove(self.back_stack)
self.subviews.back.visible = (#self.back_stack > 0)

self.context_str = save.context_str
self.subviews.list:setChoices(save.all_choices)
self.subviews.list:setFilter(save.edit_text, save.selected)
local list = self.subviews.list --as:widgets.FilteredList
list:setChoices(save.all_choices)
list:setFilter(save.edit_text, save.selected)
end

function BuildingDialog:submitBuilding(type_id,subtype_id,custom_id,choice,index)
Expand Down
17 changes: 10 additions & 7 deletions library/lua/gui/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ end
-----------

function parse_label_text(obj)
local text = obj.text or {}
if type(text) ~= 'table' then
local text = obj.text or {} --as:string[]
if type(text) ~= 'table' then --luacheck:skip
text = { text }
end
local curline = nil
Expand All @@ -190,7 +190,7 @@ function parse_label_text(obj)
local vv
if type(v) == 'string' then
vv = utils.split_string(v, NEWLINE)
else
else --luacheck:skip
vv = { v }
end

Expand Down Expand Up @@ -343,7 +343,7 @@ function check_text_keys(self, keys)
end
end

--luacheck: defclass={text_lines:'{_type:table,text:string,gap:number,tile:dfhack.pen,key:string,key_pen:number,pen:dfhack.pen,dpen:dfhack.pen,disabled:bool,enabled:bool,width:number,pad_char:string,rjustify:bool,key_sep:string,on_activate:\'anyfunc:none\'}[][]',on_click:'anyfunc:none',on_rclick:'anyfunc:none',text_hpen:number,text_active:Label.text_lines._array}
--luacheck: defclass={text_lines:'{_type:table,text:string,gap:number,tile:dfhack.pen,key:string,key_pen:number,pen:dfhack.pen,dpen:dfhack.pen,disabled:bool,enabled:bool,width:number,pad_char:string,rjustify:bool,key_sep:string,on_activate:\'anyfunc:none\'}[][]',on_click:'anyfunc:none',on_rclick:'anyfunc:none',text_hpen:number,text_active:Label.text_lines._array,text_ids:Label.text_lines._array}
Label = defclass(Label, Widget)

Label.ATTRS{
Expand Down Expand Up @@ -465,11 +465,13 @@ end
function List:setChoices(choices, selected)
self.choices = {}

for i,v in ipairs(choices or {}) do
local choices = choices or {} --as:List.choices

for i,v in ipairs(choices) do
local l = utils.clone(v);
if type(v) ~= 'table' then
l = { text = v }
else
else --luacheck:skip
l.text = v.text or v.caption or v[1]
end
parse_label_text(l)
Expand Down Expand Up @@ -664,7 +666,7 @@ end
-- Filtered List --
-------------------

--luacheck: defclass={edit:EditField,list:List,edit_key:string}
--luacheck: defclass={edit:EditField,list:List,edit_key:string,not_found:Label}
FilteredList = defclass(FilteredList, Widget)

FilteredList.ATTRS {
Expand Down Expand Up @@ -784,6 +786,7 @@ function FilteredList:getFilter()
return self.edit.text, self.list.choices
end

--luacheck:skip
function FilteredList:setFilter(filter, pos)
local choices = self.choices
local cidx = nil
Expand Down
1 change: 1 addition & 0 deletions library/lua/plugins
2 changes: 1 addition & 1 deletion travis/df-luacheck
Submodule df-luacheck updated 3 files
+172 −150 builtins_base.js
+35 −8 index.js
+2 −2 luacheck.sh

0 comments on commit c87df78

Please sign in to comment.