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"
|
last_updated = "12.11.2022"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require("playercards/PlayerCardSpawner")
|
||||||
|
|
||||||
local buttonParameters = {}
|
local buttonParameters = {}
|
||||||
buttonParameters.function_owner = self
|
buttonParameters.function_owner = self
|
||||||
buttonParameters.height = 200
|
buttonParameters.height = 200
|
||||||
@ -30,7 +32,7 @@ inputParameters.width = 1200
|
|||||||
inputParameters.height = 130
|
inputParameters.height = 130
|
||||||
inputParameters.font_size = 107
|
inputParameters.font_size = 107
|
||||||
|
|
||||||
local allCardsBag = getObjectFromGUID("15bb07")
|
local ALL_CARDS_GUID = "15bb07"
|
||||||
|
|
||||||
-- main code
|
-- main code
|
||||||
function onSave() return JSON.encode({ spawnAll, searchExact, inputParameters.value }) end
|
function onSave() return JSON.encode({ spawnAll, searchExact, inputParameters.value }) end
|
||||||
@ -100,6 +102,7 @@ function search()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID)
|
||||||
if allCardsBag == nil then
|
if allCardsBag == nil then
|
||||||
printToAll("Player card bag couldn't be found.", "Red")
|
printToAll("Player card bag couldn't be found.", "Red")
|
||||||
return
|
return
|
||||||
@ -111,23 +114,15 @@ function search()
|
|||||||
printToAll("No match found.", "Red")
|
printToAll("No match found.", "Red")
|
||||||
return
|
return
|
||||||
end
|
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)
|
-- 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)
|
table.sort(cardList, function(k1, k2) return spawnAll == (k1.data.Nickname > k2.data.Nickname) end)
|
||||||
|
|
||||||
local rot = self.getRotation()
|
local rot = self.getRotation()
|
||||||
local pos = self.positionToWorld(Vector(0, 0, -0.225))
|
local pos = self.positionToWorld(Vector(0, 2, -0.225))
|
||||||
for _, card in ipairs(cardList) do
|
Spawner.spawnCards(cardList, pos, rot, true)
|
||||||
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
|
end
|
||||||
|
@ -1,36 +1,79 @@
|
|||||||
Spawner = { }
|
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 cardList: A list of Player Card data structures (data/metadata)
|
||||||
-- @param pos Position table where the cards should be spawned (global)
|
-- @param pos Position table where the cards should be spawned (global)
|
||||||
-- @param rot Rotation table for the orientation of the spawned cards (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 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)
|
Spawner.spawnCards = function(cardList, pos, rot, sort, callback)
|
||||||
if (sort) then
|
if (sort) then
|
||||||
table.sort(cardList, Spawner.cardComparator)
|
table.sort(cardList, Spawner.cardComparator)
|
||||||
end
|
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
|
-- Spawn a single card directly
|
||||||
if (#cardList == 1) then
|
if (#cardList == 1) then
|
||||||
local cardPos = { pos.x, 2, pos.z}
|
|
||||||
spawnObjectData({
|
spawnObjectData({
|
||||||
data = cardList[1].data,
|
data = cardList[1].data,
|
||||||
position = cardPos,
|
position = pos,
|
||||||
rotation = rot,
|
rotation = rot,
|
||||||
callback_function = callback,
|
callback_function = callback,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
-- For multiple cards, construct a deck and spawn that
|
||||||
-- Multiple cards, build a deck and spawn that
|
|
||||||
local deck = Spawner.buildDeckDataTemplate()
|
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
|
for _, spawnCard in ipairs(cardList) do
|
||||||
Spawner.addCardToDeck(deck, spawnCard.data)
|
Spawner.addCardToDeck(deck, spawnCard.data)
|
||||||
end
|
end
|
||||||
local deckPos = { pos.x, 3, pos.z }
|
|
||||||
spawnObjectData({
|
spawnObjectData({
|
||||||
data = deck,
|
data = deck,
|
||||||
position = deckPos,
|
position = pos,
|
||||||
rotation = rot,
|
rotation = rot,
|
||||||
callback_function = callback,
|
callback_function = callback,
|
||||||
})
|
})
|
||||||
|
@ -129,9 +129,7 @@ end
|
|||||||
function Zones.getDefaultCardRotation(playerColor, zone)
|
function Zones.getDefaultCardRotation(playerColor, zone)
|
||||||
local deckRotation = getObjectFromGUID(playerMatGuids[playerColor]).getRotation()
|
local deckRotation = getObjectFromGUID(playerMatGuids[playerColor]).getRotation()
|
||||||
|
|
||||||
if zone == "Investigator" then
|
if zone == "Deck" then
|
||||||
deckRotation = deckRotation + Vector(0, 270, 0)
|
|
||||||
elseif zone == "Deck" then
|
|
||||||
deckRotation = deckRotation + Vector(0, 0, 180)
|
deckRotation = deckRotation + Vector(0, 0, 180)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user