Merge branch 'main' into token-stack

This commit is contained in:
Chr1Z 2024-07-08 01:10:13 +02:00 committed by GitHub
commit 6fa0baac86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 277 additions and 110 deletions

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "",
"LuaScript": "require(\"playercards/cards/Analysis\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Card",

View File

@ -58,5 +58,5 @@
"scaleZ": 1
},
"Value": 0,
"XmlUI": ""
"XmlUI": "\u003cInclude src=\"playercards/FamilyInheritance.xml\"/\u003e"
}

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "",
"LuaScript": "require(\"playercards/cards/Strong-Armed\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Card",

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "",
"LuaScript": "require(\"playercards/cards/ThirdTimesaCharm\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Card",

View File

@ -1 +1 @@
{"acknowledgedUpgradeVersions":[],"chaosTokensGUID":[],"optionPanel":{"cardLanguage":"en","changePlayAreaImage":false,"enableCardHelpers":false,"playAreaConnectionColor":{"a":1,"b":0.4,"g":0.4,"r":0.4},"playAreaConnections":true,"playAreaSnapTags":true,"showAttachmentHelper":false,"showCleanUpHelper":false,"showCYOA":false,"showDisplacementTool":false,"showDrawButton":false,"showHandHelper":false,"showSearchAssistant":false,"showTitleSplash":true,"useClassTexture":true,"useClueClickers":false,"useResourceCounters":"disabled","useSnapTags":true}}
{"acknowledgedUpgradeVersions":[],"chaosTokensGUID":[],"optionPanel":{"cardLanguage":"en","changePlayAreaImage":false,"enableCardHelpers":true,"playAreaConnectionColor":{"a":1,"b":0.4,"g":0.4,"r":0.4},"playAreaConnections":true,"playAreaSnapTags":true,"showAttachmentHelper":false,"showCleanUpHelper":false,"showCYOA":false,"showDisplacementTool":false,"showDrawButton":false,"showHandHelper":false,"showSearchAssistant":false,"showTitleSplash":true,"useClassTexture":true,"useClueClickers":false,"useResourceCounters":"disabled","useSnapTags":true}}

View File

@ -4,6 +4,7 @@ local searchLib = require("util/SearchLib")
-- forward declaration of variables that are used across functions
local matColor, handColor, setAsidePosition, setAsideRotation, drawDeckPosition, topCardDetected
local addedVectorLines, addedSnapPoint
local quickParameters = {}
quickParameters.function_owner = self
@ -34,6 +35,7 @@ inputParameters.validation = 2
function onLoad()
normalView()
self.max_typed_number = 9999
end
-- regular view with search box
@ -89,6 +91,10 @@ function updateSearchNumber(_, _, input)
inputParameters.value = tonumber(input)
end
function onNumberTyped(playerColor, number)
startSearch(playerColor, number)
end
-- starts the search with the number from the input field
function searchCustom(_, messageColor)
local number = inputParameters.value
@ -115,7 +121,7 @@ function startSearch(messageColor, number)
-- get bounds to know the height of the deck
local bounds = deckAreaObjects.draw.getBounds()
drawDeckPosition = bounds.center + Vector(0, bounds.size.y / 2 + 0.2, 0)
printToColor("Place target(s) of search on set aside hand.", messageColor, "Green")
printToColor("Place target(s) of search on set aside spot.", messageColor, "Green")
-- get playermat orientation
local offset = -15
@ -127,10 +133,28 @@ function startSearch(messageColor, number)
local handData = Player[handColor].getHandTransform()
local handCards = Player[handColor].getHandObjects()
setAsidePosition = (handData.position + offset * handData.right):setAt("y", 1.5)
setAsideRotation = { handData.rotation.x, handData.rotation.y + 180, 180 }
setAsideRotation = Vector(handData.rotation.x, handData.rotation.y + 180, 180)
-- place hand cards set aside
if #handCards > 0 then
deckLib.placeOrMergeIntoDeck(handCards, setAsidePosition, setAsideRotation)
end
-- add a temporary snap point for the set aside spot
addedSnapPoint = { position = setAsidePosition, rotation = setAsideRotation }
local snapPoints = Global.getSnapPoints() or {}
table.insert(snapPoints, addedSnapPoint)
Global.setSnapPoints(snapPoints)
-- add a temporary box for the set aside spot
local vectorLines = Global.getVectorLines() or {}
local boxSize = Vector(2.5, 0, 3.5)
addedVectorLines = generateBoxData(setAsidePosition, boxSize, setAsideRotation.y, handColor)
for _, line in ipairs(addedVectorLines) do
table.insert(vectorLines, line)
end
Global.setVectorLines(vectorLines)
-- handling for Norman Withers
if deckAreaObjects.topCard then
@ -182,4 +206,77 @@ function drawSetAsideCards()
end
obj.deal(count, handColor)
end
removeAddedSnapAndLines()
end
function removeAddedSnapAndLines()
local vectorLines = Global.getVectorLines() or {}
local snapPoints = Global.getSnapPoints() or {}
-- look for previously added data and remove it (iterate in reverse because we're removing entries)
for i = #vectorLines, 1, -1 do
for _, boxLine in ipairs(addedVectorLines) do
if vectorLines[i].points[1] == boxLine.points[1] and vectorLines[i].points[2] == boxLine.points[2] then
table.remove(vectorLines, i)
break
end
end
end
for i = #snapPoints, 1, -1 do
if snapPoints[i].position == addedSnapPoint.position then
table.remove(snapPoints, i)
break
end
end
Global.setVectorLines(vectorLines)
Global.setSnapPoints(snapPoints)
end
-- generates the lines data for a rectangular box
---@param center tts__Vector Center of the box
---@param size tts__Vector X and Z dimension of the box
---@param rotation number Rotation around the Y-axis for the box
---@param boxColor string Color for the box
---@return table lines Vector line data for the box
function generateBoxData(center, size, rotation, boxColor)
local halfWidth = size.x / 2
local halfDepth = size.z / 2
-- corners of the box in local coordinates
local corners = {
Vector(-halfWidth, 0, -halfDepth),
Vector(halfWidth, 0, -halfDepth),
Vector(halfWidth, 0, halfDepth),
Vector(-halfWidth, 0, halfDepth)
}
-- translate corners to global coordinates
for i, cornerVec in ipairs(corners) do
local rotatedCornerVec = cornerVec:rotateOver('y', rotation)
corners[i] = rotatedCornerVec + center
end
-- generate the lines data
local lines = {
{
points = { corners[1], corners[2] },
color = boxColor
},
{
points = { corners[2], corners[3] },
color = boxColor
},
{
points = { corners[3], corners[4] },
color = boxColor
},
{
points = { corners[4], corners[1] },
color = boxColor
}
}
return lines
end

View File

@ -4,7 +4,7 @@ do
-- respawns the chaos bag with a new state of tokens
---@param tokenList table List of chaos token ids
ChaosBagApi.setChaosBagState = function(tokenList)
return Global.call("setChaosBagState", tokenList)
Global.call("setChaosBagState", tokenList)
end
-- returns a Table List of chaos token ids in the current chaos bag
@ -31,31 +31,31 @@ do
-- returns all sealed tokens on cards to the chaos bag
---@param playerColor string Color of the player to show the broadcast to
ChaosBagApi.releaseAllSealedTokens = function(playerColor)
return Global.call("releaseAllSealedTokens", playerColor)
Global.call("releaseAllSealedTokens", playerColor)
end
-- returns all drawn tokens to the chaos bag
ChaosBagApi.returnChaosTokens = function()
return Global.call("returnChaosTokens")
Global.call("returnChaosTokens")
end
-- removes the specified chaos token from the chaos bag
---@param id string ID of the chaos token
ChaosBagApi.removeChaosToken = function(id)
return Global.call("removeChaosToken", id)
Global.call("removeChaosToken", id)
end
-- returns a chaos token to the bag and calls all relevant functions
---@param token tts__Object Chaos token to return
---@param fromBag boolean whether or not the token to return was in the middle of being drawn (true) or elsewhere (false)
ChaosBagApi.returnChaosTokenToBag = function(token, fromBag)
return Global.call("returnChaosTokenToBag", { token = token, fromBag = fromBag })
Global.call("returnChaosTokenToBag", { token = token, fromBag = fromBag })
end
-- spawns the specified chaos token and puts it into the chaos bag
---@param id string ID of the chaos token
ChaosBagApi.spawnChaosToken = function(id)
return Global.call("spawnChaosToken", id)
Global.call("spawnChaosToken", id)
end
-- Checks to see if the chaos bag can be manipulated. If a player is searching the bag when tokens

View File

@ -452,6 +452,9 @@ function returnAndRedraw(_, tokenGUID)
end
redrawData = {}
-- return a reference to the freshly drawn token
return chaosTokens[indexOfReturnedToken]
end
-- Checks to see if the chaos bag can be manipulated. If a player is searching the bag when tokens
@ -1735,7 +1738,7 @@ function onClick_defaultSettings()
optionPanel = {
cardLanguage = "en",
changePlayAreaImage = false,
enableCardHelpers = false,
enableCardHelpers = true,
playAreaConnectionColor = { a = 1, b = 0.4, g = 0.4, r = 0.4 },
playAreaConnections = true,
playAreaSnapTags = true,

View File

@ -51,20 +51,21 @@ As a nice reminder the XML button takes on the Frost color and icon with the tex
> require...
----------------------------------------------------------]]
local isHelperEnabled = false
-- intentionally global
hasXML = true
isHelperEnabled = false
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
end
createHelperXML()
checkOptionPanel()
syncDisplayWithOptionPanel()
end
function createHelperXML()
@ -95,14 +96,6 @@ function createHelperXML()
self.UI.setXmlTable(xmlTable)
end
function shutOff()
self.UI.hide("Helper")
end
function initialize()
self.UI.show("Helper")
end
function triggerXMLTokenLabelCreation()
Global.call("activeRedrawEffect", {
VALID_TOKENS = VALID_TOKENS,

View File

@ -1,7 +1,23 @@
--[[ Library for cards that have helpers
This file is used to share code between cards with helpers.
It syncs the visibility of the helper with the option panel and
makes sure the card has the respective tag.
Additionally, it will call 'initiliaze()' and 'shutOff()'
in the parent file if they are present.
Instructions:
1) Define the global variables before requiring this file:
hasXML = true (whether the card has an XML display)
isHelperEnabled = false (default state of the helper, should be 'false')
2) In 'onLoad()'', call 'syncDisplayWithOptionPanel()'
----------------------------------------------------------]]
local optionPanelApi = require("core/OptionPanelApi")
-- if the respective option is enabled in onLoad(), enable the helper
function checkOptionPanel()
function syncDisplayWithOptionPanel()
self.addTag("CardWithHelper")
local options = optionPanelApi.getOptions()
if options.enableCardHelpers then
setHelperState(true)
@ -33,10 +49,12 @@ function actualDisplayUpdate()
if isHelperEnabled then
self.clearContextMenu()
self.addContextMenuItem("Disable Helper", toggleHelper)
if hasXML then self.UI.show("Helper") end
if initialize then initialize() end
else
self.clearContextMenu()
self.addContextMenuItem("Enable Helper", toggleHelper)
if hasXML then self.UI.hide("Helper") end
if shutOff then shutOff() end
end
end

View File

@ -0,0 +1,2 @@
require("playercards/CardsWithHelper")
require("playercards/CardsThatRedrawTokens")

View File

@ -4,35 +4,37 @@ local chaosBagApi = require("chaosbag/ChaosBagApi")
local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi")
local isHelperEnabled = false
local updated
-- intentionally global
hasXML = true
isHelperEnabled = false
local updated, loopId
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end
checkOptionPanel()
syncDisplayWithOptionPanel()
end
-- hide buttons and stop monitoring
function shutOff()
self.UI.hide("Helper")
Wait.stopAll()
updateSave()
if loopId then
Wait.stop(loopId)
loopId = nil
end
end
-- show buttons and begin monitoring chaos bag for curse and bless tokens
function initialize()
self.UI.show("Helper")
maybeUpdateButtonState()
Wait.time(maybeUpdateButtonState, 1, -1)
updateSave()
loopId = Wait.time(maybeUpdateButtonState, 1, -1)
end
function resolveToken(player, _, tokenType)

View File

@ -1,6 +1,10 @@
require("playercards/CardsWithHelper")
local playermatApi = require("playermat/PlayermatApi")
-- intentionally global
hasXML = false
isHelperEnabled = false
-- common button parameters
local buttonParameters = {}
buttonParameters.function_owner = self
@ -28,7 +32,6 @@ local customizableList = {
-- index of the currently selected button (0-indexed from the top)
local activeButtonIndex = -1
local isHelperEnabled = false
local hypothesisList = {}
function updateSave()
@ -39,17 +42,17 @@ function updateSave()
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
activeButtonIndex = loadedData.activeButtonIndex
end
checkOptionPanel()
if activeButtonIndex > 0 then
selectButton(activeButtonIndex)
end
syncDisplayWithOptionPanel()
end
function initialize()
@ -74,7 +77,7 @@ function selectButton(index)
end
end
-- Create buttons based on the button parameters
-- create buttons based on the button parameters
function createButtons()
self.clearButtons()
@ -88,7 +91,6 @@ function createButtons()
local upgradeSheet = findUpgradeSheet()
if upgradeSheet then
for i = 1, 4 do
log(4)
if upgradeSheet.call("isUpgradeActive", i) then
table.insert(hypothesisList, customizableList[i])
end

View File

@ -1,26 +1,24 @@
require("playercards/CardsWithHelper")
local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
local tokenManager = require("core/token/TokenManager")
-- intentionally global
hasXML = true
isHelperEnabled = false
local clickableResourceCounter = nil
local foundTokens = 0
function onLoad()
self.addContextMenuItem("Add 4 resources",
function(playerColor)
Player[playerColor].clearSelectedObjects()
add4(playerColor)
end)
self.addContextMenuItem("Take all resources",
function(playerColor)
Player[playerColor].clearSelectedObjects()
takeAll(playerColor)
end)
self.addContextMenuItem("Discard all resources",
function(playerColor)
Player[playerColor].clearSelectedObjects()
loseAll(playerColor)
end)
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
end
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
end
syncDisplayWithOptionPanel()
end
function searchSelf()
@ -40,7 +38,7 @@ function searchSelf()
end
end
function add4(playerColor)
function add4()
searchSelf()
local newCount = foundTokens + 4
@ -51,7 +49,7 @@ function add4(playerColor)
end
end
function takeAll(playerColor)
function takeAll(player)
searchSelf()
local matColor = playermatApi.getMatColorByPosition(self.getPosition())
playermatApi.updateCounter(matColor, "ResourceCounter", _, foundTokens)
@ -59,14 +57,13 @@ function takeAll(playerColor)
if clickableResourceCounter then
clickableResourceCounter.call("updateVal", 0)
end
printToColor("Moved " .. foundTokens .. " resource(s) to " .. matColor .. "'s resource pool.", playerColor)
printToColor("Moved " .. foundTokens .. " resource(s) to " .. matColor .. "'s resource pool.", player.color)
end
function loseAll(playerColor)
function loseAll(player)
searchSelf()
if clickableResourceCounter then
clickableResourceCounter.call("updateVal", 0)
end
printToColor("Discarded " .. foundTokens .. " resource(s).", playerColor)
printToColor("Discarded " .. foundTokens .. " resource(s).", player.color)
end

View File

@ -5,8 +5,10 @@ local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
local tokenManager = require("core/token/TokenManager")
local isHelperEnabled = false
local updated
-- intentionally global
hasXML = true
isHelperEnabled = false
local updated, loopId
local xmlData = {
Action = { color = "#6D202CE6", onClick = "removeAndExtraAction" },
@ -16,31 +18,31 @@ local xmlData = {
}
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end
checkOptionPanel()
syncDisplayWithOptionPanel()
end
-- hide buttons and stop monitoring
function shutOff()
self.UI.hide("Helper")
Wait.stopAll()
updateSave()
end
-- show buttons and begin monitoring chaos bag for curse and bless tokens
function initialize()
self.UI.show("Helper")
maybeUpdateButtonState()
Wait.time(maybeUpdateButtonState, 1, -1)
updateSave()
loopId = Wait.time(maybeUpdateButtonState, 1, -1)
end
function shutOff()
if loopId then
Wait.stop(loopId)
loopId = nil
end
end
function addTokenToBag(_, _, tokenType)

View File

@ -0,0 +1,2 @@
require("playercards/CardsWithHelper")
require("playercards/CardsThatRedrawTokens")

View File

@ -0,0 +1,2 @@
require("playercards/CardsWithHelper")
require("playercards/CardsThatRedrawTokens")

View File

@ -1,6 +1,12 @@
require("playercards/CardsWithHelper")
local playermatApi = require("playermat/PlayermatApi")
-- intentionally global
hasXML = false
isHelperEnabled = false
local modValue, loopId
local buttonParameters = {
click_function = "shutOff",
function_owner = self,
@ -10,13 +16,20 @@ local buttonParameters = {
height = 175
}
local modValue
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end
-- use metadata to detect level and adjust modValue accordingly
if JSON.decode(self.getGMNotes()).level == 0 then
modValue = 5
@ -24,25 +37,22 @@ function onLoad(savedData)
modValue = 4
end
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
end
checkOptionPanel()
updateDisplay()
syncDisplayWithOptionPanel()
end
function initialize()
self.clearButtons()
self.createButton(buttonParameters)
updateButton()
Wait.time(updateButton, 2, -1)
loopId = Wait.time(updateButton, 2, -1)
end
function shutOff()
self.clearButtons()
Wait.stopAll()
if loopId then
Wait.stop(loopId)
loopId = nil
end
end
function updateButton()

View File

@ -63,12 +63,12 @@ local buttonParameters = {
-- table of texture URLs
local nameToTexture = {
Guardian = "http://cloud-3.steamusercontent.com/ugc/2501268517203536128/853B9CD08FC14A8B2A08C73D8ED77E0FE235CCCB/",
Mystic = "http://cloud-3.steamusercontent.com/ugc/2501268517203536470/11C99488B9CA9236059A5F02E4A852A7C77B42A6/",
Guardian = "http://cloud-3.steamusercontent.com/ugc/2501268517241599869/179119CA88170D9F5C87CD00D267E6F9F397D2F7/",
Mystic = "http://cloud-3.steamusercontent.com/ugc/2501268517241600113/F6473F92B3435C32A685BB4DC2A88C2504DDAC4F/",
Neutral = "http://cloud-3.steamusercontent.com/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/",
Rogue = "http://cloud-3.steamusercontent.com/ugc/2501268517203536767/587791B327255DB8F953B27BB9E4DE602FA32B64/",
Seeker = "http://cloud-3.steamusercontent.com/ugc/2501268517203537098/EFD9FC4CCDB105EFFDFF7A57C915CD984865760D/",
Survivor = "http://cloud-3.steamusercontent.com/ugc/2501268517203537426/14EF780606D9A449F31A007226CB48D05AA820FF/"
Rogue = "http://cloud-3.steamusercontent.com/ugc/2501268517241600395/00CFAFC13D7B6EACC147D22A40AF9FBBFFAF3136/",
Seeker = "http://cloud-3.steamusercontent.com/ugc/2501268517241600579/92DEB412D8D3A9C26D1795CEA0335480409C3E4B/",
Survivor = "http://cloud-3.steamusercontent.com/ugc/2501268517241600848/CEB685E9C8A4A3C18A4B677A519B49423B54E886/"
}
-- translation table for slot names to characters for special font

View File

@ -0,0 +1,37 @@
<Defaults>
<Button padding="30 30 30 30"
font="font_teutonic-arkham"
textColor="white"
fontSize="235"
shadow="#405041B3"
shadowDistance="-15 15"/>
<TableLayout position="130 0 -22"
rotation="0 0 270"
height="460"
width="2600"
scale="0.1 0.1 1"
cellSpacing="80"
cellBackgroundColor="rgba(1,1,1,0)"/>
</Defaults>
<TableLayout id="Helper"
active="false">
<Row>
<Cell>
<Button onClick="loseAll"
color="#6D202C"
fontSize="195"
text="Discard all"/>
</Cell>
<Cell>
<Button onClick="takeAll"
color="#173B0B"
text="Move all"/>
</Cell>
<Cell>
<Button onClick="add4"
color="#77674D"
text="Place 4"/>
</Cell>
</Row>
</TableLayout>