Merge pull request #152 from argonui/token-remover

Token Remover: Exclude chaos tokens + code cleanup
This commit is contained in:
Chr1Z 2023-01-03 23:52:13 +01:00 committed by GitHub
commit 7dcb3edba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 74 deletions

View File

@ -154,7 +154,7 @@
"ChaosBagStatTracker.766620",
"Blesstokens.afa06b",
"Cursetokens.bd0253",
"WhimsicalsTokenRemover.0a5a29",
"TokenRemover.0a5a29",
"TokenSpawner.36b4ee",
"Fan-MadeScenariosCampaignsMiscellany.66e97c",
"OfficialStandaloneChallengeScenarios.0ef5c8",

View File

@ -1,6 +1,6 @@
{
"10": {
"body": "Created by Whimsical\n\nAnything that passes over the remover that isn't a card or a deck will be deleted.\r\nTo use the remover, right click on it, choose the \"Enable\" option, and take your card with resources/horror/damage and swipe it over the remover. You may wish to unlock and/or copy the remover to your play area first.",
"body": "Created by Whimsical\n\nAnything that passes over the remover that isn't a card, deck or chaos token will be deleted.\r\nTo use the remover, right click on it, choose the \"Enable\" option, and take your card with resources/horror/damage and swipe it over the remover. You may wish to unlock and/or copy the remover to your play area first.",
"color": "Grey",
"id": 10,
"title": "Token Remover",

View File

@ -14,7 +14,7 @@
"CustomTile": {
"Stackable": false,
"Stretch": true,
"Thickness": 0.2,
"Thickness": 0.1,
"Type": 0
},
"ImageScalar": 1,
@ -34,10 +34,10 @@
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "require(\"util/TokenRemover\")",
"LuaScriptState": "[]",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Custom_Tile",
"Nickname": "Whimsical's Token Remover",
"Nickname": "Token Remover",
"Snap": true,
"Sticky": true,
"Tags": [
@ -45,15 +45,15 @@
],
"Tooltip": true,
"Transform": {
"posX": -6.868,
"posX": -7,
"posY": 1.583,
"posZ": -16.394,
"posZ": -16.4,
"rotX": 0,
"rotY": 90,
"rotZ": 0,
"scaleX": 0.75,
"scaleX": 0.8,
"scaleY": 1,
"scaleZ": 0.75
"scaleZ": 0.8
},
"Value": 0,
"XmlUI": ""

View File

@ -1,72 +1,74 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by Whimsical.
--- DateTime: 2021-02-02 9:41 a.m.
---
local zone = nil
-- Forward Declaration
---@param is_enabled boolean
local setMenu = function(is_enabled) end
local function enable()
if self.held_by_color~=nil then return end
local position = self:getPosition()
local rotation = self:getRotation()
local scale = self:getScale()
zone = spawnObject {
type = "ScriptingTrigger",
position = Vector(position.x, position.y+25+(bit32.rshift(scale.y, 1))+0.41, position.z),
rotation = rotation,
scale = Vector(scale.x*2, 50, scale.z*2),
sound = true,
snap_to_grid = true
local CHAOS_TOKEN_NAMES = {
["Elder Sign"] = true,
["+1"] = true,
["0"] = true,
["-1"] = true,
["-2"] = true,
["-3"] = true,
["-4"] = true,
["-5"] = true,
["-6"] = true,
["-7"] = true,
["-8"] = true,
["Skull"] = true,
["Cultist"] = true,
["Tablet"] = true,
["Elder Thing"] = true,
["Auto-fail"] = true,
["Bless"] = true,
["Curse"] = true,
["Frost"] = true
}
-- 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
local function disable()
if zone~=nil then zone:destruct() end
function disable()
if zone ~= nil then zone.destruct() end
setMenu(true)
end
---@param is_enabled boolean
setMenu = function(is_enabled)
self:clearContextMenu()
if is_enabled then
self:addContextMenuItem("Enable", enable, false)
-- core functions
function setMenu(isEnabled)
self.clearContextMenu()
if isEnabled then
self.addContextMenuItem("Enable", enable)
else
self:addContextMenuItem("Disable", disable, false)
self.addContextMenuItem("Disable", disable)
end
end
function onLoad(save_state)
if save_state=="" then return end
local data = JSON.decode(save_state)
zone = getObjectFromGUID(data.zone)
setMenu(zone==nil)
end
function onSave()
return JSON.encode {
zone = zone and zone:getGUID() or nil
}
end
---@param entering TTSObject
---@param object TTSObject
function onObjectEnterScriptingZone(entering, object)
if zone ~= entering then return end
if object==self then return end
if object.type=="Deck" or object.type=="Card" then return end
object:destruct()
if object == self or object.type == "Deck" or object.type == "Card" then return end
if CHAOS_TOKEN_NAMES[object.getName()] then return end
object.destruct()
end
---@param color string
function onPickUp(color)
function onPickUp()
disable()
end