updated XML

This commit is contained in:
Chr1Z93 2024-05-28 01:02:36 +02:00
parent acbd1ea922
commit fbd70c0f74
7 changed files with 106 additions and 81 deletions

View File

@ -60,5 +60,5 @@
"scaleZ": 10 "scaleZ": 10
}, },
"Value": 0, "Value": 0,
"XmlUI": "\u003cInclude src=\"playercards/PlayerCardPanel.xml\"/\u003e" "XmlUI": ""
} }

View File

@ -1,3 +1,5 @@
local guidReferenceApi = require("core/GUIDReferenceApi")
local cardIdIndex = { } local cardIdIndex = { }
local classAndLevelIndex = { } local classAndLevelIndex = { }
local basicWeaknessList = { } local basicWeaknessList = { }
@ -5,6 +7,7 @@ local uniqueWeaknessList = { }
local cycleIndex = { } local cycleIndex = { }
local indexingDone = false local indexingDone = false
local otherCardsDetected = false
function onLoad() function onLoad()
self.addContextMenuItem("Rebuild Index", startIndexBuild) self.addContextMenuItem("Rebuild Index", startIndexBuild)
@ -63,6 +66,7 @@ end
function buildIndex() function buildIndex()
local cardCount = 0 local cardCount = 0
indexingDone = false indexingDone = false
otherCardsDetected = false
-- process the allcardsbag itself -- process the allcardsbag itself
for _, cardData in ipairs(self.getData().ContainedObjects) do for _, cardData in ipairs(self.getData().ContainedObjects) do
@ -108,6 +112,7 @@ function buildIndex()
end end
buildSupplementalIndexes() buildSupplementalIndexes()
updatePlayerCardPanel()
indexingDone = true indexingDone = true
return 1 return 1
end end
@ -174,6 +179,7 @@ function buildSupplementalIndexes()
else else
-- track cards without defined cycle (should only be fan-made cards) -- track cards without defined cycle (should only be fan-made cards)
cycleName = "other" cycleName = "other"
otherCardsDetected = true
end end
-- maybe initialize table -- maybe initialize table
@ -214,6 +220,12 @@ function cardComparator(id1, id2)
end end
end end
-- inform the player card panel about the presence of other cards (no cycle -> fan-made)
function updatePlayerCardPanel()
local panel = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayerCardPanel")
panel.call("createXML", otherCardsDetected)
end
---@return boolean: If true, the bag is currently not indexing and ready to be accessed ---@return boolean: If true, the bag is currently not indexing and ready to be accessed
function isIndexReady() function isIndexReady()
if not indexingDone then if not indexingDone then
@ -223,14 +235,14 @@ function isIndexReady()
end end
-- Returns a specific card from the bag, based on ArkhamDB ID -- Returns a specific card from the bag, based on ArkhamDB ID
---@param id string ID of the card to retrieve ---@param params table ID of the card to retrieve
---@return table: If the indexes are still being constructed, returns an empty table. ---@return table: If the indexes are still being constructed, returns an empty table.
-- Otherwise, a single table with the following fields -- Otherwise, a single table with the following fields
-- cardData: TTS object data, suitable for spawning the card -- data: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata -- metadata: Table of parsed metadata
function getCardById(id) function getCardById(params)
if not isIndexReady() then return {} end if not isIndexReady() then return {} end
return cardIdIndex[id] return cardIdIndex[params.id]
end end
-- Returns a list of cards from the bag matching a class and level (0 or upgraded) -- Returns a list of cards from the bag matching a class and level (0 or upgraded)
@ -239,8 +251,8 @@ end
-- isUpgraded: true for upgraded cards (Level 1-5), false for Level 0 -- isUpgraded: true for upgraded cards (Level 1-5), false for Level 0
---@return table: If the indexes are still being constructed, returns an empty table. ---@return table: If the indexes are still being constructed, returns an empty table.
-- Otherwise, a list of tables, each with the following fields -- Otherwise, a list of tables, each with the following fields
-- cardData: TTS object data, suitable for spawning the card -- data: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata -- metadata: Table of parsed metadata
function getCardsByClassAndLevel(params) function getCardsByClassAndLevel(params)
if not isIndexReady() then return {} end if not isIndexReady() then return {} end
@ -250,7 +262,7 @@ function getCardsByClassAndLevel(params)
else else
upgradeKey = "-level0" upgradeKey = "-level0"
end end
return classAndLevelIndex[params.class..upgradeKey] return classAndLevelIndex[params.class .. upgradeKey]
end end
-- Returns a list of cards from the bag matching a cycle -- Returns a list of cards from the bag matching a cycle
@ -259,8 +271,8 @@ end
-- sortByMetadata: true to sort the table by metadata instead of ID -- sortByMetadata: true to sort the table by metadata instead of ID
---@return table: If the indexes are still being constructed, returns an empty table. ---@return table: If the indexes are still being constructed, returns an empty table.
-- Otherwise, a list of tables, each with the following fields -- Otherwise, a list of tables, each with the following fields
-- cardData: TTS object data, suitable for spawning the card -- data: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata -- metadata: Table of parsed metadata
function getCardsByCycle(params) function getCardsByCycle(params)
if not isIndexReady() then return {} end if not isIndexReady() then return {} end

View File

@ -19,16 +19,15 @@ do
---@param id string ID of the card to retrieve ---@param id string ID of the card to retrieve
---@return table: If the indexes are still being constructed, returns an empty table. ---@return table: If the indexes are still being constructed, returns an empty table.
-- Otherwise, a single table with the following fields -- Otherwise, a single table with the following fields
-- cardData: TTS object data, suitable for spawning the card -- data: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata -- metadata: Table of parsed metadata
AllCardsBagApi.getCardById = function(id) AllCardsBagApi.getCardById = function(id)
return getAllCardsBag().call("getCardById", id) return getAllCardsBag().call("getCardById", { id = id })
end end
-- Gets a random basic weakness from the bag. Once a given ID has been returned -- Gets a random basic weakness from the bag. Once a given ID has been returned it
-- it will be removed from the list and cannot be selected again until a reload -- will be removed from the list and cannot be selected again until a reload occurs
-- occurs or the indexes are rebuilt, which will refresh the list to include all -- or the indexes are rebuilt, which will refresh the list to include all weaknesses.
-- weaknesses.
---@return string: ID of the selected weakness. ---@return string: ID of the selected weakness.
AllCardsBagApi.getRandomWeaknessId = function() AllCardsBagApi.getRandomWeaknessId = function()
return getAllCardsBag().call("getRandomWeaknessId") return getAllCardsBag().call("getRandomWeaknessId")
@ -64,8 +63,8 @@ do
---@param upgraded boolean True for upgraded cards (Level 1-5), false for Level 0 ---@param upgraded boolean True for upgraded cards (Level 1-5), false for Level 0
---@return table: If the indexes are still being constructed, returns an empty table. ---@return table: If the indexes are still being constructed, returns an empty table.
-- Otherwise, a list of tables, each with the following fields -- Otherwise, a list of tables, each with the following fields
-- cardData: TTS object data, suitable for spawning the card -- data: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata -- metadata: Table of parsed metadata
AllCardsBagApi.getCardsByClassAndLevel = function(class, upgraded) AllCardsBagApi.getCardsByClassAndLevel = function(class, upgraded)
return returnCopyOfList(getAllCardsBag().call("getCardsByClassAndLevel", { class = class, upgraded = upgraded })) return returnCopyOfList(getAllCardsBag().call("getCardsByClassAndLevel", { class = class, upgraded = upgraded }))
end end
@ -75,8 +74,8 @@ do
---@param sortByMetadata boolean If true, sorts the table by metadata instead of ID ---@param sortByMetadata boolean If true, sorts the table by metadata instead of ID
---@return table: If the indexes are still being constructed, returns an empty table. ---@return table: If the indexes are still being constructed, returns an empty table.
-- Otherwise, a list of tables, each with the following fields -- Otherwise, a list of tables, each with the following fields
-- cardData: TTS object data, suitable for spawning the card -- data: TTS object data, suitable for spawning the card
-- cardMetadata: Table of parsed metadata -- metadata: Table of parsed metadata
AllCardsBagApi.getCardsByCycle = function(cycle, sortByMetadata) AllCardsBagApi.getCardsByCycle = function(cycle, sortByMetadata)
return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", { cycle = cycle, sortByMetadata = sortByMetadata })) return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", { cycle = cycle, sortByMetadata = sortByMetadata }))
end end

View File

@ -333,6 +333,70 @@ function createInvestigatorModeButtons()
}) })
end end
function createXML(showOtherCardsButton)
-- basic XML for the help button
local xmlTable = {
{
tag = "Panel",
attributes = {
active = "false",
id = "helpPanel",
position = "-165 -70 -2",
rotation = "0 0 180",
height = "50",
width = "107",
color = "#00000099"
},
children = {
tag = "Text",
attributes = {
id = "helpText",
rectAlignment = "MiddleCenter",
height = "480",
width = "1000",
scale = "0.1 0.1 1",
fontSize = "66",
color = "#F5F5F5",
backgroundColor = "#FF0000",
alignment = "MiddleLeft",
horizontalOverflow = "wrap",
text = "• Select a group to place cards\n" ..
"• Copy the cards you want for your deck\n" ..
"• Select a new group to clear the placed cards and see new ones\n" ..
"• Clear to remove all cards"
}
}
}
}
-- add the "Additional Cards" button if cards without cycle were detected
if showOtherCardsButton then
local otherCardsButtonXml = {
tag = "Panel",
attributes = {
position = "44.25 65.75 -11",
rotation = "0 0 180",
height = "225",
width = "225",
scale = "0.1 0.1 1",
onClick = "spawnOtherCards"
},
children = {
tag = "Image",
attributes = { image = "OtherCards" }
}
}
table.insert(xmlTable, otherCardsButtonXml)
end
helpVisibleToPlayers = {}
self.UI.setXmlTable(xmlTable)
end
-- click function for the XML button for the additional player cards
function spawnOtherCards()
spawnCycle("Other")
end
function toggleHelp(_, playerColor, _) function toggleHelp(_, playerColor, _)
if helpVisibleToPlayers[playerColor] then if helpVisibleToPlayers[playerColor] then
helpVisibleToPlayers[playerColor] = nil helpVisibleToPlayers[playerColor] = nil
@ -612,11 +676,6 @@ function placeClassCards(cardClass, isUpgraded)
end end
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 -- 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 ---@param cycle string Name of a cycle, should match the standard used in card metadata
function spawnCycle(cycle) function spawnCycle(cycle)
@ -641,20 +700,6 @@ function spawnCycle(cycle)
}) })
end end
-- Comparison function used to sort the class card bag indexes. Sorts by card level, then name, then subname.
function cardComparator(id1, id2)
local card1 = cardIdIndex[id1]
local card2 = cardIdIndex[id2]
if card1.metadata.level ~= card2.metadata.level then
return card1.metadata.level < card2.metadata.level
elseif card1.data.Nickname ~= card2.data.Nickname then
return card1.data.Nickname < card2.data.Nickname
else
return card1.data.Description < card2.data.Description
end
end
function spawnBonded() function spawnBonded()
prepareToPlaceCards() prepareToPlaceCards()
spawnBag.spawn({ spawnBag.spawn({

View File

@ -16,7 +16,7 @@ Spawner = { }
---@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
@ -25,9 +25,9 @@ Spawner.spawnCards = function(cardList, pos, rot, sort, callback)
local investigatorCards = { } local investigatorCards = { }
for _, card in ipairs(cardList) do for _, card in ipairs(cardList) do
if (card.metadata.type == "Investigator") then if card.metadata.type == "Investigator" then
table.insert(investigatorCards, card) table.insert(investigatorCards, card)
elseif (card.metadata.type == "Minicard") then elseif card.metadata.type == "Minicard" then
table.insert(miniCards, card) table.insert(miniCards, card)
else else
table.insert(standardCards, card) table.insert(standardCards, card)
@ -46,7 +46,7 @@ Spawner.spawnCards = function(cardList, pos, rot, sort, callback)
end end
Spawner.spawnCardSpread = function(cardList, startPos, maxCols, rot, sort, callback) Spawner.spawnCardSpread = function(cardList, startPos, maxCols, rot, sort, callback)
if (sort) then if sort then
table.sort(cardList, Spawner.cardComparator) table.sort(cardList, Spawner.cardComparator)
end end
@ -201,7 +201,7 @@ end
---@return string id >= startId ---@return string id >= startId
Spawner.findNextAvailableId = function(objectTable, startId) Spawner.findNextAvailableId = function(objectTable, startId)
local id = startId local id = startId
while (objectTable[id] ~= nil) do while objectTable[id] ~= nil do
id = tostring(tonumber(id) + 1) id = tostring(tonumber(id) + 1)
end end
return id return id

View File

@ -85,12 +85,12 @@ do
local cardsToSpawn = {} local cardsToSpawn = {}
for _, cardId in ipairs(spawnSpec.cards) do for _, cardId in ipairs(spawnSpec.cards) do
local cardData = allCardsBagApi.getCardById(cardId) local card = allCardsBagApi.getCardById(cardId)
if cardData ~= nil then if card ~= nil then
table.insert(cardsToSpawn, cardData) table.insert(cardsToSpawn, card)
end end
end end
if (spawnSpec.spread) then if spawnSpec.spread then
Spawner.spawnCardSpread(cardsToSpawn, spawnSpec.globalPos, spawnSpec.spreadCols or 9999, spawnSpec.rotation, false, internal.recordPlacedObject) Spawner.spawnCardSpread(cardsToSpawn, spawnSpec.globalPos, spawnSpec.spreadCols or 9999, spawnSpec.rotation, false, internal.recordPlacedObject)
else else
-- TTS decks come out in reverse order of the cards, reverse the list so the input order stays -- TTS decks come out in reverse order of the cards, reverse the list so the input order stays

View File

@ -1,31 +0,0 @@
<Panel active="false"
id="helpPanel"
position="-165 -70 -2"
rotation="0 0 180"
height="50"
width="107"
color="#00000099">
<Text id="helpText"
rectAlignment="MiddleCenter"
height="480"
width="1000"
scale="0.1 0.1 1"
fontSize="66"
color="#F5F5F5"
backgroundColor="#FF0000"
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"
onClick="spawnOtherCards">
<Image image="OtherCards"/>
</Panel>