Merge pull request #568 from argonui/spawner

Updated "Spawner" library
This commit is contained in:
BootleggerFinn 2024-02-15 11:19:10 -06:00 committed by GitHub
commit 50a79f1c43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 34 deletions

View File

@ -105,9 +105,9 @@ do
if (adbCardInfo.xp ~= nil and adbCardInfo.xp > 0) then
cardName = cardName .. " (" .. adbCardInfo.xp .. ")"
end
internal.maybePrint("Card not found: " .. cardName .. ", ArkhamDB ID " .. cardId, playerColor)
internal.maybePrint("Card not found: " .. cardName .. ", card ID " .. cardId, playerColor)
else
internal.maybePrint("Card not found in ArkhamDB, ID " .. cardId, playerColor)
internal.maybePrint("Card not found in ArkhamDB/Index, ID " .. cardId, playerColor)
end
end)
end
@ -142,12 +142,14 @@ do
-- investigator may have bonded cards or taboo entries, and should be present
local slots = deck.slots
internal.maybeDrawRandomWeakness(slots, playerColor)
-- handles alternative investigators (parallel, promo or revised art)
local loadAltInvestigator = "normal"
if loadInvestigators then
loadAltInvestigator = internal.addInvestigatorCards(deck, slots)
end
internal.maybeModifyDeckFromDescription(slots, deck.description_md)
internal.maybeModifyDeckFromDescription(slots, deck.description_md, playerColor)
internal.maybeAddSummonedServitor(slots)
internal.maybeAddOnTheMend(slots, playerColor)
internal.maybeAddRealityAcidReference(slots)
@ -193,6 +195,7 @@ do
local investigatorId = deck.investigator_code
slots[investigatorId .. "-m"] = 1
local deckMeta = JSON.decode(deck.meta)
-- handling alternative investigator art and parallel investigators
local loadAltInvestigator = "normal"
if deckMeta ~= nil then
@ -291,7 +294,7 @@ do
-- Processes the deck description from ArkhamDB and modifies the slot list accordingly
---@param slots table The slot list for cards in this deck. Table key is the cardId, value is the number
---@param description string The deck desription from ArkhamDB
internal.maybeModifyDeckFromDescription = function(slots, description)
internal.maybeModifyDeckFromDescription = function(slots, description, playerColor)
-- check for import instructions
local pos = string.find(description, "++SCED import instructions++")
if not pos then return end
@ -328,12 +331,19 @@ do
if instructor == "add:" then
slots[str] = (slots[str] or 0) + 1
elseif instructor == "remove:" then
if slots[str] == nil then break end
if slots[str] == nil then
internal.maybePrint("Tried to remove " .. str .. ", but didn't find card in deck.", playerColor)
break
end
slots[str] = math.max(slots[str] - 1, 0)
-- fully remove cards that have a quantity of 0
if slots[str] == 0 then
slots[str] = nil
end
-- also remove related minicard
slots[str .. "-m"] = nil
end
end
end

View File

@ -109,8 +109,8 @@ function loadCards(slots, investigatorId, bondedList, customizations, playerColo
local zoneDecks = buildZoneLists(cardsToSpawn)
-- Spawn the list for each zone
for zone, zoneCards in pairs(zoneDecks) do
local deckPos = zones.getZonePosition(playerColor, zone)
deckPos.y = 3
local deckPos = zones.getZonePosition(playerColor, zone):setAt("y", 3)
local deckRot = zones.getDefaultCardRotation(playerColor, zone)
local callback = nil
-- If cards are spread too close together TTS groups them weirdly, selecting multiples
@ -132,13 +132,7 @@ function loadCards(slots, investigatorId, bondedList, customizations, playerColo
elseif zone == "Investigator" or zone == "Minicard" then
callback = function(card) loadAltArt(card, loadAltInvestigator) end
end
Spawner.spawnCards(
zoneCards,
deckPos,
zones.getDefaultCardRotation(playerColor, zone),
true, -- Sort deck
callback)
Spawner.spawnCards(zoneCards, deckPos, deckRot, true, callback)
coroutine.yield(0)
end

View File

@ -51,7 +51,7 @@ local START_POSITIONS = {
randomWeakness = Vector(0, 2, 1.4),
-- Because the card spread is handled by the SpawnBag, we don't know (programatically) where this
-- should be placed. If more customizable cards are added it will need to be moved.
summonedServitor = Vector(CARD_WIDTH * -7.5, 2, 1.7),
summonedServitor = Vector(CARD_WIDTH * -7.5, 2, 1.7)
}
-- Shifts to move rows of cards, and groups of rows, as different groupings are laid out
@ -454,13 +454,11 @@ function getInvestigatorRowStartPos(investigatorCount, row)
investigatorPositionShiftRow.x * (row - 1),
investigatorPositionShiftRow.y * (row - 1),
investigatorPositionShiftRow.z * (row - 1)))
local investigatorsInRow =
math.min(investigatorCount - INVESTIGATOR_MAX_COLS * (row - 1), INVESTIGATOR_MAX_COLS)
local investigatorsInRow = math.min(investigatorCount - INVESTIGATOR_MAX_COLS * (row - 1), INVESTIGATOR_MAX_COLS)
rowStart:add(Vector(
investigatorPositionShiftCol.x * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2,
investigatorPositionShiftCol.y * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2,
investigatorPositionShiftCol.z * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2))
return rowStart
end
@ -472,11 +470,11 @@ function buildInvestigatorSpawnSpec(investigatorName, investigatorData, position
local sigPos = Vector(position):add(investigatorSignatureOffset)
local spawns = buildCommonSpawnSpec(investigatorName, investigatorData, position)
table.insert(spawns, {
name = investigatorName.."signatures",
cards = investigatorData.signatures,
globalPos = self.positionToWorld(sigPos),
rotation = FACE_UP_ROTATION,
})
name = investigatorName .. "signatures",
cards = investigatorData.signatures,
globalPos = self.positionToWorld(sigPos),
rotation = FACE_UP_ROTATION
})
return spawns
end
@ -493,16 +491,16 @@ function buildCommonSpawnSpec(investigatorName, investigatorData, position, oneC
local cardPos = Vector(position):add(investigatorCardOffset)
return {
{
name = investigatorName.."minicards",
name = investigatorName .. "minicards",
cards = oneCardOnly and { investigatorData.minicards[1] } or investigatorData.minicards,
globalPos = self.positionToWorld(position),
rotation = FACE_UP_ROTATION,
rotation = FACE_UP_ROTATION
},
{
name = investigatorName.."cards",
name = investigatorName .. "cards",
cards = oneCardOnly and { investigatorData.cards[1] } or investigatorData.cards,
globalPos = self.positionToWorld(cardPos),
rotation = FACE_UP_ROTATION,
rotation = FACE_UP_ROTATION
}
}
end
@ -530,8 +528,7 @@ end
-- Spawns the defined starter deck for the given investigator's.
---@param investigatorName string Name of the investigator, matching a key in InvestigatorPanelData
function spawnStarterDeck(investigatorName, investigatorData, position)
for _, spawnSpec in ipairs(
buildCommonSpawnSpec(investigatorName, INVESTIGATORS[investigatorName], position, true)) do
for _, spawnSpec in ipairs(buildCommonSpawnSpec(investigatorName, investigatorData, position, true)) do
spawnBag.spawn(spawnSpec)
end
local deckPos = Vector(position):add(investigatorSignatureOffset)

View File

@ -36,7 +36,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.x, rot.y - 90, rot.z }, callback)
Spawner.spawn(investigatorCards, position, rot, callback)
position.y = position.y + (#investigatorCards + #standardCards) * 0.07
Spawner.spawn(standardCards, position, rot, callback)
@ -85,7 +85,11 @@ Spawner.spawn = function(cardList, pos, rot, callback)
if #cardList == 0 then return end
-- Spawn a single card directly
if (#cardList == 1) then
if #cardList == 1 then
-- handle sideways card
if cardList[1].data.SidewaysCard then
rot = { rot.x, rot.y - 90, rot.z }
end
spawnObjectData({
data = cardList[1].data,
position = pos,
@ -105,6 +109,7 @@ Spawner.spawn = function(cardList, pos, rot, callback)
scaleY = 1,
scaleZ = cardList[1].data.Transform.scaleZ
}
local sidewaysDeck = true
for _, spawnCard in ipairs(cardList) do
Spawner.addCardToDeck(deck, spawnCard.data)
@ -112,9 +117,10 @@ Spawner.spawn = function(cardList, pos, rot, callback)
sidewaysDeck = (sidewaysDeck and spawnCard.data.SidewaysCard)
end
-- set the alt view angle for sideway decks
-- set the alt view angle for sideways decks
if sidewaysDeck then
deck.AltLookAngle = { x = 0, y = 180, z = 90 }
rot = { rot.x, rot.y - 90, rot.z }
end
spawnObjectData({
@ -198,7 +204,6 @@ Spawner.findNextAvailableId = function(objectTable, startId)
while (objectTable[id] ~= nil) do
id = tostring(tonumber(id) + 1)
end
return id
end