IAmCheeseman / love-rich-text

A simple library to use rich text effects in Love2D.
MIT License
6 stars 1 forks source link

Allow passing arguments to text object #5

Open IAmCheeseman opened 7 months ago

IAmCheeseman commented 7 months ago

An API to add arguments that every effect in the text object can access.

local sword = {
  damage = 12,
  cooldown = 2,
}

-- We can make effects to have some nice formatting
RichText.addInsertionEffect("damage", function(text, str, args)
  return "{color r=0.5 g=0, b=0}" .. text.args.sword.damage .. "{/color}"
end)

-- Then, apply like:
local format = [[
My weapon does {damage/} damage!
]]
local text = RichText.new(font, format, {sword=sword})
-- (would need formatting support)