Skip to content

Commit 91a06d3

Browse files
committed
devel/dflayout: provide Demo type
Makes explicit the fields required from each "demo". Remove demo_available(), just use demo.available() directly. ("Always available if .available is nil" seems a bit awkward)
1 parent 8812284 commit 91a06d3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

devel/dflayout.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ local utils = require('utils')
55

66
--- Demo Control Window and Screen ---
77

8-
local function demo_available(demo)
9-
if not demo.available then return true end
10-
return demo.available()
11-
end
8+
---@class Demo
9+
---@field text string text displayed in main window demo list
10+
---@field available fun(): boolean? return true if demo is available in current context
11+
---@field active? boolean whether the main window has enabled this demo (managed by main window)
12+
---@field views gui.View[] list of views to add to main ZScreen
13+
---@field update fun() called by main window to recompute demo frames
1214

1315
local visible_when_not_focused = true
1416
function visible()
@@ -26,6 +28,7 @@ DemoWindow.ATTRS{
2628
autoarrange_gap = 1,
2729
}
2830

31+
---@param args { demos: Demo[] }
2932
function DemoWindow:init(args)
3033
self.demos = args.demos
3134
self:addviews{
@@ -43,7 +46,7 @@ function DemoWindow:init(args)
4346
icon_width = 3,
4447
on_submit = function(index, item)
4548
local demo = self.demos[index]
46-
demo.active = demo_available(demo) and not demo.active
49+
demo.active = demo.available() and not demo.active
4750
self:refresh()
4851
end
4952
},
@@ -56,7 +59,7 @@ function DemoWindow:refresh()
5659
local choices = {}
5760
for _, demo in ipairs(self.demos) do
5861
local icon
59-
if not demo_available(demo) then
62+
if not demo.available() then
6063
icon = '-'
6164
elseif demo.active then
6265
icon = CHECK
@@ -117,6 +120,7 @@ end
117120

118121
--- Fort Toolbar Demo ---
119122

123+
---@class FortToolbarsDemo: Demo
120124
local fort_toolbars_demo = {
121125
text = 'fort toolbars',
122126
available = dfhack.world.isFortressMode,

0 commit comments

Comments
 (0)