feat: add way to destroy gizmos
This commit is contained in:
parent
50838c3982
commit
ddc1933b40
2 changed files with 19 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
return {
|
||||
isSolid = false,
|
||||
needButton = true, -- "useButton" or "onContact"
|
||||
destroy = "none",
|
||||
}
|
|
@ -15,6 +15,10 @@ function Gizmo:new(world, x, y, w, h, overrides)
|
|||
self.event = defaultEvent
|
||||
end
|
||||
|
||||
function Gizmo:getUniqueId()
|
||||
return "gizmo" .. ":" .. self.mapname .. ":" .. self.x .. ":" .. self.y
|
||||
end
|
||||
|
||||
function Gizmo:setProperties(properties)
|
||||
self:setDefaultProperties()
|
||||
self:replaceProperties(properties)
|
||||
|
@ -39,6 +43,10 @@ function Gizmo:applyProperties()
|
|||
local data = require("datas.gamedata.events." .. self.properties.event)
|
||||
self.event = data.actions
|
||||
end
|
||||
self.uniqueId = self:getUniqueId()
|
||||
if (game.destroyedGizmo[self.uniqueId] == true) then
|
||||
self:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
function Gizmo:setDefaultProperties()
|
||||
|
@ -58,6 +66,16 @@ function Gizmo:replaceProperties(properties)
|
|||
end
|
||||
|
||||
function Gizmo:doAction()
|
||||
self:action()
|
||||
if (self.properties.destroy ~= "none") then
|
||||
if (self.properties.destroy == "forever") then
|
||||
game.destroyedGizmo[self.uniqueId] = true
|
||||
end
|
||||
self:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
function Gizmo:action()
|
||||
self.scene.events:startEvent(self, self.event)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue