sonic-radiance/sonic-radiance.love/scenes/overworld/actors/gizmo.lua

64 lines
1.8 KiB
Lua
Raw Normal View History

2021-03-20 17:23:14 +01:00
local cwd = (...):gsub('%.gizmo$', '') .. "."
local Parent = require(cwd .. "parent")
local Gizmo = Parent:extend()
2021-03-21 22:02:13 +01:00
local defaultEvent = {
2021-03-20 21:08:54 +01:00
{"simpleMessage", "", "ERROR 000 NO EVENT"},
}
2021-03-20 17:23:14 +01:00
function Gizmo:new(world, x, y, w, h, overrides)
local w = w or 16;
local h = h or 16;
Gizmo.super.new(self, world, "gizmo", x, y, w, h, false)
self.overrides = overrides
self.drawDebugBox = true
2021-03-21 22:02:13 +01:00
self.event = defaultEvent
2021-03-20 17:23:14 +01:00
end
function Gizmo:setProperties(properties)
self:setDefaultProperties()
self:replaceProperties(properties)
if (self.overrides ~= nil) then
self:replaceProperties(self.overrides)
end
self:applyProperties()
end
function Gizmo:applyProperties()
-- Apply properties to the internal item system
self.isSolid = self.properties.isSolid
self.mainHitbox.isSolid = self.properties.isSolid
if (self.isSolid) then
self:addHitbox("btnInput", "btnInput", -1, -1, self.w + 2, self.h + 2, false)
end
self.needButton = self.properties.needButton
2021-03-21 19:21:51 +01:00
self.charId = self.properties.charId or 1
self.charset = self.properties.charset or nil
self.cantTurn = self.properties.cantTurn or self.cantTurn
2021-03-21 22:02:13 +01:00
if (self.properties.event ~= nil) then
local data = require("datas.gamedata.events." .. self.properties.event)
self.event = data.actions
end
2021-03-20 17:23:14 +01:00
end
function Gizmo:setDefaultProperties()
local default = require "game.utils.gizmo.properties"
self.properties = {}
for key, value in pairs(default) do
self.properties[key] = value
end
end
function Gizmo:replaceProperties(properties)
for key, _ in pairs(properties) do
if (properties[key] ~= nil) then
self.properties[key] = properties[key]
end
end
end
function Gizmo:doAction()
2021-03-21 22:02:13 +01:00
self.scene.events:startEvent(self, self.event)
2021-03-20 17:23:14 +01:00
end
return Gizmo;