SCED/src/util/TokenRemover.ttslua
2023-01-06 10:25:38 +01:00

53 lines
1.2 KiB
Plaintext

local zone = nil
local tokenChecker = require("core/token/TokenChecker")
-- general code
function onSave()
return JSON.encode(zone and zone.getGUID() or nil)
end
function onLoad(savedData)
if savedData ~= "" and savedData ~= nil then
zone = getObjectFromGUID(JSON.decode(savedData))
end
setMenu(zone == nil)
end
-- context menu functions
function enable()
local scale = self.getScale()
zone = spawnObject({
type = "ScriptingTrigger",
position = self.getPosition() + Vector(0, 2.5 + 0.11, 0),
rotation = self.getRotation(),
scale = { scale.x * 2, 5, scale.z * 2 }
})
setMenu(false)
end
function disable()
if zone ~= nil then zone.destruct() end
setMenu(true)
end
-- core functions
function setMenu(isEnabled)
self.clearContextMenu()
if isEnabled then
self.addContextMenuItem("Enable", enable)
else
self.addContextMenuItem("Disable", disable)
end
end
function onObjectEnterScriptingZone(entering, object)
if zone ~= entering then return end
if object == self or object.type == "Deck" or object.type == "Card" then return end
if tokenChecker.isChaosToken(object) then return end
object.destruct()
end
function onPickUp()
disable()
end