foundation for custom cards

This commit is contained in:
Chr1Z93 2024-05-24 21:54:29 +02:00
parent 831a4fd4c9
commit afff593874
6 changed files with 174 additions and 191 deletions

View File

@ -150,11 +150,8 @@ end
-- Event handlers for deck ID change
function redDeckChanged(_, _, inputValue) redDeckId = inputValue end
function orangeDeckChanged(_, _, inputValue) orangeDeckId = inputValue end
function whiteDeckChanged(_, _, inputValue) whiteDeckId = inputValue end
function greenDeckChanged(_, _, inputValue) greenDeckId = inputValue end
-- Event handlers for toggle buttons
@ -174,14 +171,7 @@ function loadInvestigatorsChanged()
end
function loadDecks()
-- testLoadLotsOfDecks()
-- Method in DeckImporterMain, visible due to inclusion
local indexReady = allCardsBagApi.isIndexReady()
if (not indexReady) then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
return
end
if not allCardsBagApi.isIndexReady() then return end
if (redDeckId ~= nil and redDeckId ~= "") then
buildDeck("Red", redDeckId)
end

View File

@ -18,7 +18,7 @@ end
-- called once indexing is complete it means the hotfix bag has been added
-- later, and we should rebuild the index to integrate the hotfix bag.
function rebuildIndexForHotfix()
if (indexingDone) then
if indexingDone then
startIndexBuild()
end
end
@ -210,6 +210,9 @@ function cardComparator(id1, id2)
end
function isIndexReady()
if not indexingDone then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
end
return indexingDone
end
@ -221,10 +224,7 @@ end
-- cardData: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata
function getCardById(params)
if (not indexingDone) then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
return { }
end
if not isIndexReady() then return {} end
return cardIdIndex[params.id]
end
@ -237,10 +237,8 @@ end
-- cardData: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata
function getCardsByClassAndLevel(params)
if (not indexingDone) then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
return { }
end
if not isIndexReady() then return {} end
local upgradeKey
if (params.upgraded) then
upgradeKey = "-upgrade"
@ -251,10 +249,7 @@ function getCardsByClassAndLevel(params)
end
function getCardsByCycle(cycleName)
if (not indexingDone) then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
return { }
end
if not isIndexReady() then return {} end
return cycleIndex[string.lower(cycleName)]
end

View File

@ -6,6 +6,14 @@ do
return guidReferenceApi.getObjectByOwnerAndType("Mythos", "AllCardsBag")
end
local function returnCopyOfList(data)
local copiedList = {}
for _, id in ipairs(data) do
table.insert(copiedList, id)
end
return copiedList
end
-- Returns a specific card from the bag, based on ArkhamDB ID
---@param id table String ID of the card to retrieve
---@return table table
@ -14,7 +22,7 @@ do
-- cardData: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata
AllCardsBagApi.getCardById = function(id)
return getAllCardsBag().call("getCardById", {id = id})
return getAllCardsBag().call("getCardById", { id = id })
end
-- Gets a random basic weakness from the bag. Once a given ID has been returned
@ -36,7 +44,7 @@ do
-- called once indexing is complete it means the hotfix bag has been added
-- later, and we should rebuild the index to integrate the hotfix bag.
AllCardsBagApi.rebuildIndexForHotfix = function()
return getAllCardsBag().call("rebuildIndexForHotfix")
getAllCardsBag().call("rebuildIndexForHotfix")
end
-- Searches the bag for cards which match the given name and returns a list. Note that this is
@ -44,7 +52,7 @@ do
---@param name string or string fragment to search for names
---@param exact boolean Whether the name match should be exact
AllCardsBagApi.getCardsByName = function(name, exact)
return getAllCardsBag().call("getCardsByName", {name = name, exact = exact})
return returnCopyOfList(getAllCardsBag().call("getCardsByName", { name = name, exact = exact }))
end
AllCardsBagApi.isBagPresent = function()
@ -59,16 +67,16 @@ do
-- cardData: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata
AllCardsBagApi.getCardsByClassAndLevel = function(class, upgraded)
return getAllCardsBag().call("getCardsByClassAndLevel", {class = class, upgraded = upgraded})
return returnCopyOfList(getAllCardsBag().call("getCardsByClassAndLevel", { class = class, upgraded = upgraded }))
end
AllCardsBagApi.getCardsByCycle = function(cycle)
return getAllCardsBag().call("getCardsByCycle", cycle)
return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", cycle))
end
AllCardsBagApi.getUniqueWeaknesses = function()
return getAllCardsBag().call("getUniqueWeaknesses")
return returnCopyOfList(getAllCardsBag().call("getUniqueWeaknesses"))
end
return AllCardsBagApi
end
end

View File

@ -26,22 +26,20 @@ local CYCLE_BUTTONS_Z_OFFSET = 0.2665
local STARTER_DECK_MODE_SELECTED_COLOR = { 0.2, 0.2, 0.2, 0.8 }
local TRANSPARENT = { 0, 0, 0, 0 }
local STARTER_DECK_MODE_STARTERS = "starters"
local STARTER_DECK_MODE_CARDS_ONLY = "cards"
local FACE_UP_ROTATION = { x = 0, y = 270, z = 0}
local FACE_DOWN_ROTATION = { x = 0, y = 270, z = 180}
local FACE_UP_ROTATION = { x = 0, y = 270, z = 0 }
local FACE_DOWN_ROTATION = { x = 0, y = 270, z = 180 }
-- ---------- IMPORTANT ----------
-- Coordinates defined below are in global dimensions relative to the panel - DO NOT USE THESE
-- DIRECTLY. Call scalePositions() before use, and reference the variables below
-- DIRECTLY. Call scalePositions() before use, and reference the variables below
-- Layout width for a single card, in global coordinate space
local CARD_WIDTH = 2.3
-- Coordinates to begin laying out cards. These vary based on the cards that are being placed by
-- Coordinates to begin laying out cards. These vary based on the cards that are being placed by
-- considering the width of the cards, number of cards, and desired spread intervals.
-- IMPORTANT! Because of the mix of global card sizes and relative-to-scale positions, the X and Y
-- IMPORTANT! Because of the mix of global card sizes and relative-to-scale positions, the X and Y
-- coordinates on these provide global disances while the Z is local.
local START_POSITIONS = {
classCards = Vector(CARD_WIDTH * 9.5, 2, 1.4),
@ -50,7 +48,7 @@ local START_POSITIONS = {
other = Vector(CARD_WIDTH * 9.5, 2, 1.4),
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.
-- should be placed. If more customizable cards are added it will need to be moved.
summonedServitor = Vector(CARD_WIDTH * -7.5, 2, 1.7)
}
@ -64,12 +62,12 @@ local INVESTIGATOR_POSITION_SHIFT_ROW = Vector(0, 0, 11)
local INVESTIGATOR_POSITION_SHIFT_COL = Vector(-6, 0, 0)
local INVESTIGATOR_MAX_COLS = 6
-- Positions relative to the minicard to place other stacks. Both signature card piles and starter
-- Positions relative to the minicard to place other stacks. Both signature card piles and starter
-- decks use SIGNATURE_OFFSET
local INVESTIGATOR_CARD_OFFSET = Vector(0, 0, 2.55)
local INVESTIGATOR_SIGNATURE_OFFSET = Vector(0, 0, 5.75)
-- USE THESE! Positions and offset shifts accounting for the scale of the panel
-- USE THESE! Positions and offset shifts accounting for the scale of the panel
local startPositions
local cardRowOffset
local cardGroupOffset
@ -78,7 +76,14 @@ local investigatorPositionShiftCol
local investigatorCardOffset
local investigatorSignatureOffset
local CLASS_LIST = { "Guardian", "Seeker", "Rogue", "Mystic", "Survivor", "Neutral" }
local CLASS_LIST = {
"Guardian",
"Seeker",
"Rogue",
"Mystic",
"Survivor",
"Neutral"
}
local CYCLE_LIST = {
"Core",
"The Dunwich Legacy",
@ -94,9 +99,8 @@ local CYCLE_LIST = {
}
local excludedNonBasicWeaknesses
local starterDeckMode = STARTER_DECK_MODE_CARDS_ONLY
local helpVisibleToPlayers = { }
local spawnStarterDecks = false
local helpVisibleToPlayers = {}
function onSave()
return JSON.encode({ spawnBagState = spawnBag.getStateForSave() })
@ -104,7 +108,7 @@ end
function onLoad(savedData)
if savedData and savedData ~= "" then
local saveState = JSON.decode(savedData) or { }
local saveState = JSON.decode(savedData) or {}
if saveState.spawnBagState ~= nil then
spawnBag.loadFromSave(saveState.spawnBagState)
end
@ -117,7 +121,7 @@ end
-- Build a list of non-basic weaknesses which should be excluded from the last weakness set,
-- including all signature cards and evolved weaknesses.
function buildExcludedWeaknessList()
excludedNonBasicWeaknesses = { }
excludedNonBasicWeaknesses = {}
for _, investigator in pairs(INVESTIGATORS) do
for _, signatureId in ipairs(investigator.signatures) do
excludedNonBasicWeaknesses[signatureId] = true
@ -274,9 +278,8 @@ function createCycleButtons()
if rowCount == 3 then
-- Account for two centered buttons on the final row
buttonPos.x = buttonPos.x + CYCLE_BUTTONS_X_OFFSET / 2
--[[ Account for centered button on the final row
buttonPos.x = buttonPos.x + CYCLE_BUTTONS_X_OFFSET
]]
-- Account for centered button on the final row
-- buttonPos.x = buttonPos.x + CYCLE_BUTTONS_X_OFFSET
end
else
buttonPos.x = buttonPos.x + CYCLE_BUTTONS_X_OFFSET
@ -297,8 +300,6 @@ function createClearButton()
end
function createInvestigatorModeButtons()
local starterMode = starterDeckMode == STARTER_DECK_MODE_STARTERS
self.createButton({
function_owner = self,
click_function = "setCardsOnlyMode",
@ -306,18 +307,18 @@ function createInvestigatorModeButtons()
height = 170,
width = 760,
scale = Vector(0.25, 1, 0.25),
color = starterMode and TRANSPARENT or STARTER_DECK_MODE_SELECTED_COLOR
color = spawnStarterDecks and TRANSPARENT or STARTER_DECK_MODE_SELECTED_COLOR
})
self.createButton({
function_owner = self,
click_function = "setStarterDeckMode",
click_function = "setspawnStarterDecks",
position = Vector(0.66, 0.1, -0.322),
height = 170,
width = 760,
scale = Vector(0.25, 1, 0.25),
color = starterMode and STARTER_DECK_MODE_SELECTED_COLOR or TRANSPARENT
color = spawnStarterDecks and STARTER_DECK_MODE_SELECTED_COLOR or TRANSPARENT
})
local checkX = starterMode and 0.52 or 0.11
local checkX = spawnStarterDecks and 0.52 or 0.11
self.createButton({
function_owner = self,
label = "✓",
@ -325,7 +326,8 @@ function createInvestigatorModeButtons()
position = Vector(checkX, 0.11, -0.317),
height = 0,
width = 0,
scale = Vector(0.3, 1, 0.3),
font_size = 300,
scale = Vector(0.1, 1, 0.1),
font_color = { 0, 0, 0 },
color = { 1, 1, 1 }
})
@ -354,13 +356,13 @@ function updateHelpVisibility()
self.UI.setAttribute("helpPanel", "active", string.len(visibility) > 0)
end
function setStarterDeckMode()
starterDeckMode = STARTER_DECK_MODE_STARTERS
function setspawnStarterDecks()
spawnStarterDecks = true
updateStarterModeButtons()
end
function setCardsOnlyMode()
starterDeckMode = STARTER_DECK_MODE_CARDS_ONLY
spawnStarterDecks = false
updateStarterModeButtons()
end
@ -384,7 +386,7 @@ end
function scalePositions()
-- Assume scaling is consistent in X and Z dimensions
local scale = 1 / self.getScale().x
startPositions = { }
startPositions = {}
for key, pos in pairs(START_POSITIONS) do
-- Because a scaled object means a different global size, using global distance for Z results in
-- the cards being closer or farther depending on the scale. Leave the Z values and only scale X and Y
@ -405,14 +407,12 @@ function deleteAll()
spawnBag.recall(true)
end
-- Spawn an investigator group, based on the current UI setting for either investigators or starter
-- decks.
-- Spawn an investigator group, based on the current UI setting for either investigators or starter decks
---@param groupName string Name of the group to spawn, matching a key in InvestigatorPanelData
function spawnInvestigatorGroup(groupName)
local starterMode = starterDeckMode == STARTER_DECK_MODE_STARTERS
prepareToPlaceCards()
Wait.frames(function()
if starterMode then
if spawnStarterDecks then
spawnStarters(groupName)
else
spawnInvestigators(groupName)
@ -420,7 +420,7 @@ function spawnInvestigatorGroup(groupName)
end, 2)
end
-- Spawn cards for all investigators in the given group. This creates piles for all defined
-- Spawn cards for all investigators in the given group. This creates piles for all defined
-- investigator cards and minicards as well as the signature cards.
---@param groupName string Name of the group to spawn, matching a key in InvestigatorPanelData
function spawnInvestigators(groupName)
@ -451,14 +451,14 @@ end
function getInvestigatorRowStartPos(investigatorCount, row)
local rowStart = Vector(startPositions.investigator)
rowStart:add(Vector(
investigatorPositionShiftRow.x * (row - 1),
investigatorPositionShiftRow.y * (row - 1),
investigatorPositionShiftRow.z * (row - 1)))
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)
rowStart:add(Vector(
investigatorPositionShiftCol.x * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2,
investigatorPositionShiftCol.y * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2,
investigatorPositionShiftCol.z * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2))
investigatorPositionShiftCol.x * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2,
investigatorPositionShiftCol.y * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2,
investigatorPositionShiftCol.z * (INVESTIGATOR_MAX_COLS - investigatorsInRow) / 2))
return rowStart
end
@ -470,23 +470,23 @@ 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
-- Builds the spawn specs for minicards and investigator cards. These are common enough to be
-- Builds the spawn specs for minicards and investigator cards. These are common enough to be
-- shared, and will only differ in whether they spawn the full stack of possible investigator and
-- minicards, or only the first of each.
---@param investigatorName string Name of the investigator, matching a key in InvestigatorPanelData
---@param investigatorData table Spawn definition for the investigator, retrieved from INVESTIGATORS
---@param position tts__Vector Where to spawn the minicard; investigagor cards will be placed below
---@param oneCardOnly? boolean If true, will spawn only the first card in the investigator card
--- and minicard lists. Otherwise, spawn them all in a deck
--- and minicard lists. Otherwise, spawn them all in a deck
function buildCommonSpawnSpec(investigatorName, investigatorData, position, oneCardOnly)
local cardPos = Vector(position):add(investigatorCardOffset)
return {
@ -533,23 +533,24 @@ function spawnStarterDeck(investigatorName, investigatorData, position)
end
local deckPos = Vector(position):add(investigatorSignatureOffset)
arkhamDb.getDecklist("None", investigatorData.starterDeck, true, false, false, function(slots)
local cardIdList = { }
local cardIdList = {}
for id, count in pairs(slots) do
for i = 1, count do
table.insert(cardIdList, id)
end
end
spawnBag.spawn({
name = investigatorName.."starter",
name = investigatorName .. "starter",
cards = cardIdList,
globalPos = self.positionToWorld(deckPos),
rotation = FACE_DOWN_ROTATION
})
end)
end
-- Clears the currently placed cards, then places cards for the given class and level spread
---@param cardClass string Class to place ("Guardian", "Seeker", etc)
---@param isUpgraded boolean If true, spawn the Level 1-5 cards. Otherwise, Level 0.
---@param isUpgraded boolean If true, spawn the Level 1-5 cards. Otherwise, Level 0.
function spawnClassCards(cardClass, isUpgraded)
prepareToPlaceCards()
Wait.frames(function() placeClassCards(cardClass, isUpgraded) end, 2)
@ -557,18 +558,15 @@ end
-- Spawn the class cards.
---@param cardClass string Class to place ("Guardian", "Seeker", etc)
---@param isUpgraded boolean If true, spawn the Level 1-5 cards. Otherwise, Level 0.
---@param isUpgraded boolean If true, spawn the Level 1-5 cards. Otherwise, Level 0.
function placeClassCards(cardClass, isUpgraded)
local indexReady = allCardsBagApi.isIndexReady()
if (not indexReady) then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
return
end
if not allCardsBagApi.isIndexReady() then return end
local cardIdList = allCardsBagApi.getCardsByClassAndLevel(cardClass, isUpgraded)
local skillList = { }
local eventList = { }
local assetList = { }
local skillList = {}
local eventList = {}
local assetList = {}
for _, cardId in ipairs(cardIdList) do
local cardMetadata = allCardsBagApi.getCardById(cardId).metadata
if (cardMetadata.type == "Skill") then
@ -614,24 +612,22 @@ function placeClassCards(cardClass, isUpgraded)
end
end
-- called by the XML UI to spawn cards from fan-made camnpaigns
function spawnOtherCards()
spawnCycle("Other")
end
-- Spawns the investigator sets and all cards for the given cycle
---@param cycle string Name of a cycle, should match the standard used in card metadata
function spawnCycle(cycle)
if not allCardsBagApi.isIndexReady() then return end
prepareToPlaceCards()
spawnInvestigators(cycle)
local indexReady = allCardsBagApi.isIndexReady()
if (not indexReady) then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
return
end
local cycleCardList = allCardsBagApi.getCardsByCycle(cycle)
local copiedList = { }
for i, id in ipairs(cycleCardList) do
copiedList[i] = id
end
spawnBag.spawn({
name = "cycle"..cycle,
cards = copiedList,
name = "cycle" .. cycle,
cards = allCardsBagApi.getCardsByCycle(cycle),
globalPos = self.positionToWorld(startPositions.cycle),
rotation = FACE_UP_ROTATION,
spread = true,
@ -671,16 +667,13 @@ end
-- Clears the current cards, and places all basic weaknesses on the table.
function spawnWeaknesses()
if not allCardsBagApi.isIndexReady() then return end
prepareToPlaceCards()
local indexReady = allCardsBagApi.isIndexReady()
if (not indexReady) then
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
return
end
local weaknessIdList = allCardsBagApi.getUniqueWeaknesses()
local basicWeaknessList = { }
local otherWeaknessList = { }
for i, id in ipairs(weaknessIdList) do
local basicWeaknessList = {}
local otherWeaknessList = {}
for _, id in ipairs(allCardsBagApi.getUniqueWeaknesses()) do
local cardMetadata = allCardsBagApi.getCardById(id).metadata
if cardMetadata.basicWeaknessCount ~= nil and cardMetadata.basicWeaknessCount > 0 then
table.insert(basicWeaknessList, id)
@ -721,7 +714,7 @@ function spawnRandomWeakness()
prepareToPlaceCards()
local weaknessId = allCardsBagApi.getRandomWeaknessId()
if (weaknessId == nil) then
broadcastToAll("All basic weaknesses are in play!", {0.9, 0.2, 0.2})
broadcastToAll("All basic weaknesses are in play!", { 0.9, 0.2, 0.2 })
return
end
spawnBag.spawn({

View File

@ -1,32 +1,32 @@
require("playercards/PlayerCardSpawner")
-- Allows spawning of defined lists of cards which will be created from the template in the All
-- Player Cards bag. SpawnBag.spawn will create objects based on a table definition, while
-- SpawnBag.recall will clean them all up. Recall will be limited to a small area around the
-- spawned objects. Objects moved out of this area will not be cleaned up.
-- Player Cards bag. SpawnBag.spawn will create objects based on a table definition, while
-- SpawnBag.recall will clean them all up. Recall will be limited to a small area around the
-- spawned objects. Objects moved out of this area will not be cleaned up.
--
-- SpawnSpec: Spawning requires a spawn specification with the following structure:
-- {
-- name: Name of this spawn content, used for internal tracking. Multiple specs can be spawned,
-- name: Name of this spawn content, used for internal tracking. Multiple specs can be spawned,
-- but each requires a separate name
-- cards: A list of card IDs to be spawned
-- globalPos: Where the spawned objects should be placed, in global coordinates. This should be
-- globalPos: Where the spawned objects should be placed, in global coordinates. This should be
-- a valid Vector with x, y, and z defined, e.g. { x = 5, y = 1, z = 15 }
-- rotation: Rotation for the spawned objects. X=180 should be used for face down items. As with
-- rotation: Rotation for the spawned objects. X=180 should be used for face down items. As with
-- globalPos, this should be a valid Vector with x, y, and z defined
-- spread: Optional Boolean. If present and true, cards will be spawned next to each other in a
-- spread moving to the right. globalPos will define the location of the first card, each
-- spread: Optional Boolean. If present and true, cards will be spawned next to each other in a
-- spread moving to the right. globalPos will define the location of the first card, each
-- after that will be moved a predefined distance
-- spreadCols: Optional integer. If spread is true, specifies the maximum columns cards will be
-- laid out in before starting a new row. If spread is true but spreadCols is not set, all
-- spreadCols: Optional integer. If spread is true, specifies the maximum columns cards will be
-- laid out in before starting a new row. If spread is true but spreadCols is not set, all
-- cards will be in a single row (however long that may be)
-- }
-- See BondedBag.ttslua for an example
do
local allCardsBagApi = require("playercards/AllCardsBagApi")
local SpawnBag = { }
local internal = { }
local SpawnBag = {}
local internal = {}
-- To assist debugging, will draw a box around the recall zone when it's set up
local SHOW_RECALL_ZONE = false
@ -36,8 +36,8 @@ do
local RECALL_BUFFER_Z = 0.5
-- In order to mimic the behavior of the previous memory buttons we use a temporary bag when
-- recalling objects. This bag is tiny and transparent, and will be placed at the same location as
-- this object. Once all placed cards are recalled bag to this bag, it will be destroyed
-- recalling objects. This bag is tiny and transparent, and will be placed at the same location as
-- this object. Once all placed cards are recalled bag to this bag, it will be destroyed
local RECALL_BAG = {
Name = "Bag",
Transform = {
@ -58,8 +58,8 @@ do
}
-- Tracks what has been placed by this "bag" so they can be recalled
local placedSpecs = { }
local placedObjectGuids = { }
local placedSpecs = {}
local placedObjectGuids = {}
local recallZone = nil
-- Loads a table of saved state, extracted during the parent object's onLoad
@ -81,21 +81,13 @@ do
-- Places the given spawnSpec on the table. See comment at the start of the file for spawnSpec table data and examples
SpawnBag.spawn = function(spawnSpec)
-- Limit to one placement at a time
if (placedSpecs[spawnSpec.name]) then
return
end
if (spawnSpec == nil) then
-- TODO: error here
return
end
local cardsToSpawn = { }
local cardList = spawnSpec.cards
for _, cardId in ipairs(cardList) do
if placedSpecs[spawnSpec.name] or spawnSpec == nil then return end
local cardsToSpawn = {}
for _, cardId in ipairs(spawnSpec.cards) do
local cardData = allCardsBagApi.getCardById(cardId)
if (cardData ~= nil) then
if cardData ~= nil then
table.insert(cardsToSpawn, cardData)
else
-- TODO: error here
end
end
if (spawnSpec.spread) then
@ -120,14 +112,13 @@ do
internal.recallSpawned()
end
-- We've recalled everything we can, some cards may have been moved out of the
-- card area. Just reset at this point.
placedSpecs = { }
placedObjectGuids = { }
-- We've recalled everything we can, some cards may have been moved out of the card area. Just reset at this point.
placedSpecs = {}
placedObjectGuids = {}
recallZone = nil
end
-- Deleted all spawned cards.
-- Delete all spawned cards
internal.deleteSpawned = function()
for guid, _ in pairs(placedObjectGuids) do
local obj = getObjectFromGUID(guid)
@ -140,9 +131,9 @@ do
end
end
-- Recalls spawned cards with a fake bag that replicates the memory bag recall style.
-- Recalls spawned cards with a fake bag that replicates the memory bag recall style
internal.recallSpawned = function()
local trash = spawnObjectData({data = RECALL_BAG, position = self.getPosition()})
local trash = spawnObjectData({ data = RECALL_BAG, position = self.getPosition() })
for guid, _ in pairs(placedObjectGuids) do
local obj = getObjectFromGUID(guid)
if (obj ~= nil) then
@ -156,71 +147,70 @@ do
trash.destruct()
end
-- Callback for when an object has been spawned. Tracks the object for later recall and updates the
-- recall zone.
-- Callback for when an object has been spawned. Tracks the object for later recall and updates the recall zone.
internal.recordPlacedObject = function(spawned)
placedObjectGuids[spawned.getGUID()] = true
internal.expandRecallZone(spawned)
end
-- Expands the current recall zone based on the position of the given object. The recall zone will
-- Expands the current recall zone based on the position of the given object. The recall zone will
-- be maintained as the bounding box of the extreme object positions, plus a small amount of buffer
internal.expandRecallZone = function(spawnedCard)
local pos = spawnedCard.getPosition()
if (recallZone == nil) then
-- First card out of the bag, initialize surrounding that
recallZone = { }
recallZone = {}
recallZone.upperLeft = { x = pos.x + RECALL_BUFFER_X, z = pos.z + RECALL_BUFFER_Z }
recallZone.lowerRight = { x = pos.x - RECALL_BUFFER_X, z = pos.z - RECALL_BUFFER_Z }
return
else
if (pos.x > recallZone.upperLeft.x) then
recallZone.upperLeft.x = pos.x + RECALL_BUFFER_X
end
if (pos.x < recallZone.lowerRight.x) then
recallZone.lowerRight.x = pos.x - RECALL_BUFFER_X
end
if (pos.z > recallZone.upperLeft.z) then
recallZone.upperLeft.z = pos.z + RECALL_BUFFER_Z
end
if (pos.z < recallZone.lowerRight.z) then
recallZone.lowerRight.z = pos.z - RECALL_BUFFER_Z
end
end
if (SHOW_RECALL_ZONE) then
if pos.x > recallZone.upperLeft.x then
recallZone.upperLeft.x = pos.x + RECALL_BUFFER_X
end
if pos.x < recallZone.lowerRight.x then
recallZone.lowerRight.x = pos.x - RECALL_BUFFER_X
end
if pos.z > recallZone.upperLeft.z then
recallZone.upperLeft.z = pos.z + RECALL_BUFFER_Z
end
if pos.z < recallZone.lowerRight.z then
recallZone.lowerRight.z = pos.z - RECALL_BUFFER_Z
end
if SHOW_RECALL_ZONE then
local y = 1.5
local thick = 0.05
Global.setVectorLines({
{
points = { {recallZone.upperLeft.x,y,recallZone.upperLeft.z}, {recallZone.upperLeft.x,y,recallZone.lowerRight.z} },
color = {1,0,0},
points = { { recallZone.upperLeft.x, y, recallZone.upperLeft.z }, { recallZone.upperLeft.x, y, recallZone.lowerRight.z } },
color = { 1, 0, 0 },
thickness = thick,
rotation = {0,0,0}
rotation = { 0, 0, 0 }
},
{
points = { {recallZone.upperLeft.x,y,recallZone.lowerRight.z}, {recallZone.lowerRight.x,y,recallZone.lowerRight.z} },
color = {1,0,0},
points = { { recallZone.upperLeft.x, y, recallZone.lowerRight.z }, { recallZone.lowerRight.x, y, recallZone.lowerRight.z } },
color = { 1, 0, 0 },
thickness = thick,
rotation = {0,0,0}
rotation = { 0, 0, 0 }
},
{
points = { {recallZone.lowerRight.x,y,recallZone.lowerRight.z}, {recallZone.lowerRight.x,y,recallZone.upperLeft.z} },
color = {1,0,0},
points = { { recallZone.lowerRight.x, y, recallZone.lowerRight.z }, { recallZone.lowerRight.x, y, recallZone.upperLeft.z } },
color = { 1, 0, 0 },
thickness = thick,
rotation = {0,0,0}
rotation = { 0, 0, 0 }
},
{
points = { {recallZone.lowerRight.x,y,recallZone.upperLeft.z}, {recallZone.upperLeft.x,y,recallZone.upperLeft.z} },
color = {1,0,0},
points = { { recallZone.lowerRight.x, y, recallZone.upperLeft.z }, { recallZone.upperLeft.x, y, recallZone.upperLeft.z } },
color = { 1, 0, 0 },
thickness = thick,
rotation = {0,0,0}
rotation = { 0, 0, 0 }
}
})
end
end
-- Checks to see if the given object is in the current recall zone. If there isn't a recall zone,
-- Checks to see if the given object is in the current recall zone. If there isn't a recall zone,
-- will return true so that everything can be easily cleaned up.
internal.isInRecallZone = function(obj)
if (recallZone == nil) then
@ -228,11 +218,11 @@ do
end
local pos = obj.getPosition()
return (pos.x < recallZone.upperLeft.x and pos.x > recallZone.lowerRight.x
and pos.z < recallZone.upperLeft.z and pos.z > recallZone.lowerRight.z)
and pos.z < recallZone.upperLeft.z and pos.z > recallZone.lowerRight.z)
end
internal.reverseList = function(list)
local reversed = { }
local reversed = {}
for i = 1, #list do
reversed[i] = list[#list - i + 1]
end

View File

@ -1,24 +1,31 @@
<Panel
active="false"
<Panel active="false"
id="helpPanel"
position="-165 -60 -2"
position="-165 -70 -2"
rotation="0 0 180"
height="55"
height="50"
width="107"
color="#00000099">
<Text
id="helpText"
<Text id="helpText"
rectAlignment="MiddleCenter"
height="490"
height="480"
width="1000"
scale="0.1 0.1 1"
fontSize="66"
color="#F5F5F5"
backgroundColor="#FF0000"
alignment="UpperLeft"
alignment="MiddleLeft"
horizontalOverflow="wrap">
• Select a group to place cards
• Copy the cards you want for your deck
• Select a new group to clear the placed cards and see new ones
• Clear to remove all cards</Text>
</Panel>
<Panel position="45 65 -11"
rotation="0 0 180"
height="200"
width="200"
scale="0.1 0.1 1"
color="#FFFFFF"
onClick="spawnOtherCards">
</Panel>