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
|
--- @class Selector
|
||||||
--- @field id Id | nil
|
--- @field id Id | nil
|
||||||
|
--- @field lastId Id | nil
|
||||||
--- @field locked boolean
|
--- @field locked boolean
|
||||||
local selector = {}
|
local selector = {}
|
||||||
selector.__index = selector
|
selector.__index = selector
|
||||||
@ -15,6 +16,7 @@ function selector:select(characterId)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function selector:update(dt)
|
function selector:update(dt)
|
||||||
|
self.lastId = self.id
|
||||||
if self.locked or not Tree.controls:isJustPressed("select") then return end
|
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()
|
local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
|
||||||
@ -53,6 +55,16 @@ function selector:unlock()
|
|||||||
self.locked = false
|
self.locked = false
|
||||||
end
|
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 {
|
return {
|
||||||
new = new
|
new = new
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user