Add selection tracking to selector with selected and deselected methods
This commit is contained in:
parent
a8c188b24e
commit
72eb93baf7
@ -1,5 +1,6 @@
|
||||
--- @class Selector
|
||||
--- @field id Id | nil
|
||||
--- @field lastId Id | nil
|
||||
--- @field locked boolean
|
||||
local selector = {}
|
||||
selector.__index = selector
|
||||
@ -15,6 +16,7 @@ function selector:select(characterId)
|
||||
end
|
||||
|
||||
function selector:update(dt)
|
||||
self.lastId = self.id
|
||||
if self.locked or not Tree.controls:isJustPressed("select") then return end
|
||||
|
||||
local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
|
||||
@ -53,6 +55,16 @@ function selector:unlock()
|
||||
self.locked = false
|
||||
end
|
||||
|
||||
--- If a character was selected during this tick, returns its Id
|
||||
function selector:selected()
|
||||
if self.id and self.id ~= self.lastId then return self.id end
|
||||
end
|
||||
|
||||
--- If a character was **de**selected during this tick, returns its Id
|
||||
function selector:deselected()
|
||||
if not self.id and self.lastId then return self.lastId end
|
||||
end
|
||||
|
||||
return {
|
||||
new = new
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user