From d5f04cf465b1781179563d71863795e01d0a5782 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 22 Dec 2022 12:50:02 +0100 Subject: [PATCH 1/2] addition of "load default" functionality --- config.json | 2 +- objects/LuaScriptState.luascriptstate | 1 + objects/Playermat1White.8b081b.json | 2 +- objects/Playermat1White.8b081b.luascriptstate | 1 + objects/Playermat2Orange.bd0ff4.json | 2 +- .../Playermat2Orange.bd0ff4.luascriptstate | 1 + objects/Playermat3Green.383d8b.json | 2 +- objects/Playermat3Green.383d8b.luascriptstate | 1 + objects/Playermat4Red.0840d5.json | 2 +- objects/Playermat4Red.0840d5.luascriptstate | 1 + src/core/Global.ttslua | 60 ++++++++++++++----- 11 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 objects/LuaScriptState.luascriptstate create mode 100644 objects/Playermat1White.8b081b.luascriptstate create mode 100644 objects/Playermat2Orange.bd0ff4.luascriptstate create mode 100644 objects/Playermat3Green.383d8b.luascriptstate create mode 100644 objects/Playermat4Red.0840d5.luascriptstate diff --git a/config.json b/config.json index 2a9cc134..0fe8eb4d 100644 --- a/config.json +++ b/config.json @@ -22,7 +22,7 @@ }, "Lighting_path": "Lighting.json", "LuaScript": "require(\"core/Global\")", - "LuaScriptState": "{\"optionPanel\":{\"showDrawButton\":false,\"showHandHelper\":[],\"useClueClickers\":false,\"useSnapTags\":true}}", + "LuaScriptState_path": "LuaScriptState.luascriptstate", "MusicPlayer_path": "MusicPlayer.json", "Note": "", "ObjectStates_order": [ diff --git a/objects/LuaScriptState.luascriptstate b/objects/LuaScriptState.luascriptstate new file mode 100644 index 00000000..3a990518 --- /dev/null +++ b/objects/LuaScriptState.luascriptstate @@ -0,0 +1 @@ +{"optionPanel":{"showChaosBagManager":false,"showCleanUpHelper":false,"showDrawButton":false,"showHandHelper":false,"showNavigationOverlay":false,"showTokenArranger":false,"useClueClickers":false,"useSnapTags":true}} diff --git a/objects/Playermat1White.8b081b.json b/objects/Playermat1White.8b081b.json index 9ddd84f6..9b71f76f 100644 --- a/objects/Playermat1White.8b081b.json +++ b/objects/Playermat1White.8b081b.json @@ -273,7 +273,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, - "LuaScriptState": "{\"activeInvestigatorId\":\"00000\",\"playerColor\":\"White\",\"zoneID\":\"7af2cf\"}", + "LuaScriptState_path": "Playermat1White.8b081b.luascriptstate", "LuaScript_path": "Playermat1White.8b081b.ttslua", "MeasureMovement": false, "Name": "Custom_Tile", diff --git a/objects/Playermat1White.8b081b.luascriptstate b/objects/Playermat1White.8b081b.luascriptstate new file mode 100644 index 00000000..f6e1f7ad --- /dev/null +++ b/objects/Playermat1White.8b081b.luascriptstate @@ -0,0 +1 @@ +{"activeInvestigatorId":"00000","isDrawButtonVisible":false,"playerColor":"White","zoneID":"7af2cf"} diff --git a/objects/Playermat2Orange.bd0ff4.json b/objects/Playermat2Orange.bd0ff4.json index 8683447d..3003eb32 100644 --- a/objects/Playermat2Orange.bd0ff4.json +++ b/objects/Playermat2Orange.bd0ff4.json @@ -273,7 +273,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, - "LuaScriptState": "{\"activeInvestigatorId\":\"00000\",\"playerColor\":\"Orange\",\"zoneID\":\"b047f8\"}", + "LuaScriptState_path": "Playermat2Orange.bd0ff4.luascriptstate", "LuaScript_path": "Playermat2Orange.bd0ff4.ttslua", "MeasureMovement": false, "Name": "Custom_Tile", diff --git a/objects/Playermat2Orange.bd0ff4.luascriptstate b/objects/Playermat2Orange.bd0ff4.luascriptstate new file mode 100644 index 00000000..5a62485b --- /dev/null +++ b/objects/Playermat2Orange.bd0ff4.luascriptstate @@ -0,0 +1 @@ +{"activeInvestigatorId":"00000","isDrawButtonVisible":false,"playerColor":"Orange","zoneID":"b047f8"} diff --git a/objects/Playermat3Green.383d8b.json b/objects/Playermat3Green.383d8b.json index 340f8771..dae537d8 100644 --- a/objects/Playermat3Green.383d8b.json +++ b/objects/Playermat3Green.383d8b.json @@ -273,7 +273,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, - "LuaScriptState": "{\"activeInvestigatorId\":\"00000\",\"playerColor\":\"Green\",\"zoneID\":\"fb28e1\"}", + "LuaScriptState_path": "Playermat3Green.383d8b.luascriptstate", "LuaScript_path": "Playermat3Green.383d8b.ttslua", "MeasureMovement": false, "Name": "Custom_Tile", diff --git a/objects/Playermat3Green.383d8b.luascriptstate b/objects/Playermat3Green.383d8b.luascriptstate new file mode 100644 index 00000000..142f5f9e --- /dev/null +++ b/objects/Playermat3Green.383d8b.luascriptstate @@ -0,0 +1 @@ +{"activeInvestigatorId":"00000","isDrawButtonVisible":false,"playerColor":"Green","zoneID":"fb28e1"} diff --git a/objects/Playermat4Red.0840d5.json b/objects/Playermat4Red.0840d5.json index 18d8515e..bb8fbfac 100644 --- a/objects/Playermat4Red.0840d5.json +++ b/objects/Playermat4Red.0840d5.json @@ -273,7 +273,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, - "LuaScriptState": "{\"activeInvestigatorId\":\"00000\",\"playerColor\":\"Red\",\"zoneID\":\"18538f\"}", + "LuaScriptState_path": "Playermat4Red.0840d5.luascriptstate", "LuaScript_path": "Playermat4Red.0840d5.ttslua", "MeasureMovement": false, "Name": "Custom_Tile", diff --git a/objects/Playermat4Red.0840d5.luascriptstate b/objects/Playermat4Red.0840d5.luascriptstate new file mode 100644 index 00000000..0c461d35 --- /dev/null +++ b/objects/Playermat4Red.0840d5.luascriptstate @@ -0,0 +1 @@ +{"activeInvestigatorId":"00000","isDrawButtonVisible":false,"playerColor":"Red","zoneID":"18538f"} diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 1ea6462e..0964b638 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -787,11 +787,6 @@ end -- Option Panel related functionality --------------------------------------------------------- --- loads the default options -function onClick_defaultSettings() - print("Dummy: Load default settings") -end - -- called by toggling an option function onClick_toggleOption(_, id) local state = self.UI.getAttribute(id, "isOn") @@ -814,6 +809,8 @@ function updateOptionPanelState() or (type(enabled) == "string" and enabled) or (type(enabled) == "table" and #enabled ~= 0) then self.UI.setAttribute(id, "isOn", true) + else + self.UI.setAttribute(id, "isOn", "False") end end end @@ -888,26 +885,32 @@ end ---@param name String Name of the object that should be copied ---@param position Position Desired position of the object function spawnHelperObject(name, position, rotation, color) - for _, obj in ipairs(getObjectFromGUID(BARREL_GUID).getData().ContainedObjects) do - if obj["Nickname"] == name then - return spawnObjectData({ - data = obj, - position = position, - rotation = rotation or {0, 270, 0}, - callback_function = function(object) + local spawnTable = { + position = position, + callback_function = function(object) if name == "Hand Helper" then Wait.time(function() object.call("externalColorChange", color) end, 1) elseif name == "Token Arranger" then Wait.time(function() object.call("layout") end, 1) end - end - }) + end + } + + -- only overrride rotation if there is one provided (object's rotation used instead) + if rotation then + spawnTable.rotation = rotation + end + + for _, obj in ipairs(getObjectFromGUID(BARREL_GUID).getData().ContainedObjects) do + if obj["Nickname"] == name then + spawnTable.data = obj + return spawnObjectData(spawnTable) end end end -- removes the specified tool (by name) ----@param name String Name of the object that should be removed +---@param name String Object that should be removed function removeHelperObject(name) -- links objects name to the respective option name (to grab the GUID for removal) local referenceTable = { @@ -933,3 +936,30 @@ function removeHelperObject(name) end end end + +-- loads the default options +function onClick_defaultSettings() + for id, _ in pairs(optionPanel) do + local state = false + -- override for settings that are enabled by default + if id == "useSnapTags" then + state = true + end + applyOptionPanelChange(id, state) + end + + -- clean reset of variable + optionPanel = { + useSnapTags = true, + showDrawButton = false, + useClueClickers = false, + showTokenArranger = false, + showCleanUpHelper = false, + showHandHelper = false, + showChaosBagManager = false, + showNavigationOverlay = false + } + + -- update UI + updateOptionPanelState() +end From 20e0f8075b5f8ca09291338f1b1cfc97b5df6e81 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 22 Dec 2022 13:18:45 +0100 Subject: [PATCH 2/2] bugfix for handhelper, error handling for missing barrel --- objects/LuaScriptState.luascriptstate | 2 +- src/core/Global.ttslua | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/objects/LuaScriptState.luascriptstate b/objects/LuaScriptState.luascriptstate index 3a990518..f685f165 100644 --- a/objects/LuaScriptState.luascriptstate +++ b/objects/LuaScriptState.luascriptstate @@ -1 +1 @@ -{"optionPanel":{"showChaosBagManager":false,"showCleanUpHelper":false,"showDrawButton":false,"showHandHelper":false,"showNavigationOverlay":false,"showTokenArranger":false,"useClueClickers":false,"useSnapTags":true}} +{"optionPanel":{"showChaosBagManager":false,"showCleanUpHelper":false,"showDrawButton":false,"showHandHelper":{},"showNavigationOverlay":false,"showTokenArranger":false,"useClueClickers":false,"useSnapTags":true}} diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 0964b638..ff4433c3 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -885,14 +885,22 @@ end ---@param name String Name of the object that should be copied ---@param position Position Desired position of the object function spawnHelperObject(name, position, rotation, color) + local barrel = getObjectFromGUID(BARREL_GUID) + + -- error handling for missing barrel + if not barrel then + broadcastToAll("'Barrel' with fan-made accessories could not be found!", "Red") + return + end + local spawnTable = { position = position, callback_function = function(object) - if name == "Hand Helper" then - Wait.time(function() object.call("externalColorChange", color) end, 1) - elseif name == "Token Arranger" then - Wait.time(function() object.call("layout") end, 1) - end + if name == "Hand Helper" then + Wait.time(function() object.call("externalColorChange", color) end, 0.1) + elseif name == "Token Arranger" then + Wait.time(function() object.call("layout") end, 0.1) + end end } @@ -901,7 +909,7 @@ function spawnHelperObject(name, position, rotation, color) spawnTable.rotation = rotation end - for _, obj in ipairs(getObjectFromGUID(BARREL_GUID).getData().ContainedObjects) do + for _, obj in ipairs(barrel.getData().ContainedObjects) do if obj["Nickname"] == name then spawnTable.data = obj return spawnObjectData(spawnTable) @@ -955,7 +963,7 @@ function onClick_defaultSettings() useClueClickers = false, showTokenArranger = false, showCleanUpHelper = false, - showHandHelper = false, + showHandHelper = {}, showChaosBagManager = false, showNavigationOverlay = false }