@@ -6,8 +6,8 @@ local _ENV = mkmodule('plugins.building-hacks')
66 setUpdateSkip(workshop_type,int=0)
77 setMachineInfo(workshop_type,bool need_power,int consume=0,int produce=0,table connection_points)
88 fixImpassible(workshop_type)
9- getPower(building) -- 2 or 0 returns, produced and consumed
10- setPower(building,produced, consumed)
9+ getPower(building) -- 2 or 0 returns, consumed and produced
10+ setPower(building, consumed, produced )
1111 from here:
1212 setMachineInfoAuto(name,int consume,int produce,bool need_power)
1313 setAnimationInfoAuto(name,bool make_graphics_too)
@@ -59,37 +59,28 @@ local function registerUpdateAction(shopId,callback)
5959 onUpdateAction ._library = onUpdateLocal
6060 dfhack .onStateChange .building_hacks = unregall
6161end
62- -- take in tiles with {x=?, y=? ,...} and output a table flat sparse 31x31 table
63- local function generateFrame (tiles , w , h )
62+ -- take in tiles with {x=?, y=? ,...} and output a table in format needed for setAnimationInfo
63+ local function generateFrame (tiles )
6464 local mTiles = {}
6565 local ret = {}
6666 for k ,v in ipairs (tiles ) do
67- ret [ v .x + v .y * 31 ]= v
67+ ensure_key ( ret , v .x )[ v .y ]= v
6868 end
6969 return ret
7070end
71- -- convert frames to flat arrays if needed
72- local function processFrames (shop_def ,frames )
73- local w ,h = shop_def .dim_x ,shop_def .dim_y
74- for frame_id ,frame in ipairs (frames ) do
75- if frame [1 ].x ~= nil then
76- frames [frame_id ]= generateFrame (frame ,w ,h )
77- end
78- end
79- return frames
80- end
71+
8172-- locate gears on the workshop from the raws definition
8273local function findGears ( shop_def ,gear_tiles ) -- finds positions of all gears and inverted gears
83- gear_tiles = gear_tiles or {42 ,15 }
74+ gear_tiles = gear_tiles or {ch = 42 ,ch_alt = 15 }
8475 local w ,h = shop_def .dim_x ,shop_def .dim_y
8576 local stage = shop_def .build_stages
8677 local ret = {}
8778 for x = 0 ,w - 1 do
8879 for y = 0 ,h - 1 do
8980 local tile = shop_def .tile [stage ][x ][y ]
90- if tile == gear_tiles [ 1 ] then -- gear icon
81+ if tile == gear_tiles . ch then -- gear icon
9182 table.insert (ret ,{x = x ,y = y ,invert = false })
92- elseif tile == gear_tiles [ 2 ] then -- inverted gear icon
83+ elseif tile == gear_tiles . ch_alt then -- inverted gear icon
9384 table.insert (ret ,{x = x ,y = y ,invert = true })
9485 end
9586 end
@@ -105,34 +96,33 @@ local function lookup_color( shop_def,x,y,stage )
10596end
10697-- adds frames for all gear icons and inverted gear icons
10798local function processFramesAuto ( shop_def ,gears ,auto_graphics ,gear_tiles )
108- gear_tiles = gear_tiles or {42 ,15 ,graphics_cache [1 ],graphics_cache [2 ]}
109- local w ,h = shop_def .dim_x ,shop_def .dim_y
99+ gear_tiles = gear_tiles or {ch = 42 ,ch_alt = 15 ,tile = graphics_cache [1 ],tile_alt = graphics_cache [2 ]}
110100 local frames = {{},{}} -- two frames only
111101 local stage = shop_def .build_stages
112102
113103 for i ,v in ipairs (gears ) do
114104
115105 local tile ,tile_inv
116106 if v .inverted then
117- tile = gear_tiles [ 1 ]
118- tile_inv = gear_tiles [ 2 ]
107+ tile = gear_tiles . ch
108+ tile_inv = gear_tiles . ch_alt
119109 else
120- tile = gear_tiles [ 2 ]
121- tile_inv = gear_tiles [ 1 ]
110+ tile = gear_tiles . ch_alt
111+ tile_inv = gear_tiles . ch
122112 end
123113
124- table.insert (frames [1 ],{x = v .x ,y = v .y ,tile ,lookup_color (shop_def ,v .x ,v .y ,stage )})
125- table.insert (frames [2 ],{x = v .x ,y = v .y ,tile_inv ,lookup_color (shop_def ,v .x ,v .y ,stage )})
114+ table.insert (frames [1 ],{x = v .x ,y = v .y ,ch = tile ,fg = lookup_color (shop_def ,v .x ,v .y ,stage )})
115+ table.insert (frames [2 ],{x = v .x ,y = v .y ,ch = tile_inv ,fg = lookup_color (shop_def ,v .x ,v .y ,stage )})
126116
127117 -- insert default gear graphics if auto graphics is on
128118 if auto_graphics then
129- frames [1 ][# frames [1 ]][ 5 ] = gear_tiles [ 3 ]
130- frames [2 ][# frames [2 ]][ 5 ] = gear_tiles [ 4 ]
119+ frames [1 ][# frames [1 ]]. tile = gear_tiles . tile
120+ frames [2 ][# frames [2 ]]. tile = gear_tiles . tile_alt
131121 end
132122 end
133123
134124 for frame_id ,frame in ipairs (frames ) do
135- frames [frame_id ]= generateFrame (frame , w , h )
125+ frames [frame_id ]= generateFrame (frame )
136126 end
137127 return frames
138128end
0 commit comments