Merge pull request #33 from argonui/search-spawner
Update Search a Card to use the new CardSpawner module
This commit is contained in:
commit
fe6992b89f
@ -6,6 +6,8 @@ information = {
|
||||
last_updated = "12.11.2022"
|
||||
}
|
||||
|
||||
require("playercards/PlayerCardSpawner")
|
||||
|
||||
local buttonParameters = {}
|
||||
buttonParameters.function_owner = self
|
||||
buttonParameters.height = 200
|
||||
@ -30,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
|
||||
@ -100,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
|
||||
@ -111,23 +114,15 @@ 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)
|
||||
|
||||
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)
|
||||
end
|
||||
|
@ -1,36 +1,79 @@
|
||||
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.x, rot.y - 90, rot.z}, 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}
|
||||
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()
|
||||
-- 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
|
||||
local deckPos = { pos.x, 3, pos.z }
|
||||
spawnObjectData({
|
||||
data = deck,
|
||||
position = deckPos,
|
||||
position = pos,
|
||||
rotation = rot,
|
||||
callback_function = callback,
|
||||
})
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user