diff --git a/objects/Playermat1White.8b081b.ttslua b/objects/Playermat1White.8b081b.ttslua index b2cd6913..7dd4c4fd 100644 --- a/objects/Playermat1White.8b081b.ttslua +++ b/objects/Playermat1White.8b081b.ttslua @@ -2,7 +2,6 @@ -- specific setup (different for each playmat) --------------------------------------------------------- -PLAYER_COLOR = "White" PLAY_ZONE_POSITION = { x = -54.5, y = 4, z = 19 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } TRASHCAN_GUID = "147e80" diff --git a/objects/Playermat2Orange.bd0ff4.ttslua b/objects/Playermat2Orange.bd0ff4.ttslua index 0d86c537..c30fe5af 100644 --- a/objects/Playermat2Orange.bd0ff4.ttslua +++ b/objects/Playermat2Orange.bd0ff4.ttslua @@ -2,7 +2,6 @@ -- specific setup (different for each playmat) --------------------------------------------------------- -PLAYER_COLOR = "Orange" PLAY_ZONE_POSITION = { x = -54.5, y = 4, z = -19 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } TRASHCAN_GUID = "f7b6c8" diff --git a/objects/Playermat3Green.383d8b.ttslua b/objects/Playermat3Green.383d8b.ttslua index 17c1a652..35b55b38 100644 --- a/objects/Playermat3Green.383d8b.ttslua +++ b/objects/Playermat3Green.383d8b.ttslua @@ -2,7 +2,6 @@ -- specific setup (different for each playmat) --------------------------------------------------------- -PLAYER_COLOR = "Green" PLAY_ZONE_POSITION = { x = -26.5, y = 4, z = 26.5 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } TRASHCAN_GUID = "5f896a" diff --git a/objects/Playermat4Red.0840d5.ttslua b/objects/Playermat4Red.0840d5.ttslua index 024f8cdd..082fc126 100644 --- a/objects/Playermat4Red.0840d5.ttslua +++ b/objects/Playermat4Red.0840d5.ttslua @@ -2,7 +2,6 @@ -- specific setup (different for each playmat) --------------------------------------------------------- -PLAYER_COLOR = "Red" PLAY_ZONE_POSITION = { x = -26.5, y = 4, z = -26.5 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } TRASHCAN_GUID = "4b8594" diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index 5434eb6d..ebcd03ac 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -2,14 +2,10 @@ Cleans up the table for the next scenario in a campaign: - sets counters to default values (resources and doom) or trauma values (health and sanity, if not disabled) from campaign log - puts everything on playmats and hands into respective trashcans -- use the IGNORE_TAG to exclude objects from tidying (default: "CleanUpHelper_Ignore") ---]] +- use the IGNORE_TAG to exclude objects from tidying (default: "CleanUpHelper_Ignore")]] local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") -local playmatAPI = require("playermat/PlaymatApi") - --- enable this for debugging -local SHOW_RAYS = false +local playmatApi = require("playermat/PlaymatApi") -- these objects will be ignored local IGNORE_GUIDS = { @@ -82,9 +78,7 @@ buttonParameters.function_owner = self --------------------------------------------------------- function onSave() - return JSON.encode({ - options = options - }) + return JSON.encode({ options = options }) end function onLoad(savedData) @@ -214,7 +208,7 @@ function resetSkillTrackers() if obj ~= nil then obj.call("updateStats", { 1, 1, 1, 1 }) else - printToAll("Skill tracker number " .. i .. " could not be found.", "Yellow") + printToAll("Skill tracker for " .. COLORS[i] .. " playmat could not be found.", "Yellow") end end end @@ -297,7 +291,7 @@ function discardHands() for i = 1, 4 do local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i]) if trashcan == nil then return end - local hand = Player[playmatAPI.getHandColor(COLORS[i])].getHandObjects() + local hand = Player[playmatApi.getPlayerColor(COLORS[i])].getHandObjects() for j = #hand, 1, -1 do trashcan.putObject(hand[j]) end @@ -340,7 +334,7 @@ function tidyPlayerMatCoroutine() local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i]) if trashcan == nil then printToAll("Trashcan for " .. COLORS[i] .. " playmat could not be found!", "Red") - return + return 1 end for _, entry in ipairs(findObjects(i)) do @@ -391,7 +385,7 @@ function findObjects(num) size = PHYSICS_SCALE[num], origin = PHYSICS_POSITION[num], orientation = { 0, PHYSICS_ROTATION[num], 0 }, - debug = SHOW_RAYS + debug = false }) end diff --git a/src/arkhamdb/DeckImporterMain.ttslua b/src/arkhamdb/DeckImporterMain.ttslua index 8d981451..fee13045 100644 --- a/src/arkhamdb/DeckImporterMain.ttslua +++ b/src/arkhamdb/DeckImporterMain.ttslua @@ -1,6 +1,7 @@ require("arkhamdb/DeckImporterUi") require("playercards/PlayerCardSpawner") +local playmatApi = require("playermat/PlaymatApi") local playAreaApi = require("core/PlayAreaApi") local arkhamDb = require("arkhamdb/ArkhamDb") local zones = require("playermat/Zones") @@ -176,7 +177,8 @@ end ---@param deck Object Callback-provided spawned deck object ---@param playerColor String Color of the player to draw the cards to function deckSpawned(deck, playerColor) - local handPos = Player[playerColor].getHandTransform(1).position -- Only one hand zone per player + local player = Player[playmatApi.getPlayerColor(playerColor)] + local handPos = player.getHandTransform(1).position -- Only one hand zone per player local deckCards = deck.getData().ContainedObjects -- Process in reverse order so taking cards out doesn't upset the indexing for i = #deckCards, 1, -1 do diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 1ae504ed..0b39fb23 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -354,7 +354,7 @@ function handleStatTrackerClick(_, _, isRightClick) playerColor = "White" playerName = "Overall" else - playerColor = playmatApi.getHandColor(MAT_GUID_TO_COLOR[key]) + playerColor = playmatApi.getPlayerColor(MAT_GUID_TO_COLOR[key]) playerName = Player[playerColor].steam_name or playerColor local playerSquidCount = personalStats["Auto-fail"] or 0 diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index d98005ae..5d4b9d32 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -68,7 +68,7 @@ isDES = false function onSave() return JSON.encode({ zoneID = zoneID, - playerColor = PLAYER_COLOR, + playerColor = playerColor, activeInvestigatorId = activeInvestigatorId, isDrawButtonVisible = isDrawButtonVisible }) @@ -81,6 +81,7 @@ function onLoad(save_state) STAT_TRACKER = getObjectFromGUID(STAT_TRACKER_GUID) RESOURCE_COUNTER = getObjectFromGUID(RESOURCE_COUNTER_GUID) + -- button creation for i = 1, 6 do makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], {-3.85, 3, 10.38}, i) end @@ -114,10 +115,11 @@ function onLoad(save_state) font_size = 180 }) + -- save state loading local state = JSON.decode(save_state) if state ~= nil then zoneID = state.zoneID - PLAYER_COLOR = state.playerColor + playerColor = state.playerColor activeInvestigatorId = state.activeInvestigatorId isDrawButtonVisible = state.isDrawButtonVisible end @@ -134,15 +136,6 @@ end -- utility functions --------------------------------------------------------- -function log(message) - if DEBUG then print(message) end -end - --- send messages to player who clicked button if no seated player found -function setMessageColor(color) - messageColor = Player[PLAYER_COLOR].seated and PLAYER_COLOR or color -end - function spawnDeckZone() spawnObject({ position = self.positionToWorld({-1.4, 0, 0.3 }), @@ -166,7 +159,9 @@ function searchArea(origin, size) }) end -function doNotReady(card) return card.getVar("do_not_ready") or false end +function doNotReady(card) + return card.getVar("do_not_ready") or false +end --------------------------------------------------------- -- Discard buttons @@ -232,19 +227,18 @@ end -- Upkeep button --------------------------------------------------------- -function doUpkeep(_, color, alt_click) - setMessageColor(color) - - -- right-click binds to new player color - if alt_click then - PLAYER_COLOR = color - printToColor("Upkeep button bound to " .. color, color) +function doUpkeep(_, clickedByColor, isRightClick) + -- right-click allow color changing + if isRightClick then + changeColor(clickedByColor) return end - local forcedLearning = false + -- send messages to player who clicked button if no seated player found + messageColor = Player[playerColor].seated and playerColor or clickedByColor -- unexhaust cards in play zone, flip action tokens and find forcedLearning + local forcedLearning = false for _, v in ipairs(searchArea(PLAY_ZONE_POSITION, PLAY_ZONE_SCALE)) do local obj = v.hit_object if obj.getDescription() == "Action Token" and obj.is_face_down then @@ -305,7 +299,7 @@ function doUpkeep(_, color, alt_click) if forcedLearning then printToColor("Wow, did you really take 'Versatile' to play Patrice with 'Forced Learning'? Choose which draw replacement effect takes priority and draw cards accordingly.", messageColor) else - local handSize = #Player[PLAYER_COLOR].getHandObjects() + local handSize = #Player[playerColor].getHandObjects() if handSize < 5 then local cardsToDraw = 5 - handSize printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", messageColor) @@ -329,7 +323,8 @@ end -- function for "draw 1 button" (that can be added via option panel) function doDrawOne(_, color) - setMessageColor(color) + -- send messages to player who clicked button if no seated player found + messageColor = Player[playerColor].seated and playerColor or color drawCardsWithReshuffle(1) end @@ -352,7 +347,7 @@ function drawCardsWithReshuffle(numCards) end if topCard ~= nil then - topCard.deal(numCards, PLAYER_COLOR) + topCard.deal(numCards, playerColor) numCards = numCards - 1 if numCards == 0 then return end end @@ -403,7 +398,7 @@ end function drawCards(numCards) if drawDeck == nil then return end - drawDeck.deal(numCards, PLAYER_COLOR) + drawDeck.deal(numCards, playerColor) end function shuffleDiscardIntoDeck() @@ -416,8 +411,7 @@ end -- discard a random non-hidden card from hand function doDiscardOne() - local handColor = getHandColor() - local hand = Player[handColor].getHandObjects() + local hand = Player[playerColor].getHandObjects() if #hand == 0 then broadcastToAll("Cannot discard from empty hand!", "Red") else @@ -445,18 +439,72 @@ function doDiscardOne() end end --- gets the hand color of the closest seated player (by roughly cutting the table into quarters) -function getHandColor() - for _, handColor in ipairs(Player.getAvailableColors()) do - local handPosition = Player[handColor].getHandTransform().position +--------------------------------------------------------- +-- color related functions +--------------------------------------------------------- - if (PLAYER_COLOR == "White" and handPosition.x < -42 and handPosition.z > 0) - or (PLAYER_COLOR == "Orange" and handPosition.x < -42 and handPosition.z < 0) - or (PLAYER_COLOR == "Green" and handPosition.x > -42 and handPosition.z > 0) - or (PLAYER_COLOR == "Red" and handPosition.x > -42 and handPosition.z < 0) then - return handColor +-- changes the player color +function changeColor(clickedByColor) + local colorList = { + "White", + "Brown", + "Red", + "Orange", + "Yellow", + "Green", + "Teal", + "Blue", + "Purple", + "Pink" + } + + -- remove existing colors from the list of choices + for _, existingColor in ipairs(Player.getAvailableColors()) do + for i, newColor in ipairs(colorList) do + if existingColor == newColor then + table.remove(colorList, i) + end end end + + -- show the option dialog for color selection to the player that triggered this + Player[clickedByColor].showOptionsDialog("Select a new color:", colorList, _, function(color) + local HAND_ZONE_GUIDS = { + "a70eee", -- White + "5fe087", -- Orange + "0285cc", -- Green + "be2f17" -- Red + } + local index + local startPos = self.getPosition() + + -- get respective hand zone by position + if startPos.x < -42 then + if startPos.z > 0 then + index = 1 + else + index = 2 + end + else + if startPos.z > 0 then + index = 3 + else + index = 4 + end + end + + -- update the color of the hand zone + local handZone = getObjectFromGUID(HAND_ZONE_GUIDS[index]) + handZone.setValue(color) + + -- if the seated player clicked this, reseat him to the new color + if clickedByColor == playerColor then + Player[playerColor].changeColor(color) + end + + -- update the internal variable + playerColor = color + end) end --------------------------------------------------------- diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index a04893fc..6e563907 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -43,9 +43,9 @@ do -- Returns the color of the player's hand that is seated next to the playermat ---@param matColor String Color of the playermat - PlaymatApi.getHandColor = function(matColor) + PlaymatApi.getPlayerColor = function(matColor) local mat = getObjectFromGUID(MAT_IDS[matColor]) - return mat.call("getHandColor") + return mat.getVar("playerColor") end -- Returns if there is the card"Dream-Enhancing Serum" on the requested playermat