diff options
author | sanine <sanine.not@pm.me> | 2023-09-16 15:07:23 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-09-16 15:07:23 -0500 |
commit | b3f797fdea2f2227f95104a727a13a7a01ba98fa (patch) | |
tree | 23ed480625df3543aa095377c2ca04c8744ef4aa /draw.lua | |
parent | e5daa18bc2aef0a15c6e706d5705f98f9c1fb8ea (diff) |
add legendary actions
Diffstat (limited to 'draw.lua')
-rw-r--r-- | draw.lua | 51 |
1 files changed, 48 insertions, 3 deletions
@@ -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, |