feat: add way to destroy gizmos

This commit is contained in:
Kazhnuz 2021-03-22 19:01:18 +01:00
parent 50838c3982
commit ddc1933b40
2 changed files with 19 additions and 0 deletions

View file

@ -1,4 +1,5 @@
return { return {
isSolid = false, isSolid = false,
needButton = true, -- "useButton" or "onContact" needButton = true, -- "useButton" or "onContact"
destroy = "none",
} }

View file

@ -15,6 +15,10 @@ function Gizmo:new(world, x, y, w, h, overrides)
self.event = defaultEvent self.event = defaultEvent
end end
function Gizmo:getUniqueId()
return "gizmo" .. ":" .. self.mapname .. ":" .. self.x .. ":" .. self.y
end
function Gizmo:setProperties(properties) function Gizmo:setProperties(properties)
self:setDefaultProperties() self:setDefaultProperties()
self:replaceProperties(properties) self:replaceProperties(properties)
@ -39,6 +43,10 @@ function Gizmo:applyProperties()
local data = require("datas.gamedata.events." .. self.properties.event) local data = require("datas.gamedata.events." .. self.properties.event)
self.event = data.actions self.event = data.actions
end end
self.uniqueId = self:getUniqueId()
if (game.destroyedGizmo[self.uniqueId] == true) then
self:destroy()
end
end end
function Gizmo:setDefaultProperties() function Gizmo:setDefaultProperties()
@ -58,6 +66,16 @@ function Gizmo:replaceProperties(properties)
end end
function Gizmo:doAction() 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) self.scene.events:startEvent(self, self.event)
end end