Update Search a Card to use the new CardSpawner module

This required enhancing the CardSpawner to handle mixed card sizes (investigator, standard, mini).
This commit is contained in:
Buhallin 2022-11-13 23:42:44 -08:00
parent bf35013bbc
commit 98469664a2
No known key found for this signature in database
GPG Key ID: DB3C362823852294
2 changed files with 62 additions and 22 deletions

View File

@ -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

View File

@ -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,
})