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", "ChaosBagStatTracker.766620",
"Blesstokens.afa06b", "Blesstokens.afa06b",
"Cursetokens.bd0253", "Cursetokens.bd0253",
"WhimsicalsTokenRemover.0a5a29", "TokenRemover.0a5a29",
"TokenSpawner.36b4ee", "TokenSpawner.36b4ee",
"Fan-MadeScenariosCampaignsMiscellany.66e97c", "Fan-MadeScenariosCampaignsMiscellany.66e97c",
"OfficialStandaloneChallengeScenarios.0ef5c8", "OfficialStandaloneChallengeScenarios.0ef5c8",

View File

@ -1,6 +1,6 @@
{ {
"10": { "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", "color": "Grey",
"id": 10, "id": 10,
"title": "Token Remover", "title": "Token Remover",

View File

@ -14,7 +14,7 @@
"CustomTile": { "CustomTile": {
"Stackable": false, "Stackable": false,
"Stretch": true, "Stretch": true,
"Thickness": 0.2, "Thickness": 0.1,
"Type": 0 "Type": 0
}, },
"ImageScalar": 1, "ImageScalar": 1,
@ -34,10 +34,10 @@
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "require(\"util/TokenRemover\")", "LuaScript": "require(\"util/TokenRemover\")",
"LuaScriptState": "[]", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Custom_Tile", "Name": "Custom_Tile",
"Nickname": "Whimsical's Token Remover", "Nickname": "Token Remover",
"Snap": true, "Snap": true,
"Sticky": true, "Sticky": true,
"Tags": [ "Tags": [
@ -45,15 +45,15 @@
], ],
"Tooltip": true, "Tooltip": true,
"Transform": { "Transform": {
"posX": -6.868, "posX": -7,
"posY": 1.583, "posY": 1.583,
"posZ": -16.394, "posZ": -16.4,
"rotX": 0, "rotX": 0,
"rotY": 90, "rotY": 90,
"rotZ": 0, "rotZ": 0,
"scaleX": 0.75, "scaleX": 0.8,
"scaleY": 1, "scaleY": 1,
"scaleZ": 0.75 "scaleZ": 0.8
}, },
"Value": 0, "Value": 0,
"XmlUI": "" "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 local zone = nil
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
}
-- Forward Declaration -- general code
---@param is_enabled boolean function onSave()
local setMenu = function(is_enabled) end return JSON.encode(zone and zone.getGUID() or nil)
end
local function enable() function onLoad(savedData)
if self.held_by_color~=nil then return end if savedData ~= "" and savedData ~= nil then
local position = self:getPosition() zone = getObjectFromGUID(JSON.decode(savedData))
local rotation = self:getRotation() end
local scale = self:getScale() setMenu(zone == nil)
end
zone = spawnObject { -- context menu functions
function enable()
local scale = self.getScale()
zone = spawnObject({
type = "ScriptingTrigger", type = "ScriptingTrigger",
position = Vector(position.x, position.y+25+(bit32.rshift(scale.y, 1))+0.41, position.z), position = self.getPosition() + Vector(0, 2.5 + 0.11, 0),
rotation = rotation, rotation = self.getRotation(),
scale = Vector(scale.x*2, 50, scale.z*2), scale = { scale.x * 2, 5, scale.z * 2 }
sound = true, })
snap_to_grid = true
}
setMenu(false) setMenu(false)
end end
local function disable() function disable()
if zone~=nil then zone:destruct() end if zone ~= nil then zone.destruct() end
setMenu(true) setMenu(true)
end end
---@param is_enabled boolean -- core functions
setMenu = function(is_enabled) function setMenu(isEnabled)
self:clearContextMenu() self.clearContextMenu()
if is_enabled then if isEnabled then
self:addContextMenuItem("Enable", enable, false) self.addContextMenuItem("Enable", enable)
else else
self:addContextMenuItem("Disable", disable, false) self.addContextMenuItem("Disable", disable)
end end
end end
function onLoad(save_state) function onObjectEnterScriptingZone(entering, object)
if save_state=="" then return end if zone ~= entering then return end
local data = JSON.decode(save_state) if object == self or object.type == "Deck" or object.type == "Card" then return end
zone = getObjectFromGUID(data.zone) if CHAOS_TOKEN_NAMES[object.getName()] then return end
setMenu(zone==nil) object.destruct()
end end
function onSave() function onPickUp()
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()
end
---@param color string
function onPickUp(color)
disable() disable()
end end