From 31b4613caf26f2cdb3c508aa2e17418604603ca4 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 12 Feb 2024 10:01:05 +0100 Subject: [PATCH] code maintenance --- .../PlayermatHider.a758b2.json | 60 ------------------- src/accessories/PlayermatHider.ttslua | 21 ------- src/arkhamdb/DeckImporterMain.ttslua | 1 - src/core/DoomInPlayCounter.ttslua | 4 +- src/core/Global.ttslua | 1 - src/playercards/PlayerCardPanel.ttslua | 5 +- src/playercards/PlayerCardSpawner.ttslua | 33 +++++----- src/playercards/SpawnBag.ttslua | 3 +- src/playermat/Playmat.ttslua | 14 ++--- 9 files changed, 28 insertions(+), 114 deletions(-) delete mode 100644 objects/Fan-MadeAccessories.aa8b38/PlayermatHider.a758b2.json delete mode 100644 src/accessories/PlayermatHider.ttslua diff --git a/objects/Fan-MadeAccessories.aa8b38/PlayermatHider.a758b2.json b/objects/Fan-MadeAccessories.aa8b38/PlayermatHider.a758b2.json deleted file mode 100644 index b97c1549..00000000 --- a/objects/Fan-MadeAccessories.aa8b38/PlayermatHider.a758b2.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "AltLookAngle": { - "x": 0, - "y": 0, - "z": 0 - }, - "Autoraise": true, - "ColorDiffuse": { - "b": 1, - "g": 1, - "r": 1 - }, - "CustomImage": { - "CustomTile": { - "Stackable": false, - "Stretch": true, - "Thickness": 0.1, - "Type": 3 - }, - "ImageScalar": 1, - "ImageSecondaryURL": "", - "ImageURL": "http://cloud-3.steamusercontent.com/ugc/2115061845796985108/F0ADB7094641DA966FFA3AF0CC6987D33D2D9591/", - "WidthScale": 0 - }, - "Description": "Use the buttons to show / hide a playmat.", - "DragSelectable": true, - "GMNotes": "", - "GUID": "a758b2", - "Grid": true, - "GridProjection": false, - "Hands": false, - "HideWhenFaceDown": false, - "IgnoreFoW": false, - "LayoutGroupSortIndex": 0, - "Locked": false, - "LuaScript": "require(\"accessories/PlayermatHider\")", - "LuaScriptState": "", - "MeasureMovement": false, - "Name": "Custom_Tile", - "Nickname": "PlayermatHider", - "Snap": true, - "Sticky": true, - "Tags": [ - "CleanUpHelper_ignore" - ], - "Tooltip": true, - "Transform": { - "posX": 0, - "posY": 2, - "posZ": 0, - "rotX": 0, - "rotY": 270, - "rotZ": 0, - "scaleX": 5, - "scaleY": 1, - "scaleZ": 5 - }, - "Value": 0, - "XmlUI": "\u003cInclude src=\"accessories/PlayermatHider.xml\"/\u003e" -} diff --git a/src/accessories/PlayermatHider.ttslua b/src/accessories/PlayermatHider.ttslua deleted file mode 100644 index b4185b6c..00000000 --- a/src/accessories/PlayermatHider.ttslua +++ /dev/null @@ -1,21 +0,0 @@ -local guidReferenceApi = require("core/GUIDReferenceApi") -local playmatApi = require("playermat/PlaymatApi") - -function onClick_hide(player, matColor) - local objects = guidReferenceApi.getObjectsByOwner(matColor) - if not objects.Playermat then return end - - player.showConfirmDialog("Really remove this playmat and related objects? This can't be reversed.", - function() - -- remove action tokens - local actionTokens = playmatApi.searchAroundPlaymat(matColor, "isActionToken") - for _, obj in ipairs(actionTokens) do - obj.destruct() - end - - -- remove mat owned objects - for _, obj in pairs(objects) do - obj.destruct() - end - end) -end diff --git a/src/arkhamdb/DeckImporterMain.ttslua b/src/arkhamdb/DeckImporterMain.ttslua index d909081c..6a5e33aa 100644 --- a/src/arkhamdb/DeckImporterMain.ttslua +++ b/src/arkhamdb/DeckImporterMain.ttslua @@ -3,7 +3,6 @@ require("playercards/PlayerCardSpawner") local allCardsBagApi = require("playercards/AllCardsBagApi") local arkhamDb = require("arkhamdb/ArkhamDb") -local playAreaApi = require("core/PlayAreaApi") local playmatApi = require("playermat/PlaymatApi") local zones = require("playermat/Zones") diff --git a/src/core/DoomInPlayCounter.ttslua b/src/core/DoomInPlayCounter.ttslua index 0fcff336..598f33d5 100644 --- a/src/core/DoomInPlayCounter.ttslua +++ b/src/core/DoomInPlayCounter.ttslua @@ -1,7 +1,7 @@ local guidReferenceApi = require("core/GUIDReferenceApi") local playmatApi = require("playermat/PlaymatApi") -local ZONE, TRASH, loopID +local ZONE, TRASH local doomURL = "https://i.imgur.com/EoL7yaZ.png" local IGNORE_TAG = "DoomCounter_ignore" local TOTAL_PLAY_AREA = { @@ -32,7 +32,7 @@ function onLoad() TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash") ZONE = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone") - loopID = Wait.time(updateCounter, 2, -1) + Wait.time(updateCounter, 2, -1) end -- main function diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 6d3b3841..14e36181 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -37,7 +37,6 @@ local chaosTokensLastMatGUID = nil local tokenDrawingStats = { ["Overall"] = {} } local bagSearchers = {} -local MAT_COLORS = { "White", "Orange", "Green", "Red" } local hideTitleSplashWaitFunctionId = nil -- online functionality related variables diff --git a/src/playercards/PlayerCardPanel.ttslua b/src/playercards/PlayerCardPanel.ttslua index 92c34ead..cc2311eb 100644 --- a/src/playercards/PlayerCardPanel.ttslua +++ b/src/playercards/PlayerCardPanel.ttslua @@ -99,10 +99,7 @@ local starterDeckMode = STARTER_DECK_MODE_CARDS_ONLY local helpVisibleToPlayers = { } function onSave() - local saveState = { - spawnBagState = spawnBag.getStateForSave(), - } - return JSON.encode(saveState) + return JSON.encode({ spawnBagState = spawnBag.getStateForSave() }) end function onLoad(savedData) diff --git a/src/playercards/PlayerCardSpawner.ttslua b/src/playercards/PlayerCardSpawner.ttslua index cd14b1cb..17f51900 100644 --- a/src/playercards/PlayerCardSpawner.ttslua +++ b/src/playercards/PlayerCardSpawner.ttslua @@ -10,11 +10,11 @@ Spawner = { } -- investigator, standard, and mini, spawning them in that order with larger cards on bottom. If -- there are different types, the provided callback will be called once for each type as it spawns -- either a card or deck. --- @param cardList: A list of Player Card data structures (data/metadata) --- @param pos Position table where the cards should be spawned (global) --- @param rot Rotation table for the orientation of the spawned cards (global) --- @param sort Boolean, true if this list of cards should be sorted before spawning --- @param callback Function, callback to be called after the card/deck spawns. +---@param cardList table A list of Player Card data structures (data/metadata) +---@param pos tts__Vector table where the cards should be spawned (global) +---@param rot tts__Vector table for the orientation of the spawned cards (global) +---@param sort boolean True if this list of cards should be sorted before spawning +---@param callback? function Callback to be called after the card/deck spawns. Spawner.spawnCards = function(cardList, pos, rot, sort, callback) if (sort) then table.sort(cardList, Spawner.cardComparator) @@ -80,29 +80,30 @@ end ---@param cardList table A list of Player Card data structures (data/metadata) ---@param pos table Position where the cards should be spawned (global) ---@param rot table Rotation for the orientation of the spawned cards (global) ----@param callback function callback to be called after the card/deck spawns. +---@param callback? function callback to be called after the card/deck spawns. Spawner.spawn = function(cardList, pos, rot, callback) - if (#cardList == 0) then - return - end + if #cardList == 0 then return end + -- Spawn a single card directly if (#cardList == 1) then spawnObjectData({ data = cardList[1].data, position = pos, rotation = rot, - callback_function = callback, + callback_function = callback }) return end + -- For multiple cards, construct a deck and spawn that local deck = Spawner.buildDeckDataTemplate() + -- Decks won't inherently scale to the cards in them. The card list being spawned should be all -- the same type/size by this point, so use the first card to set the size deck.Transform = { scaleX = cardList[1].data.Transform.scaleX, scaleY = 1, - scaleZ = cardList[1].data.Transform.scaleZ, + scaleZ = cardList[1].data.Transform.scaleZ } local sidewaysDeck = true for _, spawnCard in ipairs(cardList) do @@ -110,15 +111,17 @@ Spawner.spawn = function(cardList, pos, rot, callback) -- set sidewaysDeck to false if any card is not a sideways card sidewaysDeck = (sidewaysDeck and spawnCard.data.SidewaysCard) end + -- set the alt view angle for sideway decks if sidewaysDeck then deck.AltLookAngle = { x = 0, y = 180, z = 90 } end + spawnObjectData({ data = deck, position = pos, rotation = rot, - callback_function = callback, + callback_function = callback }) end @@ -187,9 +190,9 @@ Spawner.buildDeckDataTemplate = function() end -- Returns the first ID which does not exist in the given table, starting at startId and increasing --- @param objectTable Table keyed by strings which are numbers --- @param startId First possible ID. --- @return String ID >= startId +---@param objectTable table keyed by strings which are numbers +---@param startId string possible ID. +---@return string id >= startId Spawner.findNextAvailableId = function(objectTable, startId) local id = startId while (objectTable[id] ~= nil) do diff --git a/src/playercards/SpawnBag.ttslua b/src/playercards/SpawnBag.ttslua index dce3e2ae..3bdcb80e 100644 --- a/src/playercards/SpawnBag.ttslua +++ b/src/playercards/SpawnBag.ttslua @@ -78,8 +78,7 @@ do } end - -- Places the given spawnSpec on the table. See SpawnBag.ttslua header for spawnSpec table data and - -- examples + -- Places the given spawnSpec on the table. See comment at the start of the file for spawnSpec table data and examples SpawnBag.spawn = function(spawnSpec) -- Limit to one placement at a time if (placedSpecs[spawnSpec.name]) then diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index f3f551f6..fa129b32 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -300,14 +300,12 @@ function doUpkeep(_, clickedByColor, isRightClick) -- flip investigator mini-card and summoned servitor mini-card -- (all characters allowed to account for custom IDs - e.g. 'Z0000' for TTS Zoop generated IDs) - if activeInvestigatorId ~= nil then - local miniId = string.match(activeInvestigatorId, ".....") .. "-m" - for _, obj in ipairs(getObjects()) do - if obj.type == "Card" and obj.is_face_down then - local notes = JSON.decode(obj.getGMNotes()) - if notes ~= nil and notes.type == "Minicard" and (notes.id == miniId or notes.id == "09080-m") then - obj.flip() - end + local miniId = string.match(activeInvestigatorId, ".....") .. "-m" + for _, obj in ipairs(getObjects()) do + if obj.type == "Card" and obj.is_face_down then + local notes = JSON.decode(obj.getGMNotes()) + if notes ~= nil and notes.type == "Minicard" and (notes.id == miniId or notes.id == "09080-m") then + obj.flip() end end end