Skip to content

Commit 31d0655

Browse files
committed
docs: yet another day, yet another doc update. Also improved optional args for gear char/tile
1 parent 217c198 commit 31d0655

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

docs/dev/Lua API.rst

+29-13
Original file line numberDiff line numberDiff line change
@@ -6574,7 +6574,7 @@ Functions
65746574
Each frame tile is table of with following optional members: ``ch``, ``fg``,
65756575
``bg``, ``bold``, ``tile``, ``tile_overlay``, ``tile_signpost``, ``tile_item``.
65766576
First 4 are function same as ascii workshop definition. The latter 4 are graphics
6577-
layers. ``tile_signpost `` is only valid in first row and it shows up above the workshop.
6577+
layers. ``tile_signpost`` is only valid in first row and it shows up above the workshop.
65786578

65796579
:frame_skip: How many ticks to display one frame. If set to negative number, zero or skipped, frames
65806580
are synchronized with machine animation.
@@ -6588,8 +6588,9 @@ Functions
65886588
:make_graphics_too: replace same tiles in graphics mode with tiles from vanilla df mechanism
65896589
:frame_length: How many ticks to display one frame. If set to negative number, zero or skipped, frames
65906590
are synchronized with machine animation.
6591-
:gear_tiles: Optional table with of 2 or 4 indexes. First two define ascii tiles and next two graphics tiles.
6592-
This overrides default gear tiles.
6591+
:gear_tiles: Optional table with ``ch``, ``ch_alt``, ``tile``, ``tile_alt``. First two are ascii
6592+
gear tiles and are used to find tiles in workshop raw and animate them. Second two are
6593+
used to animate graphical tiles.
65936594

65946595
* ``setOnUpdate(workshop_type, interval, callback)``
65956596

@@ -6638,20 +6639,35 @@ Examples
66386639
Simple mechanical workshop::
66396640

66406641
local bhacks = require('plugins.building-hacks')
6641-
--work only powered, consume 15 power and one connection point at 0,0
6642-
bhacks.setMachineInfo("BONE_GRINDER",true,15,0,{{x=0,y=0}})
6643-
--set animation to switch between gear tiles at 0,0
6644-
bhacks.setAnimationInfo("BONE_GRINDER",{
6645-
{[0]={42,7,0,0}}, --first frame, 1 changed tile
6646-
{[0]={15,7,0,0}} -- second frame, same
6647-
}
6648-
)
6642+
6643+
--work only powered, consume 15 power and one connection point at 0, 0
6644+
bhacks.setMachineInfo("BONE_GRINDER", true, 15, 0, {{x=0, y=0}})
6645+
6646+
--load custom graphical tiles for use if graphics is enabled
6647+
local tile1=dfhack.screen.findGraphicsTile('DRAGON_ENGINE_TILES', 0, 0)
6648+
local tile2=dfhack.screen.findGraphicsTile('DRAGON_ENGINE_TILES', 1, 0)
6649+
6650+
local frames={}
6651+
--first frame - tile (1, 1) changed to character 42
6652+
ensure_key(frames, 1, 1)[1]={ch=42, fg=7, bg=0, bold=0, tile=tile1}
6653+
--second frame - tile (1,1) changed to character 15
6654+
ensure_key(frames, 2, 1)[1]={ch=15, fg=7, bg=0, bold=0, tile=tile2}
6655+
6656+
--set animation to switch between gear tiles at 1,1
6657+
bhacks.setAnimationInfo("BONE_GRINDER", frames)
66496658

66506659
Or with auto_gears::
66516660

66526661
local bhacks = require('plugins.building-hacks')
6653-
bhacks.setMachineInfoAuto("BONE_GRINDER",true,15)
6654-
bhacks.setAnimationInfoAuto("BONE_GRINDER",true)
6662+
6663+
--load custom graphical tiles for use if graphics is enabled
6664+
local tile1=dfhack.screen.findGraphicsTile('DRAGON_ENGINE_TILES', 0, 0)
6665+
local tile2=dfhack.screen.findGraphicsTile('DRAGON_ENGINE_TILES', 1, 0)
6666+
6667+
--work only powered, consume 15 power and find connection point from building raws
6668+
bhacks.setMachineInfoAuto("BONE_GRINDER", true, 15)
6669+
--set animation to switch between default ascii gears and specific graphic tiles loaded above
6670+
bhacks.setAnimationInfoAuto("BONE_GRINDER", true, -1, {tile=tile1, tile_alt=tile2})
66556671

66566672
buildingplan
66576673
============

plugins/lua/building-hacks.lua

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ local _ENV = mkmodule('plugins.building-hacks')
1515
]]
1616

1717
_registeredStuff={}
18+
19+
local CHAR_GEAR=42
20+
local CHAR_GEAR_ALT=15
21+
1822
--cache graphics tiles for mechanical gears
1923
local graphics_cache
2024
function reload_graphics_cache( )
@@ -71,7 +75,7 @@ end
7175

7276
--locate gears on the workshop from the raws definition
7377
local function findGears( shop_def ,gear_tiles) --finds positions of all gears and inverted gears
74-
gear_tiles=gear_tiles or {ch=42,ch_alt=15}
78+
gear_tiles=gear_tiles or {ch=CHAR_GEAR,ch_alt=CHAR_GEAR_ALT}
7579
local w,h=shop_def.dim_x,shop_def.dim_y
7680
local stage=shop_def.build_stages
7781
local ret={}
@@ -96,28 +100,28 @@ local function lookup_color( shop_def,x,y,stage )
96100
end
97101
--adds frames for all gear icons and inverted gear icons
98102
local function processFramesAuto( shop_def ,gears,auto_graphics,gear_tiles)
99-
gear_tiles=gear_tiles or {ch=42,ch_alt=15,tile=graphics_cache[1],tile_alt=graphics_cache[2]}
103+
gear_tiles=gear_tiles or {ch=CHAR_GEAR,ch_alt=CHAR_GEAR_ALT,tile=graphics_cache[1],tile_alt=graphics_cache[2]}
100104
local frames={{},{}} --two frames only
101105
local stage=shop_def.build_stages
102106

103107
for i,v in ipairs(gears) do
104108

105109
local tile,tile_inv
106110
if v.inverted then
107-
tile=gear_tiles.ch
108-
tile_inv=gear_tiles.ch_alt
111+
tile=gear_tiles.ch or CHAR_GEAR
112+
tile_inv=gear_tiles.ch_alt or CHAR_GEAR_ALT
109113
else
110-
tile=gear_tiles.ch_alt
111-
tile_inv=gear_tiles.ch
114+
tile=gear_tiles.ch_alt or CHAR_GEAR_ALT
115+
tile_inv=gear_tiles.ch or CHAR_GEAR
112116
end
113117

114118
table.insert(frames[1],{x=v.x,y=v.y,ch=tile,fg=lookup_color(shop_def,v.x,v.y,stage)})
115119
table.insert(frames[2],{x=v.x,y=v.y,ch=tile_inv,fg=lookup_color(shop_def,v.x,v.y,stage)})
116120

117121
--insert default gear graphics if auto graphics is on
118122
if auto_graphics then
119-
frames[1][#frames[1]].tile=gear_tiles.tile
120-
frames[2][#frames[2]].tile=gear_tiles.tile_alt
123+
frames[1][#frames[1]].tile=gear_tiles.tile or graphics_cache[1]
124+
frames[2][#frames[2]].tile=gear_tiles.tile_alt or graphics_cache[2]
121125
end
122126
end
123127

0 commit comments

Comments
 (0)