better custom color support

This commit is contained in:
Chr1Z93 2023-03-16 13:13:38 +01:00
parent 0492292c23
commit c52df403bc
9 changed files with 96 additions and 56 deletions

View File

@ -2,7 +2,6 @@
-- specific setup (different for each playmat) -- specific setup (different for each playmat)
--------------------------------------------------------- ---------------------------------------------------------
PLAYER_COLOR = "White"
PLAY_ZONE_POSITION = { x = -54.5, y = 4, z = 19 } PLAY_ZONE_POSITION = { x = -54.5, y = 4, z = 19 }
PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 }
TRASHCAN_GUID = "147e80" TRASHCAN_GUID = "147e80"

View File

@ -2,7 +2,6 @@
-- specific setup (different for each playmat) -- specific setup (different for each playmat)
--------------------------------------------------------- ---------------------------------------------------------
PLAYER_COLOR = "Orange"
PLAY_ZONE_POSITION = { x = -54.5, y = 4, z = -19 } PLAY_ZONE_POSITION = { x = -54.5, y = 4, z = -19 }
PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 }
TRASHCAN_GUID = "f7b6c8" TRASHCAN_GUID = "f7b6c8"

View File

@ -2,7 +2,6 @@
-- specific setup (different for each playmat) -- specific setup (different for each playmat)
--------------------------------------------------------- ---------------------------------------------------------
PLAYER_COLOR = "Green"
PLAY_ZONE_POSITION = { x = -26.5, y = 4, z = 26.5 } PLAY_ZONE_POSITION = { x = -26.5, y = 4, z = 26.5 }
PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 }
TRASHCAN_GUID = "5f896a" TRASHCAN_GUID = "5f896a"

View File

@ -2,7 +2,6 @@
-- specific setup (different for each playmat) -- specific setup (different for each playmat)
--------------------------------------------------------- ---------------------------------------------------------
PLAYER_COLOR = "Red"
PLAY_ZONE_POSITION = { x = -26.5, y = 4, z = -26.5 } PLAY_ZONE_POSITION = { x = -26.5, y = 4, z = -26.5 }
PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 } PLAY_ZONE_SCALE = { x = 32, y = 5, z = 12 }
TRASHCAN_GUID = "4b8594" TRASHCAN_GUID = "4b8594"

View File

@ -2,14 +2,10 @@
Cleans up the table for the next scenario in a campaign: 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 - 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 - 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 tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
local playmatAPI = require("playermat/PlaymatApi") local playmatApi = require("playermat/PlaymatApi")
-- enable this for debugging
local SHOW_RAYS = false
-- these objects will be ignored -- these objects will be ignored
local IGNORE_GUIDS = { local IGNORE_GUIDS = {
@ -82,9 +78,7 @@ buttonParameters.function_owner = self
--------------------------------------------------------- ---------------------------------------------------------
function onSave() function onSave()
return JSON.encode({ return JSON.encode({ options = options })
options = options
})
end end
function onLoad(savedData) function onLoad(savedData)
@ -214,7 +208,7 @@ function resetSkillTrackers()
if obj ~= nil then if obj ~= nil then
obj.call("updateStats", { 1, 1, 1, 1 }) obj.call("updateStats", { 1, 1, 1, 1 })
else 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 end
end end
@ -297,7 +291,7 @@ function discardHands()
for i = 1, 4 do for i = 1, 4 do
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i]) local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i])
if trashcan == nil then return end 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 for j = #hand, 1, -1 do
trashcan.putObject(hand[j]) trashcan.putObject(hand[j])
end end
@ -340,7 +334,7 @@ function tidyPlayerMatCoroutine()
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i]) local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i])
if trashcan == nil then if trashcan == nil then
printToAll("Trashcan for " .. COLORS[i] .. " playmat could not be found!", "Red") printToAll("Trashcan for " .. COLORS[i] .. " playmat could not be found!", "Red")
return return 1
end end
for _, entry in ipairs(findObjects(i)) do for _, entry in ipairs(findObjects(i)) do
@ -391,7 +385,7 @@ function findObjects(num)
size = PHYSICS_SCALE[num], size = PHYSICS_SCALE[num],
origin = PHYSICS_POSITION[num], origin = PHYSICS_POSITION[num],
orientation = { 0, PHYSICS_ROTATION[num], 0 }, orientation = { 0, PHYSICS_ROTATION[num], 0 },
debug = SHOW_RAYS debug = false
}) })
end end

View File

@ -1,6 +1,7 @@
require("arkhamdb/DeckImporterUi") require("arkhamdb/DeckImporterUi")
require("playercards/PlayerCardSpawner") require("playercards/PlayerCardSpawner")
local playmatApi = require("playermat/PlaymatApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local arkhamDb = require("arkhamdb/ArkhamDb") local arkhamDb = require("arkhamdb/ArkhamDb")
local zones = require("playermat/Zones") local zones = require("playermat/Zones")
@ -176,7 +177,8 @@ end
---@param deck Object Callback-provided spawned deck object ---@param deck Object Callback-provided spawned deck object
---@param playerColor String Color of the player to draw the cards to ---@param playerColor String Color of the player to draw the cards to
function deckSpawned(deck, playerColor) 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 local deckCards = deck.getData().ContainedObjects
-- Process in reverse order so taking cards out doesn't upset the indexing -- Process in reverse order so taking cards out doesn't upset the indexing
for i = #deckCards, 1, -1 do for i = #deckCards, 1, -1 do

View File

@ -354,7 +354,7 @@ function handleStatTrackerClick(_, _, isRightClick)
playerColor = "White" playerColor = "White"
playerName = "Overall" playerName = "Overall"
else else
playerColor = playmatApi.getHandColor(MAT_GUID_TO_COLOR[key]) playerColor = playmatApi.getPlayerColor(MAT_GUID_TO_COLOR[key])
playerName = Player[playerColor].steam_name or playerColor playerName = Player[playerColor].steam_name or playerColor
local playerSquidCount = personalStats["Auto-fail"] or 0 local playerSquidCount = personalStats["Auto-fail"] or 0

View File

@ -68,7 +68,7 @@ isDES = false
function onSave() function onSave()
return JSON.encode({ return JSON.encode({
zoneID = zoneID, zoneID = zoneID,
playerColor = PLAYER_COLOR, playerColor = playerColor,
activeInvestigatorId = activeInvestigatorId, activeInvestigatorId = activeInvestigatorId,
isDrawButtonVisible = isDrawButtonVisible isDrawButtonVisible = isDrawButtonVisible
}) })
@ -81,6 +81,7 @@ function onLoad(save_state)
STAT_TRACKER = getObjectFromGUID(STAT_TRACKER_GUID) STAT_TRACKER = getObjectFromGUID(STAT_TRACKER_GUID)
RESOURCE_COUNTER = getObjectFromGUID(RESOURCE_COUNTER_GUID) RESOURCE_COUNTER = getObjectFromGUID(RESOURCE_COUNTER_GUID)
-- button creation
for i = 1, 6 do for i = 1, 6 do
makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], {-3.85, 3, 10.38}, i) makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], {-3.85, 3, 10.38}, i)
end end
@ -114,10 +115,11 @@ function onLoad(save_state)
font_size = 180 font_size = 180
}) })
-- save state loading
local state = JSON.decode(save_state) local state = JSON.decode(save_state)
if state ~= nil then if state ~= nil then
zoneID = state.zoneID zoneID = state.zoneID
PLAYER_COLOR = state.playerColor playerColor = state.playerColor
activeInvestigatorId = state.activeInvestigatorId activeInvestigatorId = state.activeInvestigatorId
isDrawButtonVisible = state.isDrawButtonVisible isDrawButtonVisible = state.isDrawButtonVisible
end end
@ -134,15 +136,6 @@ end
-- utility functions -- 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() function spawnDeckZone()
spawnObject({ spawnObject({
position = self.positionToWorld({-1.4, 0, 0.3 }), position = self.positionToWorld({-1.4, 0, 0.3 }),
@ -166,7 +159,9 @@ function searchArea(origin, size)
}) })
end 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 -- Discard buttons
@ -232,19 +227,18 @@ end
-- Upkeep button -- Upkeep button
--------------------------------------------------------- ---------------------------------------------------------
function doUpkeep(_, color, alt_click) function doUpkeep(_, clickedByColor, isRightClick)
setMessageColor(color) -- right-click allow color changing
if isRightClick then
-- right-click binds to new player color changeColor(clickedByColor)
if alt_click then
PLAYER_COLOR = color
printToColor("Upkeep button bound to " .. color, color)
return return
end 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 -- 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 for _, v in ipairs(searchArea(PLAY_ZONE_POSITION, PLAY_ZONE_SCALE)) do
local obj = v.hit_object local obj = v.hit_object
if obj.getDescription() == "Action Token" and obj.is_face_down then if obj.getDescription() == "Action Token" and obj.is_face_down then
@ -305,7 +299,7 @@ function doUpkeep(_, color, alt_click)
if forcedLearning then 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) 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 else
local handSize = #Player[PLAYER_COLOR].getHandObjects() local handSize = #Player[playerColor].getHandObjects()
if handSize < 5 then if handSize < 5 then
local cardsToDraw = 5 - handSize local cardsToDraw = 5 - handSize
printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", messageColor) printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", messageColor)
@ -329,7 +323,8 @@ end
-- function for "draw 1 button" (that can be added via option panel) -- function for "draw 1 button" (that can be added via option panel)
function doDrawOne(_, color) 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) drawCardsWithReshuffle(1)
end end
@ -352,7 +347,7 @@ function drawCardsWithReshuffle(numCards)
end end
if topCard ~= nil then if topCard ~= nil then
topCard.deal(numCards, PLAYER_COLOR) topCard.deal(numCards, playerColor)
numCards = numCards - 1 numCards = numCards - 1
if numCards == 0 then return end if numCards == 0 then return end
end end
@ -403,7 +398,7 @@ end
function drawCards(numCards) function drawCards(numCards)
if drawDeck == nil then return end if drawDeck == nil then return end
drawDeck.deal(numCards, PLAYER_COLOR) drawDeck.deal(numCards, playerColor)
end end
function shuffleDiscardIntoDeck() function shuffleDiscardIntoDeck()
@ -416,8 +411,7 @@ end
-- discard a random non-hidden card from hand -- discard a random non-hidden card from hand
function doDiscardOne() function doDiscardOne()
local handColor = getHandColor() local hand = Player[playerColor].getHandObjects()
local hand = Player[handColor].getHandObjects()
if #hand == 0 then if #hand == 0 then
broadcastToAll("Cannot discard from empty hand!", "Red") broadcastToAll("Cannot discard from empty hand!", "Red")
else else
@ -445,18 +439,72 @@ function doDiscardOne()
end end
end end
-- gets the hand color of the closest seated player (by roughly cutting the table into quarters) ---------------------------------------------------------
function getHandColor() -- color related functions
for _, handColor in ipairs(Player.getAvailableColors()) do ---------------------------------------------------------
local handPosition = Player[handColor].getHandTransform().position
if (PLAYER_COLOR == "White" and handPosition.x < -42 and handPosition.z > 0) -- changes the player color
or (PLAYER_COLOR == "Orange" and handPosition.x < -42 and handPosition.z < 0) function changeColor(clickedByColor)
or (PLAYER_COLOR == "Green" and handPosition.x > -42 and handPosition.z > 0) local colorList = {
or (PLAYER_COLOR == "Red" and handPosition.x > -42 and handPosition.z < 0) then "White",
return handColor "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
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 end
--------------------------------------------------------- ---------------------------------------------------------

View File

@ -43,9 +43,9 @@ do
-- Returns the color of the player's hand that is seated next to the playermat -- Returns the color of the player's hand that is seated next to the playermat
---@param matColor String Color of the playermat ---@param matColor String Color of the playermat
PlaymatApi.getHandColor = function(matColor) PlaymatApi.getPlayerColor = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor]) local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.call("getHandColor") return mat.getVar("playerColor")
end end
-- Returns if there is the card"Dream-Enhancing Serum" on the requested playermat -- Returns if there is the card"Dream-Enhancing Serum" on the requested playermat