neckrat d2caa40a0a feat: manapool (kind of bad manapool)
Co-authored-by: Ivan Yuriev <peaashmeter@users.noreply.github.com>
2025-10-12 23:41:16 +03:00

58 lines
2.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local Vec3 = require "lib.utils.vec3"
local ui = require "lib.ui.core"
--- @class SkillButton : Rectangle
--- @field owner Character
--- @field spellId number
local SkillButton = ui.Rectangle {
size = Vec3 { 100, 100 },
color = { 1, 0, 0 },
}
function SkillButton:update(dt)
ui.Rectangle.update(self, dt)
self.owner:try(Tree.behaviors.spellcaster, function(spellcaster)
self.color = spellcaster.state == "casting" and { 0, 1, 0 } or { 1, 0, 0 }
self:onTap(function()
if not spellcaster.cast then
spellcaster.cast = spellcaster.spellbook
[self.spellId]
spellcaster.state = "casting"
else
spellcaster.state = "idle"
spellcaster.cast = nil
end
end)
end)
end
local skillRows = {}
local layout = {}
function layout:build()
return ui.Root {
child = ui.Align {
alignment = "bottom_center",
child =
--- для каждого персонажа строим свой ряд скиллов, сохраняем его на потом и возвращаем
--- если персонаж не выделен, не возвращаем ничего
(function()
local id = Tree.level.selector.id
if not id then return nil end
if skillRows[id] then return skillRows[id] end
local r =
ui.Row {
children = {
setmetatable({ owner = Tree.level.characters[id], spellId = 1 }, { __index = SkillButton }),
setmetatable({ owner = Tree.level.characters[id], spellId = 2 }, { __index = SkillButton })
}
}
skillRows[id] = r
return r
end)()
}
}
end
return layout