updated guid reference handler
This commit is contained in:
parent
8a9f83a5b5
commit
037bd6b21e
@ -24,5 +24,17 @@ do
|
|||||||
return getGuidHandler().call("getObjectsByOwner", owner)
|
return getGuidHandler().call("getObjectsByOwner", owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- sends new information to the reference handler to edit the main index
|
||||||
|
---@param owner String Parent of the object
|
||||||
|
---@param type String Type of the object
|
||||||
|
---@param guid String GUID of the object
|
||||||
|
GUIDReferenceApi.editIndex = function(owner, type, guid)
|
||||||
|
return getGuidHandler().call("editIndex", {
|
||||||
|
owner = owner,
|
||||||
|
type = type,
|
||||||
|
guid = guid
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return GUIDReferenceApi
|
return GUIDReferenceApi
|
||||||
end
|
end
|
||||||
|
@ -90,12 +90,43 @@ local GuidReferences = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local editsToIndex = {
|
||||||
|
White = {},
|
||||||
|
Orange = {},
|
||||||
|
Green = {},
|
||||||
|
Red = {},
|
||||||
|
Mythos = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- save function to keep edits to the index
|
||||||
|
function onSave() return JSON.encode({ editsToIndex = editsToIndex }) end
|
||||||
|
|
||||||
|
-- load function to restore edits to the index
|
||||||
|
function onLoad(savedData)
|
||||||
|
if savedData and savedData ~= "" then
|
||||||
|
local loadedData = JSON.decode(savedData)
|
||||||
|
editsToIndex = loadedData.editsToIndex
|
||||||
|
updateMainIndex()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- merges the main index and the edits
|
||||||
|
function updateMainIndex()
|
||||||
|
for owner, subTable in pairs(editsToIndex) do
|
||||||
|
for type, guid in pairs(subTable) do
|
||||||
|
GuidReferences[owner][type] = guid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- returns an object reference for the requested owner and type
|
||||||
function getObjectByOwnerAndType(params)
|
function getObjectByOwnerAndType(params)
|
||||||
local owner = params.owner or "Mythos"
|
local owner = params.owner or "Mythos"
|
||||||
local type = params.type
|
local type = params.type
|
||||||
return getObjectFromGUID(GuidReferences[owner][type])
|
return getObjectFromGUID(GuidReferences[owner][type])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns a list of objects for the requested type
|
||||||
function getObjectsByType(type)
|
function getObjectsByType(type)
|
||||||
local objList = {}
|
local objList = {}
|
||||||
for owner, objects in pairs(GuidReferences) do
|
for owner, objects in pairs(GuidReferences) do
|
||||||
@ -107,6 +138,7 @@ function getObjectsByType(type)
|
|||||||
return objList
|
return objList
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns a list of objects for the requested owner
|
||||||
function getObjectsByOwner(owner)
|
function getObjectsByOwner(owner)
|
||||||
local objList = {}
|
local objList = {}
|
||||||
for type, guid in pairs(GuidReferences[owner]) do
|
for type, guid in pairs(GuidReferences[owner]) do
|
||||||
@ -117,3 +149,9 @@ function getObjectsByOwner(owner)
|
|||||||
end
|
end
|
||||||
return objList
|
return objList
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- makes an edit to the main index
|
||||||
|
function editIndex(params)
|
||||||
|
editsToIndex[params.owner][params.type] = params.guid
|
||||||
|
updateMainIndex()
|
||||||
|
end
|
||||||
|
@ -1225,7 +1225,8 @@ function playermatRemovalSelected(player, selectedIndex, id)
|
|||||||
|
|
||||||
if mat then
|
if mat then
|
||||||
-- confirmation dialog about deletion
|
-- confirmation dialog about deletion
|
||||||
player.showConfirmDialog("Do you really want to remove " .. matColor .. "'s playermat? This can't be reversed.", function() removePlayermat(matColor) end)
|
player.pingTable(mat.getPosition())
|
||||||
|
player.showConfirmDialog("Do you really want to remove " .. matColor .. "'s playermat and related objects? This can't be reversed.", function() removePlayermat(matColor) end)
|
||||||
else
|
else
|
||||||
-- info dialog that it is already deleted
|
-- info dialog that it is already deleted
|
||||||
player.showInfoDialog(matColor .. "'s playermat has already been removed.")
|
player.showInfoDialog(matColor .. "'s playermat has already been removed.")
|
||||||
@ -1235,7 +1236,19 @@ end
|
|||||||
-- removes a playermat and all related objects from play
|
-- removes a playermat and all related objects from play
|
||||||
---@param matColor String Color of the playermat to remove
|
---@param matColor String Color of the playermat to remove
|
||||||
function removePlayermat(matColor)
|
function removePlayermat(matColor)
|
||||||
|
local matObjects = guidReferenceApi.getObjectsByOwner(matColor)
|
||||||
|
if not matObjects.Playermat then return end
|
||||||
|
|
||||||
|
-- remove action tokens
|
||||||
|
local actionTokens = playmatApi.searchAroundPlaymat(matColor, "isActionToken")
|
||||||
|
for _, obj in ipairs(actionTokens) do
|
||||||
|
obj.destruct()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- remove mat owned objects
|
||||||
|
for _, obj in pairs(matObjects) do
|
||||||
|
obj.destruct()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- sets the option panel to the correct state (corresponding to 'optionPanel')
|
-- sets the option panel to the correct state (corresponding to 'optionPanel')
|
||||||
@ -1312,18 +1325,22 @@ function applyOptionPanelChange(id, state)
|
|||||||
|
|
||||||
-- option: Show hand helper for each player
|
-- option: Show hand helper for each player
|
||||||
elseif id == "showHandHelper" then
|
elseif id == "showHandHelper" then
|
||||||
for i, color in ipairs(MAT_COLORS) do
|
local helperName = "Hand Helper"
|
||||||
local pos = playmatApi.transformLocalPosition({0.05, 0, -1.182}, color)
|
local spawnData = playmatApi.getHelperSpawnData("All", helperName)
|
||||||
local rot = playmatApi.returnRotation(color)
|
local i = 0
|
||||||
optionPanel[id][i] = spawnOrRemoveHelper(state, "Hand Helper", pos, rot)
|
for color, data in pairs(spawnData) do
|
||||||
|
i = i + 1
|
||||||
|
optionPanel[id][i] = spawnOrRemoveHelper(state, helperName, data.position, data.rotation, color)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- option: Show search assistant for each player
|
-- option: Show search assistant for each player
|
||||||
elseif id == "showSearchAssistant" then
|
elseif id == "showSearchAssistant" then
|
||||||
for i, color in ipairs(MAT_COLORS) do
|
local helperName = "Search Assistant"
|
||||||
local pos = playmatApi.transformLocalPosition({-0.3, 0, -1.182}, color)
|
local spawnData = playmatApi.getHelperSpawnData("All", helperName)
|
||||||
local rot = playmatApi.returnRotation(color)
|
local i = 0
|
||||||
optionPanel[id][i] = spawnOrRemoveHelper(state, "Search Assistant", pos, rot)
|
for color, data in pairs(spawnData) do
|
||||||
|
i = i + 1
|
||||||
|
optionPanel[id][i] = spawnOrRemoveHelper(state, helperName, data.position, data.rotation, color)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- option: Show attachment helper
|
-- option: Show attachment helper
|
||||||
@ -1345,13 +1362,17 @@ end
|
|||||||
---@param name String Name of the helper object
|
---@param name String Name of the helper object
|
||||||
---@param position Vector Position of the object (where it will spawn)
|
---@param position Vector Position of the object (where it will spawn)
|
||||||
---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0})
|
---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0})
|
||||||
|
---@param owner String Owner of the object (defaults to "Mythos")
|
||||||
---@return. GUID of the spawnedObj (or nil if object was removed)
|
---@return. GUID of the spawnedObj (or nil if object was removed)
|
||||||
function spawnOrRemoveHelper(state, name, position, rotation)
|
function spawnOrRemoveHelper(state, name, position, rotation, owner)
|
||||||
if (type(state) == "table" and #state == 0) then
|
if (type(state) == "table" and #state == 0) then
|
||||||
return removeHelperObject(name)
|
return removeHelperObject(name)
|
||||||
elseif state then
|
elseif state then
|
||||||
Player.getPlayers()[1].pingTable(position)
|
Player.getPlayers()[1].pingTable(position)
|
||||||
return spawnHelperObject(name, position, rotation).getGUID()
|
local spawnedGUID = spawnHelperObject(name, position, rotation).getGUID()
|
||||||
|
local cleanName = name:gsub("%s+", "")
|
||||||
|
guidReferenceApi.editIndex(owner or "Mythos", cleanName, spawnedGUID)
|
||||||
|
return spawnedGUID
|
||||||
else
|
else
|
||||||
return removeHelperObject(name)
|
return removeHelperObject(name)
|
||||||
end
|
end
|
||||||
|
@ -96,6 +96,26 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns a table with spawn data (position and rotation) for a helper object
|
||||||
|
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
|
||||||
|
---@param helperName String Name of the helper object
|
||||||
|
PlaymatApi.getHelperSpawnData = function(matColor, helperName)
|
||||||
|
local resultTable = {}
|
||||||
|
local localPositionTable = {
|
||||||
|
["Hand Helper"] = {0.05, 0, -1.182},
|
||||||
|
["Search Assistant"] = {-0.3, 0, -1.182}
|
||||||
|
}
|
||||||
|
|
||||||
|
for color, mat in pairs(getMatForColor(matColor)) do
|
||||||
|
resultTable[color] = {
|
||||||
|
position = mat.positionToWorld(localPositionTable[helperName]),
|
||||||
|
rotation = mat.getRotation()
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return resultTable
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Triggers the Upkeep for the requested playmat
|
-- Triggers the Upkeep for the requested playmat
|
||||||
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
|
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
|
||||||
---@param playerColor String Color of the calling player (for messages)
|
---@param playerColor String Color of the calling player (for messages)
|
||||||
|
Loading…
Reference in New Issue
Block a user