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

86 lines
2.5 KiB
Lua
Raw Normal View History

2021-04-10 14:43:30 +02:00
local Parent = require "scenes.overworld.actors.parent"
2021-03-20 17:23:14 +01:00
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 = false
2021-03-21 22:02:13 +01:00
self.event = defaultEvent
self.interactionName = "Talk"
2021-03-20 17:23:14 +01:00
end
2021-03-22 19:01:18 +01:00
function Gizmo:getUniqueId()
return "gizmo" .. ":" .. self.mapname .. ":" .. self.x .. ":" .. self.y
end
2021-03-20 17:23:14 +01:00
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
2021-05-07 11:56:44 +02:00
self:addHitbox("btnInput", "btnInput", {-1, -1, self.w + 2, self.h + 2}, false)
2021-03-20 17:23:14 +01:00
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
2021-03-22 19:21:27 +01:00
self.charDir = self.properties.charDir or "down"
2021-03-21 19:21:51 +01:00
self.cantTurn = self.properties.cantTurn or self.cantTurn
2021-03-22 21:04:55 +01:00
self.isTurning = (self.properties.isTurning == true)
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-22 19:01:18 +01:00
self.uniqueId = self:getUniqueId()
if (game.destroyedGizmo[self.uniqueId] == true) then
self:destroy()
end
self.interactionName = self.properties.interactionName or self.interactionName
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-22 19:01:18 +01:00
self:action()
2021-04-05 16:29:51 +02:00
if (self.properties.destroy == "forever") then
game.destroyedGizmo[self.uniqueId] = true
self:destroy()
end
if (self.properties.destroy == "temp") then
2021-03-22 19:01:18 +01:00
self:destroy()
end
end
function Gizmo:action()
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;