PeaAshMeter bab4b006ca перемещение персонажа по нажатию на кнопку
- я официально в тильте отэкспериментов с ui, щас возьму и напишу лютейшую императивщину
2025-09-04 02:01:25 +03:00

50 lines
1.5 KiB
Lua

--- @class Selector
--- @field id Id | nil
local selector = {}
selector.__index = selector
local function new()
return setmetatable({}, selector)
end
--- @param characterId integer | nil
function selector:select(characterId)
self.id = characterId
end
-- function selector:deselect()
-- self.id = nil
-- end
--- TODO: сделать обработчик селектора
function selector:update(dt)
if not Tree.controls:isJustPressed("select") then return end
local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
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 })
if not characterId and self.id then -- временная обработка события "побежать к точке"
local char = Tree.level.characters[self.id]
if char.cast then
char.cast = false
local charPos = char.logic.mapLogic.position
local path = (require "lib.pathfinder")(charPos, mousePosition)
path:pop_front()
print("Following path: ")
for p in path:values() do print(p) end
char:followPath(path)
end
end
self:select(characterId)
print("[Selector]:", mousePosition, characterId and "selected " .. characterId or "deselected")
end
return {
new = new
}