37 lines
950 B
Lua
37 lines
950 B
Lua
--- @class Selector
|
|
--- @field id Id
|
|
local selector = {}
|
|
selector.__index = selector
|
|
|
|
local function new()
|
|
return setmetatable({}, selector)
|
|
end
|
|
|
|
--- @param characterId integer
|
|
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[mousePosition.x][mousePosition.y]
|
|
|
|
self:select(characterId)
|
|
print("я ЖОСКО заселектил ", characterId)
|
|
end
|
|
|
|
return {
|
|
new = new
|
|
}
|