From dccf5daaccf24351ad63ad81ec45d000e3afa6ba Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 30 Sep 2024 12:46:53 +0200 Subject: [PATCH] some bugfixes --- src/core/Global.ttslua | 36 ++++++++++++++++----------- src/core/token/TokenManagerApi.ttslua | 11 +++----- src/playermat/Playermat.ttslua | 36 ++++++++++++++++++++------- src/playermat/Zones.ttslua | 4 +-- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index f339ca44..213d94ed 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2472,25 +2472,17 @@ end -- generates the data to spawn an infinite bag of a specific type of resources function TokenManager.getDataForInfiniteBag(tokenType) TokenManager.initTokenTemplates() - local tokenTemplate = tokenTemplates["resource"] - local subTypeData - local subTypeStateId - - for stateId, objData in pairs(tokenTemplate["States"]) do - if tokenType == objData["Memo"] then - subTypeStateId = stateId - subTypeData = objData - break - end - end + local template = deepCopy(tokenTemplates["resource"]) + local subTypeStateId = stateTable[tokenType] + local subTypeData = template["States"][subTypeStateId] -- add states to data - subTypeData["States"] = tokenTemplate["States"] + subTypeData["States"] = template["States"] -- add "1" state and remove the current state - subTypeData["States"]["1"] = tokenTemplate - subTypeData["States"]["1"]["States"] = nil - subTypeData["States"][tostring(subTypeStateId)] = nil + subTypeData["States"][1] = template + subTypeData["States"][1]["States"] = nil + subTypeData["States"][subTypeStateId] = nil return subTypeData --local spawnData = {} @@ -2565,3 +2557,17 @@ function getColoredName(playerColor) -- add bb-code return "[" .. Color.fromString(playerColor):toHex() .. "]" .. displayName .. "[-]" end + +-- creates a deep copy of a table +function deepCopy(data) + if type(data) ~= "table" then return data end + local copiedList = {} + for key, value in pairs(data) do + if type(value) == "table" then + copiedList[key] = deepCopy(value) + else + copiedList[key] = value + end + end + return copiedList +end diff --git a/src/core/token/TokenManagerApi.ttslua b/src/core/token/TokenManagerApi.ttslua index 0d6341d1..4ad9c4b0 100644 --- a/src/core/token/TokenManagerApi.ttslua +++ b/src/core/token/TokenManagerApi.ttslua @@ -89,19 +89,14 @@ do function TokenManagerApi.maybeReplenishCard(card, uses) Global.call("callTable", { { "TokenManager", "maybeReplenishCard" }, - { - card = card, - uses = uses - } + { card = card, uses = uses } }) end function TokenManagerApi.getDataForInfiniteBag(tokenType) - Global.call("callTable", { + return Global.call("callTable", { { "TokenManager", "getDataForInfiniteBag" }, - { - tokenType = tokenType - } + tokenType }) end diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index 637670ec..7b616a0f 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -272,9 +272,15 @@ function round(num, numDecimalPlaces) end -- updates the internal "messageColor" which is used for print/broadcast statements if no player is seated ----@param clickedByColor string Colorstring of player who clicked a button +---@param clickedByColor? string Colorstring of player who clicked a button function updateMessageColor(clickedByColor) - messageColor = Player[playerColor].seated and playerColor or clickedByColor + if Player[playerColor].seated then + messageColor = playerColor + elseif clickedByColor and Player[clickedByColor].seated then + messageColor = clickedByColor + else + messageColor = Player.getPlayers()[1].color + end end --------------------------------------------------------- @@ -1340,6 +1346,8 @@ end -- does something for specific investigators when they are loaded function newInvestigatorCallback(newId) + updateMessageColor() + -- remove existing object that was placed for a specific investigator local obj = guidReferenceApi.getObjectByOwnerAndType(playerColor, "InvestigatorSpecifics") if obj ~= nil then @@ -1350,13 +1358,17 @@ function newInvestigatorCallback(newId) if newId == "01005-p" or newId == "01005-pf" then -- parallel Wendy Adams printToColor( - "There's a Game Key for parallel Wendy to add sealing options to any card:" .. + "Wendy Adams: There's a Game Key to add sealing options to any card:" .. " Top menu bar > Options > Game Keys", messageColor) elseif newId == "06003" then -- Tony Morgan - local spawnedObj = spawnObjectData({ data = getDataForInfiniteBag("bounty") }) + local spawnedObj = spawnObjectData({ + data = getDataForInfiniteBag("bounty"), + position = zones.getZonePosition(playerColor, "SetAside7"), + rotation = self.getRotation() + }) guidReferenceApi.editIndex(playerColor, "InvestigatorSpecifics", spawnedObj.getGUID()) - printToColor("We've spawned an infinite bag of bounty tokens for convenience near your playermat.", messageColor) + printToColor("Tony Morgan: Spawned an infinite bag of bounty tokens near your playermat.", messageColor) elseif newId == "08004" then -- Norman Withers printToColor( @@ -1364,9 +1376,13 @@ function newInvestigatorCallback(newId) "and then the mod should keep it flipped throughout the game.", messageColor) elseif newId == "09015" then -- Darrell Simmons - local spawnedObj = spawnObjectData({ data = getDataForInfiniteBag("evidence") }) + local spawnedObj = spawnObjectData({ + data = getDataForInfiniteBag("evidence"), + position = zones.getZonePosition(playerColor, "SetAside7"), + rotation = self.getRotation() + }) guidReferenceApi.editIndex(playerColor, "InvestigatorSpecifics", spawnedObj.getGUID()) - printToColor("We've spawned an infinite bag of evidence tokens for convenience near your playermat.", messageColor) + printToColor("Darrell Simons: Spawned an infinite bag of evidence tokens near your playermat.", messageColor) elseif newId == "89001" then -- Subject 5U-21 local sourceBag = guidReferenceApi.getObjectByOwnerAndType("Mythos", "OptionPanelSource") @@ -1382,13 +1398,15 @@ function newInvestigatorCallback(newId) break end end - printToColor("We've spawned a helper to track the classes of devoured cards near your playermat. " .. - "Note that this and 'Ravenous' will work with the Attachment Helper from the option panel.", messageColor) + printToColor("Subject 5U-21: Spawned a helper to track the classes of devoured cards near your playermat. " .. + "Note that this and 'Ravenous' will work with the Attachment Helper from the option panel.", messageColor) end end function getDataForInfiniteBag(tokenType) local tokenData = tokenManagerApi.getDataForInfiniteBag(tokenType) + log(tokenData) + return tokenData end -- returns the mini ID for the currently placed investigator diff --git a/src/playermat/Zones.ttslua b/src/playermat/Zones.ttslua index 1b56f136..f9d4dc30 100644 --- a/src/playermat/Zones.ttslua +++ b/src/playermat/Zones.ttslua @@ -80,7 +80,7 @@ do zoneData["White"]["SetAside5"] = { 2.78, 0, 0.042 } zoneData["White"]["SetAside6"] = { 2.78, 0, 0.605 } zoneData["White"]["UnderSetAside6"] = { 2.93, 0, 0.805 } - zoneData["White"]["SetAside7"] = { 3.21, 0, 0.705 } + zoneData["White"]["SetAside7"] = { 2.85, 0, 1.650 } zoneData["Orange"] = {} zoneData["Orange"]["Investigator"] = commonZones["Investigator"] @@ -113,7 +113,7 @@ do zoneData["Orange"]["SetAside5"] = { -2.78, 0, 0.042 } zoneData["Orange"]["SetAside6"] = { -2.78, 0, 0.605 } zoneData["Orange"]["UnderSetAside6"] = { -2.93, 0, 0.805 } - zoneData["Orange"]["SetAside7"] = { -3.21, 0, 0.705 } + zoneData["Orange"]["SetAside7"] = { -2.85, 0, 1.650 } -- Green positions are the same as White and Red the same as Orange zoneData["Red"] = zoneData["Orange"]