summaryrefslogtreecommitdiff
path: root/draw.lua
diff options
context:
space:
mode:
Diffstat (limited to 'draw.lua')
-rw-r--r--draw.lua51
1 files changed, 48 insertions, 3 deletions
diff --git a/draw.lua b/draw.lua
index b0aa3b1..af60763 100644
--- a/draw.lua
+++ b/draw.lua
@@ -75,8 +75,8 @@ local function wrap_text(str, max_len, tbl)
-- remove word-end from line
local start = string.find(line, '[^ ]+$')
- local word = string.sub(line, start)
- local line = string.sub(line, 1, start-1)
+ local word = string.sub(line, start or #line)
+ local line = string.sub(line, 1, (start and start-1) or nil)
local rest = word .. string.sub(str, count+1)
table.insert(tbl, line)
return wrap_text(rest, max_len, tbl)
@@ -240,6 +240,13 @@ end
--===== actions =====--
+local function subheader(title)
+ return pad(0, 10, stack(
+ {pad(0, 5, text(title, 25, 'font-variant-caps:small-caps;stroke:black;fill:darkred'))},
+ {divider()}
+ ))
+end
+
local function actions(stats)
if not stats.actions then return empty() end
@@ -248,15 +255,53 @@ local function actions(stats)
table.insert(tbl, {trait(action)})
end
return stack(
+ {subheader('Actions')},
+ unpack(tbl)
+ )
+end
+
+
+local function reactions(stats)
+ if not stats.reactions then return empty() end
+
+ local tbl = {}
+ for _, reaction in ipairs(stats.reactions) do
+ table.insert(tbl, {trait(reaction)})
+ end
+ return stack(
+ {subheader('Reactions')},
+ unpack(tbl)
+ )
+end
+
+
+local function legendary(stats)
+ if not stats.legendary then return empty() end
+
+ local tbl = {}
+ for _, action in ipairs(stats.legendary) do
+ table.insert(tbl, {trait(action)})
+ end
+ return stack(
+ {subheader('Legendary Actions')},
+ {pad(0, 10, wrapped_text(stats.legendary.description, 80, 10, 14, 2, ''))},
unpack(tbl)
)
end
+
+
--===== draw =====--
function draw(stats)
- local f, h = stack({base(stats)}, {traits(stats)}, {actions(stats)})
+ local f, h = stack(
+ {base(stats)},
+ {traits(stats)},
+ {actions(stats)},
+ {reactions(stats)},
+ {legendary(stats)}
+ )
return m.render(m.svg{
viewBox = string.format("0 0 500 %d", h),
width = 500,