added documentation

This commit is contained in:
Chr1Z93 2024-08-03 22:07:59 +02:00
parent 513749427b
commit 5eb6873c45
3 changed files with 25 additions and 8 deletions

View File

@ -1164,6 +1164,7 @@ function onClick_toggleUi(player, windowId)
changeWindowVisibilityForColor(player.color, windowId) changeWindowVisibilityForColor(player.color, windowId)
end end
-- wrapper for the real function to unpack arguments
function changeWindowVisibilityForColorWrapper(params) function changeWindowVisibilityForColorWrapper(params)
changeWindowVisibilityForColor(params.color, params.windowId, params.overrideState, params.owner) changeWindowVisibilityForColor(params.color, params.windowId, params.overrideState, params.owner)
end end

View File

@ -1,6 +1,10 @@
do do
local GlobalApi = {} local GlobalApi = {}
-- downloads an object from the library and optionally replaces an existing object
---@param url string Path to JSON file (without .json extension) in the library
---@param player tts__Player Player that initiated this
---@param replace string GUID of the object to replace
function GlobalApi.placeholderDownload(url, player, replace) function GlobalApi.placeholderDownload(url, player, replace)
Global.call("placeholder_download", { Global.call("placeholder_download", {
url = url, url = url,
@ -9,29 +13,41 @@ do
}) })
end end
-- splashes the scenario title (used when placing a scenario) and plays a sound
---@param scenarioName string Name of the scenario
function GlobalApi.titleSplash(scenarioName) function GlobalApi.titleSplash(scenarioName)
Global.call("titleSplash", scenarioName) Global.call("titleSplash", scenarioName)
end end
function GlobalApi.changeWindowVisibility(playerColor, windowId, owner) -- toggles the visibility of the specific window for the specified color
---@param playerColor string Player color to toggle the visibility for
---@param windowId string ID of the XML element
---@param overrideState? boolean Forcefully sets the new visibility
---@param owner? tts__Object Object that owns the XML (or nil if Global)
---@return boolean visible Returns the new state of the visibility
function GlobalApi.changeWindowVisibility(playerColor, windowId, overrideState, owner)
Global.call("changeWindowVisibilityForColorWrapper", { Global.call("changeWindowVisibilityForColorWrapper", {
color = playerColor, color = playerColor,
windowId = windowId, windowId = windowId,
overrideState = overrideState,
owner = owner owner = owner
}) })
end end
function GlobalApi.updateGlobalXml(globalXml) -- this helper function updates the global XML while preserving the visibility of windows
Global.call("updateGlobalXml", globalXml) ---@param newXml table Complete new XmlTable for the Global UI
function GlobalApi.updateGlobalXml(newXml)
Global.call("updateGlobalXml", newXml)
end end
-- loads saved options -- loads saved options
---@param options table Set a new state for the option table ---@param options table Set a new state for the option table
function GlobalApi.loadOptionPanelSettings(options) function GlobalApi.loadOptionPanelSettings(options)
return Global.call("loadSettings", options) Global.call("loadSettings", options)
end end
---@return any: Table of option panel state -- gets the current state of the option panel
---@return table: option panel state
function GlobalApi.getOptionPanelState() function GlobalApi.getOptionPanelState()
return Global.getTable("optionPanel") return Global.getTable("optionPanel")
end end

View File

@ -917,7 +917,7 @@ function createXML()
end end
function onClick_hideOrShowOptions(player) function onClick_hideOrShowOptions(player)
GlobalApi.changeWindowVisibility(player.color, "optionPanelMain", self) GlobalApi.changeWindowVisibility(player.color, "optionPanelMain", _, self)
end end
function onClick_textureSelect(player) function onClick_textureSelect(player)
@ -947,8 +947,8 @@ function onClick_handColorSelect(player)
handZone.setValue(newColor) handZone.setValue(newColor)
-- update visibility for old and new color -- update visibility for old and new color
GlobalApi.changeWindowVisibility(playerColor, "optionPanelMain", self) GlobalApi.changeWindowVisibility(playerColor, "optionPanelMain", _, self)
GlobalApi.changeWindowVisibility(newColor, "optionPanelMain", self) GlobalApi.changeWindowVisibility(newColor, "optionPanelMain", _, self)
navigationOverlayApi.copyVisibility(playerColor, newColor) navigationOverlayApi.copyVisibility(playerColor, newColor)
-- if there was a seated player, reseat to the new color -- if there was a seated player, reseat to the new color