From 98469664a25d7f87776be4eed16cb3e08235ae82 Mon Sep 17 00:00:00 2001 From: Buhallin Date: Sun, 13 Nov 2022 23:42:44 -0800 Subject: [PATCH 1/4] Update Search a Card to use the new CardSpawner module This required enhancing the CardSpawner to handle mixed card sizes (investigator, standard, mini). --- src/playercards/CardSearch.ttslua | 31 +++++++------- src/playercards/PlayerCardSpawner.ttslua | 53 ++++++++++++++++++++---- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/playercards/CardSearch.ttslua b/src/playercards/CardSearch.ttslua index 23b3086c..a768ea9f 100644 --- a/src/playercards/CardSearch.ttslua +++ b/src/playercards/CardSearch.ttslua @@ -6,6 +6,8 @@ information = { last_updated = "12.11.2022" } +require("playercards/PlayerCardSpawner") + local buttonParameters = {} buttonParameters.function_owner = self buttonParameters.height = 200 @@ -116,18 +118,19 @@ function search() table.sort(cardList, function(k1, k2) return spawnAll == (k1.data.Nickname > k2.data.Nickname) end) local rot = self.getRotation() - local pos = self.positionToWorld(Vector(0, 0, -0.225)) - for _, card in ipairs(cardList) do - pos[2] = pos[2] + 0.1 - spawnObjectData({ - data = card.data, - position = pos, - rotation = rot - }) - if not spawnAll then return end - if i == 100 then - printToAll("Only first 100 results of " .. #cardList .. " total results spawned.", "Yellow") - return - end - end + local pos = self.positionToWorld(Vector(0, 2, -0.225)) + Spawner.spawnCards(cardList, pos, rot, true) + -- for _, card in ipairs(cardList) do + -- pos[2] = pos[2] + 0.1 + -- spawnObjectData({ + -- data = card.data, + -- position = pos, + -- rotation = rot + -- }) + -- if not spawnAll then return end + -- if i == 100 then + -- printToAll("Only first 100 results of " .. #cardList .. " total results spawned.", "Yellow") + -- return + -- end + -- end end diff --git a/src/playercards/PlayerCardSpawner.ttslua b/src/playercards/PlayerCardSpawner.ttslua index c7be6553..40d152a8 100644 --- a/src/playercards/PlayerCardSpawner.ttslua +++ b/src/playercards/PlayerCardSpawner.ttslua @@ -1,36 +1,73 @@ Spawner = { } --- Spawns a list of cards at the given position/rotation +-- Spawns a list of cards at the given position/rotation. This will separate cards by size - +-- 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 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) end + + local miniCards = { } + local standardCards = { } + local investigatorCards = { } + + for _, card in ipairs(cardList) do + if (card.metadata.type == "Investigator") then + table.insert(investigatorCards, card) + elseif (card.metadata.type == "Minicard") then + table.insert(miniCards, card) + else + table.insert(standardCards, card) + end + end + -- Spawn each of the three types individually. Each Y position shift accounts for the thickness + -- of the spawned deck + local position = { x = pos.x, y = pos.y, z = pos.z } + Spawner.spawn(investigatorCards, position, rot, callback) + + position.y = position.y + (#investigatorCards + #standardCards) * 0.07 + Spawner.spawn(standardCards, position, rot, callback) + + position.y = position.y + (#standardCards + #miniCards) * 0.07 + Spawner.spawn(miniCards, position, rot, callback) +end + +-- Spawn a specific list of cards. This method is for internal use and should not be called +-- directly, use spawnCards instead. +-- @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 callback Function, callback to be called after the card/deck spawns. +Spawner.spawn = function(cardList, pos, rot, callback) + if (#cardList == 0) then + return + end -- Spawn a single card directly if (#cardList == 1) then - local cardPos = { pos.x, 2, pos.z} + log(pos) spawnObjectData({ data = cardList[1].data, - position = cardPos, + position = pos, rotation = rot, callback_function = callback, }) return end - - -- Multiple cards, build a deck and spawn that + -- For multiple cards, construct a deck and spawn that local deck = Spawner.buildDeckDataTemplate() for _, spawnCard in ipairs(cardList) do Spawner.addCardToDeck(deck, spawnCard.data) end - local deckPos = { pos.x, 3, pos.z } spawnObjectData({ data = deck, - position = deckPos, + position = pos, rotation = rot, callback_function = callback, }) From 258e8aec79d632ac41b4e734faa5b1944f027302 Mon Sep 17 00:00:00 2001 From: Buhallin Date: Sun, 13 Nov 2022 23:51:52 -0800 Subject: [PATCH 2/4] Rotate investigator cards 90 degrees when spawning, so they match the orientation of other cards --- src/playercards/PlayerCardSpawner.ttslua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playercards/PlayerCardSpawner.ttslua b/src/playercards/PlayerCardSpawner.ttslua index 40d152a8..32f635a2 100644 --- a/src/playercards/PlayerCardSpawner.ttslua +++ b/src/playercards/PlayerCardSpawner.ttslua @@ -30,7 +30,7 @@ Spawner.spawnCards = function(cardList, pos, rot, sort, callback) -- Spawn each of the three types individually. Each Y position shift accounts for the thickness -- of the spawned deck local position = { x = pos.x, y = pos.y, z = pos.z } - Spawner.spawn(investigatorCards, position, rot, callback) + Spawner.spawn(investigatorCards, position, { rot.x, rot.y - 90, rot.z}, callback) position.y = position.y + (#investigatorCards + #standardCards) * 0.07 Spawner.spawn(standardCards, position, rot, callback) From a516175177c2a9f5b47e7d31af416f824235b57c Mon Sep 17 00:00:00 2001 From: Buhallin Date: Sun, 13 Nov 2022 23:56:29 -0800 Subject: [PATCH 3/4] Remove investigator card rotation handling from deck loader, since the spawner handles it now --- src/playermat/Zones.ttslua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/playermat/Zones.ttslua b/src/playermat/Zones.ttslua index b69f1e80..bdd6a6b4 100644 --- a/src/playermat/Zones.ttslua +++ b/src/playermat/Zones.ttslua @@ -129,9 +129,7 @@ end function Zones.getDefaultCardRotation(playerColor, zone) local deckRotation = getObjectFromGUID(playerMatGuids[playerColor]).getRotation() - if zone == "Investigator" then - deckRotation = deckRotation + Vector(0, 270, 0) - elseif zone == "Deck" then + if zone == "Deck" then deckRotation = deckRotation + Vector(0, 0, 180) end From fa4d1f428d6698f894b14a4e8ce2417724cd7f88 Mon Sep 17 00:00:00 2001 From: Buhallin Date: Mon, 14 Nov 2022 02:02:18 -0800 Subject: [PATCH 4/4] Finish some missed cleanup and fix a bug with deck size --- src/playercards/CardSearch.ttslua | 20 ++++++-------------- src/playercards/PlayerCardSpawner.ttslua | 8 +++++++- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/playercards/CardSearch.ttslua b/src/playercards/CardSearch.ttslua index a768ea9f..9c179f1d 100644 --- a/src/playercards/CardSearch.ttslua +++ b/src/playercards/CardSearch.ttslua @@ -32,7 +32,7 @@ inputParameters.width = 1200 inputParameters.height = 130 inputParameters.font_size = 107 -local allCardsBag = getObjectFromGUID("15bb07") +local ALL_CARDS_GUID = "15bb07" -- main code function onSave() return JSON.encode({ spawnAll, searchExact, inputParameters.value }) end @@ -102,6 +102,7 @@ function search() return end + local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID) if allCardsBag == nil then printToAll("Player card bag couldn't be found.", "Red") return @@ -113,6 +114,10 @@ function search() printToAll("No match found.", "Red") return end + if (#cardList > 100) then + printToAll("Matched more than 100 cards, please try a more specific search.", "Yellow") + return + end -- sort table by name (reverse for multiple results, because bottom card spawns first) table.sort(cardList, function(k1, k2) return spawnAll == (k1.data.Nickname > k2.data.Nickname) end) @@ -120,17 +125,4 @@ function search() local rot = self.getRotation() local pos = self.positionToWorld(Vector(0, 2, -0.225)) Spawner.spawnCards(cardList, pos, rot, true) - -- for _, card in ipairs(cardList) do - -- pos[2] = pos[2] + 0.1 - -- spawnObjectData({ - -- data = card.data, - -- position = pos, - -- rotation = rot - -- }) - -- if not spawnAll then return end - -- if i == 100 then - -- printToAll("Only first 100 results of " .. #cardList .. " total results spawned.", "Yellow") - -- return - -- end - -- end end diff --git a/src/playercards/PlayerCardSpawner.ttslua b/src/playercards/PlayerCardSpawner.ttslua index 32f635a2..d0e1eef6 100644 --- a/src/playercards/PlayerCardSpawner.ttslua +++ b/src/playercards/PlayerCardSpawner.ttslua @@ -51,7 +51,6 @@ Spawner.spawn = function(cardList, pos, rot, callback) end -- Spawn a single card directly if (#cardList == 1) then - log(pos) spawnObjectData({ data = cardList[1].data, position = pos, @@ -62,6 +61,13 @@ Spawner.spawn = function(cardList, pos, rot, callback) 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, + } for _, spawnCard in ipairs(cardList) do Spawner.addCardToDeck(deck, spawnCard.data) end