From 83115e82f8edf50e03381dfbd6fcb19da82b3179 Mon Sep 17 00:00:00 2001 From: PeaAshMeter Date: Sun, 12 Oct 2025 00:17:15 +0300 Subject: [PATCH] fix selection during a cast --- lib/level/selector.lua | 16 +++++++++------- lib/spellbook.lua | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/level/selector.lua b/lib/level/selector.lua index 8305a3e..5e0a3c2 100644 --- a/lib/level/selector.lua +++ b/lib/level/selector.lua @@ -10,9 +10,9 @@ end --- @param characterId integer | nil function selector:select(characterId) self.id = characterId + print("[Selector]:", characterId and "selected " .. characterId or "deselected") end ---- TODO: сделать обработчик селектора function selector:update(dt) if not Tree.controls:isJustPressed("select") then return end @@ -21,19 +21,21 @@ function selector:update(dt) if mousePosition.x >= Tree.level.size.x or mousePosition.y >= Tree.level.size.y or mousePosition.y < 0 or mousePosition.x < 0 then return end - local characterId = Tree.level.characterGrid:get(Vec3 { mousePosition.x, mousePosition.y }) + local selectedId = Tree.level.characterGrid:get(Vec3 { mousePosition.x, mousePosition.y }) - if not characterId and self.id then -- Когда кликаем по тайлу за персонажа в режиме каста, кастуем спелл + if not self.id then + return self:select(selectedId) + else local char = Tree.level.characters[self.id] char:try(Tree.behaviors.spellcaster, function(b) - if not b.cast then return end + if not b.cast then + self:select(selectedId) + return + end b.cast:cast(char, mousePosition) b.cast = nil end) end - self:select(characterId) - - print("[Selector]:", mousePosition, characterId and "selected " .. characterId or "deselected") end return { diff --git a/lib/spellbook.lua b/lib/spellbook.lua index 0854045..55e227a 100644 --- a/lib/spellbook.lua +++ b/lib/spellbook.lua @@ -18,10 +18,13 @@ local walk = setmetatable({ function walk:cast(caster, target) local path = self.path + if path:is_empty() then return end path:pop_front() print("Following path: ") for p in path:values() do print(p) end caster:has(Tree.behaviors.map):followPath(path) + -- TODO: списать деньги за каст (антиутопия какая-то) + -- TODO: привязка тинькоффа end function walk:update(caster, dt)