summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-09-16 15:07:23 -0500
committersanine <sanine.not@pm.me>2023-09-16 15:07:23 -0500
commitb3f797fdea2f2227f95104a727a13a7a01ba98fa (patch)
tree23ed480625df3543aa095377c2ca04c8744ef4aa
parente5daa18bc2aef0a15c6e706d5705f98f9c1fb8ea (diff)
add legendary actions
-rwxr-xr-xdemo.lua5
-rw-r--r--draw.lua51
2 files changed, 53 insertions, 3 deletions
diff --git a/demo.lua b/demo.lua
index a855cbc..17ec5dd 100755
--- a/demo.lua
+++ b/demo.lua
@@ -35,6 +35,11 @@ local stats = {
actions = {
{ name='Warhammer', value="*Melee Weapon Attack:* +5 to hit, reach 5 ft., one target. *Hit:* 7 (1d8 + 3) bludgeoning damage or 8 (1d10 + 3) bludgeoning damage if used with two hands to make a melee attack, plus 3 (1d6) fire damage." },
},
+
+ legendary = {
+ description = "The death tyrant can take 3 legendary actions, using the Eye Ray option below. It can take only one legendary action at a time and only at the end of another creature's turn. The tyrant regains spent legendary actions at the start of its turn.",
+ { name='Eye Ray', value='The death tyrant uses one random eye ray.' },
+ },
}
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,