bugfixing and formatting

This commit is contained in:
Chr1Z93 2024-06-26 13:59:20 +02:00
parent b668146ba4
commit 6988ce170b
10 changed files with 647 additions and 596 deletions

View File

@ -37,7 +37,7 @@
{ {
"Name": "Playermat-Seeker-Cache", "Name": "Playermat-Seeker-Cache",
"Type": 0, "Type": 0,
"URL": "http://cloud-3.steamusercontent.com/ugc/2444972799638880905/CFC02BF5A6140B9B4B92312AD6DC74D8DD61180B/" "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/"
}, },
{ {
"Name": "Playermat-Survivor-Cache", "Name": "Playermat-Survivor-Cache",

View File

@ -1,188 +1,172 @@
tableHeightOffset =-9 tableHeightOffset = -9
function onSave() function onSave()
saved_data = JSON.encode({tid=tableImageData, cd=checkData}) return JSON.encode({ tid = tableImageData, cd = checkData })
--saved_data = ""
return saved_data
end end
function onload(saved_data) function onload(saved_data)
--Loads the tracking for if the game has started yet if saved_data ~= "" then
if saved_data ~= "" then local loaded_data = JSON.decode(saved_data)
local loaded_data = JSON.decode(saved_data) tableImageData = loaded_data.tid
tableImageData = loaded_data.tid checkData = loaded_data.cd
checkData = loaded_data.cd else
else tableImageData = {}
tableImageData = {} checkData = { move = false, scale = false }
checkData = {move=false, scale=false} end
end
--Disables interactable status of objects with GUID in list --Disables interactable status of objects with GUID in list
for _, guid in ipairs(ref_noninteractable) do for _, guid in ipairs(ref_noninteractable) do
local obj = getObjectFromGUID(guid) local obj = getObjectFromGUID(guid)
if obj then obj.interactable = false end if obj then obj.interactable = false end
end end
--Establish references to table parts --Establish references to table parts
obj_leg1 = getObjectFromGUID("afc863") obj_leg1 = getObjectFromGUID("afc863")
obj_leg2 = getObjectFromGUID("c8edca") obj_leg2 = getObjectFromGUID("c8edca")
obj_leg3 = getObjectFromGUID("393bf7") obj_leg3 = getObjectFromGUID("393bf7")
obj_leg4 = getObjectFromGUID("12c65e") obj_leg4 = getObjectFromGUID("12c65e")
obj_surface = getObjectFromGUID("4ee1f2") obj_surface = getObjectFromGUID("4ee1f2")
obj_side_top = getObjectFromGUID("35b95f") obj_side_top = getObjectFromGUID("35b95f")
obj_side_bot = getObjectFromGUID("f938a2") obj_side_bot = getObjectFromGUID("f938a2")
obj_side_lef = getObjectFromGUID("9f95fd") obj_side_lef = getObjectFromGUID("9f95fd")
obj_side_rig = getObjectFromGUID("5af8f2") obj_side_rig = getObjectFromGUID("5af8f2")
controlActive = true controlActive = true
createOpenCloseButton() createOpenCloseButton()
end end
--Activation/deactivation of control panel --Activation/deactivation of control panel
--Activated by clicking on --Activated by clicking on
function click_toggleControl(_, color) function click_toggleControl(_, color)
if permissionCheck(color) then if permissionCheck(color) then
if not controlActive then if not controlActive then
--Activate control panel --Activate control panel
controlActive = true controlActive = true
self.clearButtons() self.clearButtons()
createOpenCloseButton() createOpenCloseButton()
createSurfaceInput() createSurfaceInput()
createSurfaceButtons() createSurfaceButtons()
createScaleInput() createScaleInput()
createScaleButtons() createScaleButtons()
else else
--Deactivate control panel --Deactivate control panel
controlActive = false controlActive = false
self.clearButtons() self.clearButtons()
self.clearInputs() self.clearInputs()
createOpenCloseButton() createOpenCloseButton()
end
end end
end
end end
--Table surface control --Table surface control
--Changes table surface --Changes table surface
function click_applySurface(_, color) function click_applySurface(_, color)
if permissionCheck(color) then if permissionCheck(color) then
updateSurface() updateSurface()
broadcastToAll("New Table Image Applied", {0.2,0.9,0.2}) broadcastToAll("New Table Image Applied", { 0.2, 0.9, 0.2 })
end end
end end
--Saves table surface --Saves table surface
function click_saveSurface(_, color) function click_saveSurface(_, color)
if permissionCheck(color) then if permissionCheck(color) then
local nickname = self.getInputs()[1].value local nickname = self.getInputs()[1].value
local url = self.getInputs()[2].value local url = self.getInputs()[2].value
if nickname == "" then if nickname == "" then
--No nickname --No nickname
broadcastToAll("Please supply a nickname for this save.", {0.9,0.2,0.2}) broadcastToAll("Please supply a nickname for this save.", { 0.9, 0.2, 0.2 })
else else
--Nickname exists --Nickname exists
if findInImageDataIndex(url, nickname) == nil then if findInImageDataIndex(url, nickname) == nil then
--Save doesn't exist already --Save doesn't exist already
table.insert(tableImageData, {url=url, name=nickname}) table.insert(tableImageData, { url = url, name = nickname })
broadcastToAll("Image URL saved to memory.", {0.2,0.9,0.2}) broadcastToAll("Image URL saved to memory.", { 0.2, 0.9, 0.2 })
--Refresh buttons --Refresh buttons
self.clearButtons()
createOpenCloseButton()
createSurfaceButtons()
createScaleButtons()
else
--Save exists already
broadcastToAll("Memory already contains a save with this Name or URL. Delete it first.", {0.9,0.2,0.2})
end
end
end
end
--Loads table surface
function click_loadMemory(_, color, index)
if permissionCheck(color) then
self.editInput({index=0, value=tableImageData[index].name})
self.editInput({index=1, value=tableImageData[index].url})
updateSurface()
broadcastToAll("Table Image Loaded", {0.2,0.9,0.2})
end
end
--Deletes table surface
function click_deleteMemory(_, color, index)
if permissionCheck(color) then
table.remove(tableImageData, index)
self.clearButtons() self.clearButtons()
createOpenCloseButton() createOpenCloseButton()
createSurfaceButtons() createSurfaceButtons()
createScaleButtons() createScaleButtons()
broadcastToAll("Element Removed from Memory", {0.2,0.9,0.2}) else
--Save exists already
broadcastToAll("Memory already contains a save with this Name or URL. Delete it first.", { 0.9, 0.2, 0.2 })
end
end end
end
end
--Loads table surface
function click_loadMemory(_, color, index)
if permissionCheck(color) then
self.editInput({ index = 0, value = tableImageData[index].name })
self.editInput({ index = 1, value = tableImageData[index].url })
updateSurface()
broadcastToAll("Table Image Loaded", { 0.2, 0.9, 0.2 })
end
end
--Deletes table surface
function click_deleteMemory(_, color, index)
if permissionCheck(color) then
table.remove(tableImageData, index)
self.clearButtons()
createOpenCloseButton()
createSurfaceButtons()
createScaleButtons()
broadcastToAll("Element Removed from Memory", { 0.2, 0.9, 0.2 })
end
end end
--Updates surface from the values in the input field --Updates surface from the values in the input field
function updateSurface() function updateSurface()
local customInfo = obj_surface.getCustomObject() local customInfo = obj_surface.getCustomObject()
customInfo.diffuse = self.getInputs()[2].value customInfo.diffuse = self.getInputs()[2].value
obj_surface.setCustomObject(customInfo) obj_surface.setCustomObject(customInfo)
obj_surface = obj_surface.reload() obj_surface = obj_surface.reload()
end end
--Table Scale control --Table Scale control
--Applies Scale to table pieces --Applies Scale to table pieces
function click_applyScale(_, color) function click_applyScale(_, color)
if permissionCheck(color) then if permissionCheck(color) then
local newWidth = tonumber(self.getInputs()[3].value) local newWidth = tonumber(self.getInputs()[3].value)
local newDepth = tonumber(self.getInputs()[4].value) local newDepth = tonumber(self.getInputs()[4].value)
if type(newWidth) ~= "number" then if type(newWidth) ~= "number" then
broadcastToAll("Invalid Width", {0.9,0.2,0.2}) broadcastToAll("Invalid Width", { 0.9, 0.2, 0.2 })
return return
elseif type(newDepth) ~= "number" then elseif type(newDepth) ~= "number" then
broadcastToAll("Invalid Depth", {0.9,0.2,0.2}) broadcastToAll("Invalid Depth", { 0.9, 0.2, 0.2 })
return return
elseif newWidth<0.1 or newDepth<0.1 then elseif newWidth < 0.1 or newDepth < 0.1 then
broadcastToAll("Scale cannot go below 0.1", {0.9,0.2,0.2}) broadcastToAll("Scale cannot go below 0.1", { 0.9, 0.2, 0.2 })
return return
elseif newWidth>12 or newDepth>12 then elseif newWidth > 12 or newDepth > 12 then
broadcastToAll("Scale should not go over 12 (world size limitation)", {0.9,0.2,0.2}) broadcastToAll("Scale should not go over 12 (world size limitation)", { 0.9, 0.2, 0.2 })
return return
else else
changeTableScale(math.abs(newWidth), math.abs(newDepth)) changeTableScale(math.abs(newWidth), math.abs(newDepth))
broadcastToAll("Scale applied.", {0.2,0.9,0.2}) broadcastToAll("Scale applied.", { 0.2, 0.9, 0.2 })
end
end end
end
end end
--Checks/unchecks move box for hands --Checks/unchecks move box for hands
function click_checkMove(_, color) function click_checkMove(_, color)
if permissionCheck(color) then if permissionCheck(color) then
local find_func = function(o) return o.click_function=="click_checkMove" end local find_func = function(o) return o.click_function == "click_checkMove" end
if checkData.move == true then if checkData.move == true then
checkData.move = false checkData.move = false
local buttonEntry = findButton(self, find_func) local buttonEntry = findButton(self, find_func)
self.editButton({index=buttonEntry.index, label=""}) self.editButton({ index = buttonEntry.index, label = "" })
else else
checkData.move = true checkData.move = true
local buttonEntry = findButton(self, find_func) local buttonEntry = findButton(self, find_func)
self.editButton({index=buttonEntry.index, label=string.char(10008)}) self.editButton({ index = buttonEntry.index, label = string.char(10008) })
end
end end
end
end end
--Checks/unchecks scale box for hands --Checks/unchecks scale box for hands
@ -206,273 +190,343 @@ end
--Alters scale of elements and moves them --Alters scale of elements and moves them
function changeTableScale(width, depth) function changeTableScale(width, depth)
--Scaling factors used to translate scale to position offset --Scaling factors used to translate scale to position offset
local width2pos = (width-1) * 18 local width2pos = (width - 1) * 18
local depth2pos = (depth-1) * 18 local depth2pos = (depth - 1) * 18
--Hand zone movement --Hand zone movement
if checkData.move == true then if checkData.move == true then
for _, pc in ipairs(ref_playerColor) do for _, pc in ipairs(ref_playerColor) do
if Player[pc].getHandCount() > 0 then if Player[pc].getHandCount() > 0 then
moveHandZone(Player[pc], width2pos, depth2pos) moveHandZone(Player[pc], width2pos, depth2pos)
end end
end
end end
--Hand zone scaling end
--The button to enable this was disabled for technical reasons --Hand zone scaling
if checkData.scale == true then --The button to enable this was disabled for technical reasons
for _, pc in ipairs(ref_playerColor) do if checkData.scale == true then
if Player[pc].getHandCount() > 0 then for _, pc in ipairs(ref_playerColor) do
scaleHandZone(Player[pc], width, depth) if Player[pc].getHandCount() > 0 then
end scaleHandZone(Player[pc], width, depth)
end end
end end
end
--Resizing table elements --Resizing table elements
obj_side_top.setScale({width, 1, 1}) obj_side_top.setScale({ width, 1, 1 })
obj_side_bot.setScale({width, 1, 1}) obj_side_bot.setScale({ width, 1, 1 })
obj_side_lef.setScale({depth, 1, 1}) obj_side_lef.setScale({ depth, 1, 1 })
obj_side_rig.setScale({depth, 1, 1}) obj_side_rig.setScale({ depth, 1, 1 })
obj_surface.setScale({width, 1, depth}) obj_surface.setScale({ width, 1, depth })
--Moving table elements to accomodate new scale --Moving table elements to accomodate new scale
obj_side_lef.setPosition({-width2pos,tableHeightOffset,0}) obj_side_lef.setPosition({ -width2pos, tableHeightOffset, 0 })
obj_side_rig.setPosition({ width2pos,tableHeightOffset,0}) obj_side_rig.setPosition({ width2pos, tableHeightOffset, 0 })
obj_side_top.setPosition({0,tableHeightOffset, depth2pos}) obj_side_top.setPosition({ 0, tableHeightOffset, depth2pos })
obj_side_bot.setPosition({0,tableHeightOffset,-depth2pos}) obj_side_bot.setPosition({ 0, tableHeightOffset, -depth2pos })
obj_leg1.setPosition({-width2pos,tableHeightOffset,-depth2pos}) obj_leg1.setPosition({ -width2pos, tableHeightOffset, -depth2pos })
obj_leg2.setPosition({-width2pos,tableHeightOffset, depth2pos}) obj_leg2.setPosition({ -width2pos, tableHeightOffset, depth2pos })
obj_leg3.setPosition({ width2pos,tableHeightOffset, depth2pos}) obj_leg3.setPosition({ width2pos, tableHeightOffset, depth2pos })
obj_leg4.setPosition({ width2pos,tableHeightOffset,-depth2pos}) obj_leg4.setPosition({ width2pos, tableHeightOffset, -depth2pos })
self.setPosition(obj_leg4.positionToWorld({-22.12, 8.74,-19.16})) self.setPosition(obj_leg4.positionToWorld({ -22.12, 8.74, -19.16 }))
--Only enabled when changing tableHeightOffset --Only enabled when changing tableHeightOffset
--obj_surface.setPosition({0,tableHeightOffset,0}) --obj_surface.setPosition({0,tableHeightOffset,0})
end end
--Move hand zone, p=player reference, facts are scaling factors --Move hand zone, p=player reference, facts are scaling factors
function moveHandZone(p, width2pos, depth2pos) function moveHandZone(p, width2pos, depth2pos)
local widthX = obj_side_rig.getPosition().x local widthX = obj_side_rig.getPosition().x
local depthZ = obj_side_top.getPosition().z local depthZ = obj_side_top.getPosition().z
for i=1, p.getHandCount() do for i = 1, p.getHandCount() do
local handT = p.getHandTransform() local handT = p.getHandTransform()
local pos = handT.position local pos = handT.position
local y = handT.rotation.y local y = handT.rotation.y
if y<45 or y>320 or y>135 and y<225 then if y < 45 or y > 320 or y > 135 and y < 225 then
if pos.z > 0 then if pos.z > 0 then
pos.z = pos.z + depth2pos - depthZ pos.z = pos.z + depth2pos - depthZ
else else
pos.z = pos.z - depth2pos + depthZ pos.z = pos.z - depth2pos + depthZ
end end
else else
if pos.x > 0 then if pos.x > 0 then
pos.x = pos.x + width2pos - widthX pos.x = pos.x + width2pos - widthX
else else
pos.x = pos.x - width2pos + widthX pos.x = pos.x - width2pos + widthX
end end
end
--Only enabled when changing tableHeightOffset
--pos.y = tableHeightOffset + 14
handT.position = pos
p.setHandTransform(handT, i)
end end
end
--Only enabled when changing tableHeightOffset
--pos.y = tableHeightOffset + 14
handT.position = pos
p.setHandTransform(handT, i)
end
end
---Scales hand zones, p=player reference, facts are scaling factors ---Scales hand zones, p=player reference, facts are scaling factors
function scaleHandZone(p, width, depth) function scaleHandZone(p, width, depth)
local widthFact = width / obj_side_top.getScale().x local widthFact = width / obj_side_top.getScale().x
local depthFact = depth / obj_side_lef.getScale().x local depthFact = depth / obj_side_lef.getScale().x
for i=1, p.getHandCount() do for i = 1, p.getHandCount() do
local handT = p.getHandTransform() local handT = p.getHandTransform()
local scale = handT.scale local scale = handT.scale
local y = handT.rotation.y local y = handT.rotation.y
if y<45 or y>320 or y>135 and y<225 then if y < 45 or y > 320 or y > 135 and y < 225 then
scale.x = scale.x * widthFact scale.x = scale.x * widthFact
else else
scale.x = scale.x * depthFact scale.x = scale.x * depthFact
end
handT.scale = scale
p.setHandTransform(handT, i)
end end
handT.scale = scale
p.setHandTransform(handT, i)
end
end end
--Information gathering --Information gathering
--Checks if a color is promoted or host --Checks if a color is promoted or host
function permissionCheck(color) function permissionCheck(color)
if Player[color].host==true or Player[color].promoted==true then if Player[color].host == true or Player[color].promoted == true then
return true return true
else else
return false return false
end end
end end
--Locates a string saved within memory file --Locates a string saved within memory file
function findInImageDataIndex(...) function findInImageDataIndex(...)
for _, str in ipairs({...}) do for _, str in ipairs({ ... }) do
for i, v in ipairs(tableImageData) do for i, v in ipairs(tableImageData) do
if v.url == str or v.name == str then if v.url == str or v.name == str then
return i return i
end end
end
end end
return nil end
return nil
end end
--Round number (num) to the Nth decimal (dec) --Round number (num) to the Nth decimal (dec)
function round(num, dec) function round(num, dec)
local mult = 10^(dec or 0) local mult = 10 ^ (dec or 0)
return math.floor(num * mult + 0.5) / mult return math.floor(num * mult + 0.5) / mult
end end
--Locates a button with a helper function --Locates a button with a helper function
function findButton(obj, func) function findButton(obj, func)
if func==nil then error("No func supplied to findButton") end if func == nil then error("No func supplied to findButton") end
for _, v in ipairs(obj.getButtons()) do for _, v in ipairs(obj.getButtons()) do
if func(v) then if func(v) then
return v return v
end
end end
return nil end
return nil
end end
--Creation of buttons/inputs --Creation of buttons/inputs
function createOpenCloseButton() function createOpenCloseButton()
local tooltip = "Open Table Control Panel" local tooltip = "Open Table Control Panel"
if controlActive then if controlActive then
tooltip = "Close Table Control Panel" tooltip = "Close Table Control Panel"
end end
self.createButton({ self.createButton({
click_function="click_toggleControl", function_owner=self, click_function = "click_toggleControl",
position={0,0,0}, rotation={-45,0,0}, height=400, width=400, function_owner = self,
color={1,1,1,0}, tooltip=tooltip position = { 0, 0, 0 },
}) rotation = { -45, 0, 0 },
height = 400,
width = 400,
color = { 1, 1, 1, 0 },
tooltip = tooltip
})
end end
function createSurfaceInput() function createSurfaceInput()
local currentURL = obj_surface.getCustomObject().diffuse local currentURL = obj_surface.getCustomObject().diffuse
local nickname = "" local nickname = ""
if findInImageDataIndex(currentURL) ~= nil then if findInImageDataIndex(currentURL) ~= nil then
nickname = tableImageData[findInImageDataIndex(currentURL)].name nickname = tableImageData[findInImageDataIndex(currentURL)].name
end end
self.createInput({ self.createInput({
label="Nickname", input_function="none", function_owner=self, label = "Nickname",
alignment=3, position={0,0,2}, height=224, width=4000, input_function = "none",
font_size=200, tooltip="Enter nickname for table image (only used for save)", function_owner = self,
value=nickname alignment = 3,
}) position = { 0, 0, 2 },
self.createInput({ height = 224,
label="URL", input_function="none", function_owner=self, width = 4000,
alignment=3, position={0,0,3}, height=224, width=4000, font_size = 200,
font_size=200, tooltip="Enter URL for tabletop image", tooltip = "Enter nickname for table image (only used for save)",
value=currentURL value = nickname
}) })
self.createInput({
label = "URL",
input_function = "none",
function_owner = self,
alignment = 3,
position = { 0, 0, 3 },
height = 224,
width = 4000,
font_size = 200,
tooltip = "Enter URL for tabletop image",
value = currentURL
})
end end
function createSurfaceButtons() function createSurfaceButtons()
--Label --Label
self.createButton({
label = "Tabletop Surface Image",
click_function = "none",
position = { 0, 0, 1 },
height = 0,
width = 0,
font_size = 300,
font_color = { 1, 1, 1 }
})
--Functional
self.createButton({
label = "Apply Image\nTo Table",
click_function = "click_applySurface",
function_owner = self,
tooltip = "Apply URL as table image",
position = { 2, 0, 4 },
height = 440,
width = 1400,
font_size = 200,
})
self.createButton({
label = "Save Image\nTo Memory",
click_function = "click_saveSurface",
function_owner = self,
tooltip = "Record URL into memory (requires nickname)",
position = { -2, 0, 4 },
height = 440,
width = 1400,
font_size = 200,
})
--Label
self.createButton({
label = "Load From Memory",
click_function = "none",
position = { 0, 0, 5.5 },
height = 0,
width = 0,
font_size = 300,
font_color = { 1, 1, 1 }
})
--Saves, created dynamically from memory file
for i, memoryEntry in ipairs(tableImageData) do
--Load
local funcName = i .. "loadMemory"
local func = function(x, y) click_loadMemory(x, y, i) end
self.setVar(funcName, func)
self.createButton({ self.createButton({
label="Tabletop Surface Image", click_function="none", label = memoryEntry.name,
position={0,0,1}, height=0, width=0, font_size=300, font_color={1,1,1} click_function = funcName,
function_owner = self,
tooltip = memoryEntry.url,
font_size = 200,
position = { -0.6, 0, 6.5 + 0.5 * (i - 1) },
height = 240,
width = 3300,
}) })
--Functional --Delete
local funcName = i .. "deleteMemory"
local func = function(x, y) click_deleteMemory(x, y, i) end
self.setVar(funcName, func)
self.createButton({ self.createButton({
label="Apply Image\nTo Table", click_function="click_applySurface", label = "DELETE",
function_owner=self, tooltip="Apply URL as table image", click_function = funcName,
position={2,0,4}, height=440, width=1400, font_size=200, function_owner = self,
tooltip = "",
position = { 3.6, 0, 6.5 + 0.5 * (i - 1) },
height = 240,
width = 600,
font_size = 160,
font_color = { 1, 0, 0 },
color = { 0.8, 0.8, 0.8 }
}) })
self.createButton({ end
label="Save Image\nTo Memory", click_function="click_saveSurface",
function_owner=self, tooltip="Record URL into memory (requires nickname)",
position={-2,0,4}, height=440, width=1400, font_size=200,
})
--Label
self.createButton({
label="Load From Memory", click_function="none",
position={0,0,5.5}, height=0, width=0, font_size=300, font_color={1,1,1}
})
--Saves, created dynamically from memory file
for i, memoryEntry in ipairs(tableImageData) do
--Load
local funcName = i.."loadMemory"
local func = function(x,y) click_loadMemory(x,y,i) end
self.setVar(funcName, func)
self.createButton({
label=memoryEntry.name, click_function=funcName,
function_owner=self, tooltip=memoryEntry.url, font_size=200,
position={-0.6,0,6.5+0.5*(i-1)}, height=240, width=3300,
})
--Delete
local funcName = i.."deleteMemory"
local func = function(x,y) click_deleteMemory(x,y,i) end
self.setVar(funcName, func)
self.createButton({
label="DELETE", click_function=funcName,
function_owner=self, tooltip="",
position={3.6,0,6.5+0.5*(i-1)}, height=240, width=600,
font_size=160, font_color={1,0,0}, color={0.8,0.8,0.8}
})
end
end end
function createScaleInput() function createScaleInput()
self.createInput({ self.createInput({
label=string.char(8644), input_function="none", function_owner=self, label = string.char(8644),
alignment=3, position={-8.5,0,2}, height=224, width=400, input_function = "none",
font_size=200, tooltip="Table Width", function_owner = self,
value=round(obj_side_top.getScale().x, 1) alignment = 3,
}) position = { -8.5, 0, 2 },
self.createInput({ height = 224,
label=string.char(8645), input_function="none", function_owner=self, width = 400,
alignment=3, position={-7.5,0,2}, height=224, width=400, font_size = 200,
font_size=200, tooltip="Table Depth", tooltip = "Table Width",
value=round(obj_side_lef.getScale().x, 1) value = round(obj_side_top.getScale().x, 1)
}) })
self.createInput({
label = string.char(8645),
input_function = "none",
function_owner = self,
alignment = 3,
position = { -7.5, 0, 2 },
height = 224,
width = 400,
font_size = 200,
tooltip = "Table Depth",
value = round(obj_side_lef.getScale().x, 1)
})
end end
function createScaleButtons() function createScaleButtons()
--Labels --Labels
self.createButton({ self.createButton({
label="Table Scale", click_function="none", label = "Table Scale",
position={-8,0,1}, height=0, width=0, font_size=300, font_color={1,1,1} click_function = "none",
}) position = { -8, 0, 1 },
self.createButton({ height = 0,
label=string.char(8644).." "..string.char(8645), width = 0,
click_function="none", font_size = 300,
position={-8,0,2}, height=0, width=0, font_size=300, font_color={1,1,1} font_color = { 1, 1, 1 }
}) })
self.createButton({ self.createButton({
label="Move Hands:", click_function="none", label = string.char(8644) .. " " .. string.char(8645),
position={-8.3,0,3}, height=0, width=0, font_size=200, font_color={1,1,1} click_function = "none",
}) position = { -8, 0, 2 },
--Disabled due to me removing the feature for technical reasons height = 0,
--[[ width = 0,
font_size = 300,
font_color = { 1, 1, 1 }
})
self.createButton({
label = "Move Hands:",
click_function = "none",
position = { -8.3, 0, 3 },
height = 0,
width = 0,
font_size = 200,
font_color = { 1, 1, 1 }
})
--Disabled due to me removing the feature for technical reasons
--[[
self.createButton({ self.createButton({
label="Scale Hands:", click_function="none", label="Scale Hands:", click_function="none",
position={-8.3,0,4}, height=0, width=0, font_size=200, font_color={1,1,1} position={-8.3,0,4}, height=0, width=0, font_size=200, font_color={1,1,1}
}) })
]] ]]
--Checkboxes --Checkboxes
local label = "" local label = ""
if checkData.move == true then label = string.char(10008) end if checkData.move == true then label = string.char(10008) end
self.createButton({ self.createButton({
label=label, click_function="click_checkMove", label = label,
function_owner=self, tooltip="Check to move hands when table is rescaled", click_function = "click_checkMove",
position={-6.8,0,3}, height=224, width=224, font_size=200, function_owner = self,
}) tooltip = "Check to move hands when table is rescaled",
--[[ position = { -6.8, 0, 3 },
height = 224,
width = 224,
font_size = 200,
})
--[[
local label = "" local label = ""
if checkData.scale == true then label = string.char(10008) end if checkData.scale == true then label = string.char(10008) end
self.createButton({ self.createButton({
@ -481,31 +535,29 @@ function createScaleButtons()
position={-6.8,0,4}, height=224, width=224, font_size=200, position={-6.8,0,4}, height=224, width=224, font_size=200,
}) })
]] ]]
--Apply button --Apply button
self.createButton({ self.createButton({
label="Apply Scale", click_function="click_applyScale", label = "Apply Scale",
function_owner=self, tooltip="Apply width/depth to table", click_function = "click_applyScale",
position={-8,0,4}, height=440, width=1400, font_size=200, function_owner = self,
}) tooltip = "Apply width/depth to table",
position = { -8, 0, 4 },
height = 440,
width = 1400,
font_size = 200,
})
end end
--Data tables --Data tables
ref_noninteractable = { ref_noninteractable = {
"afc863","c8edca","393bf7","12c65e","f938a2","9f95fd","35b95f", "afc863", "c8edca", "393bf7", "12c65e", "f938a2", "9f95fd", "35b95f",
"5af8f2","4ee1f2","bd69bd" "5af8f2", "4ee1f2", "bd69bd"
} }
ref_playerColor = { ref_playerColor = {
"White", "Brown", "Red", "Orange", "Yellow", "White", "Brown", "Red", "Orange", "Yellow",
"Green", "Teal", "Blue", "Purple", "Pink", "Black" "Green", "Teal", "Blue", "Purple", "Pink", "Black"
} }
--Dummy function, absorbs unwanted triggers --Dummy function, absorbs unwanted triggers

View File

@ -41,7 +41,7 @@
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "require(\"core/UniversalActionAbilityToken\")", "LuaScript": "require(\"core/UniversalActionAbilityToken\")",
"LuaScriptState": "", "LuaScriptState": "{\"class\":\"Neutral\",\"symbol\":\"Neutral\"}",
"MeasureMovement": false, "MeasureMovement": false,
"Memo": "universalActionAbility", "Memo": "universalActionAbility",
"Name": "Custom_Tile", "Name": "Custom_Tile",

View File

@ -11,9 +11,6 @@ local phaseImages = {
"http://cloud-3.steamusercontent.com/ugc/982233321870237261/C287CAED2423970F33E72D6C7415CBEC6794C533/" "http://cloud-3.steamusercontent.com/ugc/982233321870237261/C287CAED2423970F33E72D6C7415CBEC6794C533/"
} }
-- these are intentionally global for remote updating
-- phaseId, broadcastChange
function onSave() function onSave()
return JSON.encode({ return JSON.encode({
phaseId = phaseId, phaseId = phaseId,
@ -21,11 +18,15 @@ function onSave()
}) })
end end
function loadFromSaveTable(savedData)
for var, val in pairs(JSON.decode(savedData)) do
_G[var] = val
end
end
function onLoad(savedData) function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData) loadFromSaveTable(savedData)
phaseId = loadedData.phaseId
broadcastChange = loadedData.broadcastChange
else else
phaseId = 1 phaseId = 1
broadcastChange = false broadcastChange = false

View File

@ -1,277 +1,275 @@
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
function onload(savedData) function onSave()
revealCardPositions = { return JSON.encode({ saved_hiddenCards = hiddenCards })
Vector(3.5, 0.25, 0),
Vector(-3.5, 0.25, 0)
}
revealCardPositionsSwap = {
Vector(-3.5, 0.25, 0),
Vector(3.5, 0.25, 0)
}
self.createButton({
label = 'Underworld Market\nHelper',
click_function = "none",
function_owner = self,
position = {0,-0.1,-1.6},
height = 0,
width = 0,
font_size = 145,
font_color = {1,1,1}
})
hiddenCards = 10
hiddenCardLabel = '-----'
isSetup = false
movingCards = false
self.addContextMenuItem('Reset helper', resetHelper)
if savedData ~= '' then
local loaded_data = JSON.decode(savedData)
hiddenCards = loaded_data.saved_hiddenCards
isSetup = true
refreshButtons()
end
end end
function onSave() function onload(savedData)
return JSON.encode({ revealCardPositions = {
saved_hiddenCards = hiddenCards Vector(3.5, 0.25, 0),
}) Vector(-3.5, 0.25, 0)
}
revealCardPositionsSwap = {
Vector(-3.5, 0.25, 0),
Vector(3.5, 0.25, 0)
}
self.createButton({
label = 'Underworld Market\nHelper',
click_function = "none",
function_owner = self,
position = { 0, -0.1, -1.6 },
height = 0,
width = 0,
font_size = 145,
font_color = { 1, 1, 1 }
})
hiddenCards = 10
hiddenCardLabel = '-----'
isSetup = false
movingCards = false
self.addContextMenuItem('Reset helper', resetHelper)
if savedData and savedData ~= '' then
local loaded_data = JSON.decode(savedData)
hiddenCards = loaded_data.saved_hiddenCards
isSetup = true
refreshButtons()
end
end end
function onObjectEnterContainer(container, object) function onObjectEnterContainer(container, object)
if container ~= self then return end if container ~= self then return end
if isSetup and object.tag == "Card" then if isSetup and object.tag == "Card" then
refreshButtons() refreshButtons()
end end
if object.tag == "Deck" then if object.tag == "Deck" then
if validateDeck(object) then if validateDeck(object) then
takeDeckOut(object.getGUID(), self.getPosition() + Vector(0, 0.1, 0)) takeDeckOut(object.getGUID(), self.getPosition() + Vector(0, 0.1, 0))
refreshButtons() refreshButtons()
isSetup = true isSetup = true
end
elseif object.tag ~= "Card" then
broadcastToAll("The 'Underworld Market Helper' is meant to be used for cards.", "White")
end end
elseif object.tag ~= "Card" then
broadcastToAll("The 'Underworld Market Helper' is meant to be used for cards.", "White")
end
end end
function onObjectLeaveContainer(container, object) function onObjectLeaveContainer(container, object)
if container ~= self then return end if container ~= self then return end
if isSetup then if isSetup then
refreshButtons() refreshButtons()
end end
end end
function validateDeck(deck) function validateDeck(deck)
if deck.getQuantity() ~= 10 then if deck.getQuantity() ~= 10 then
print('Underworld Market Helper: Deck must include exactly 10 cards.') print('Underworld Market Helper: Deck must include exactly 10 cards.')
return false return false
end
local illicitCount = 0
for _, card in ipairs(deck.getObjects()) do
decodedGMNotes = JSON.decode(card.gm_notes)
if decodedGMNotes ~= nil and string.find(decodedGMNotes.traits, "Illicit", 1, true) then
illicitCount = illicitCount + 1
end end
end
local illicitCount = 0 if illicitCount ~= 10 then
print('Underworld Market Helper: Deck must include 10 Illicit cards.')
return false
end
for _, card in ipairs(deck.getObjects()) do return true
decodedGMNotes = JSON.decode(card.gm_notes)
if decodedGMNotes ~= nil and string.find(decodedGMNotes.traits, "Illicit", 1, true) then
illicitCount = illicitCount + 1
end
end
if illicitCount ~= 10 then
print('Underworld Market Helper: Deck must include 10 Illicit cards.')
return false
end
return true
end end
function refreshButtons() function refreshButtons()
local cardsList = '' local cardsList = ''
for i, card in ipairs(self.getObjects()) do for i, card in ipairs(self.getObjects()) do
local localCardName = card.name local localCardName = card.name
if i <= hiddenCards then if i <= hiddenCards then
localCardName = hiddenCardLabel localCardName = hiddenCardLabel
end
cardsList = cardsList .. localCardName .. '\n'
end end
self.clearButtons() cardsList = cardsList .. localCardName .. '\n'
end
self.createButton({ self.clearButtons()
label = 'Market Deck:',
click_function = "none",
function_owner = self,
position = {0,-0.1,-1.6},
height = 0,
width = 0,
font_size = 150,
font_color = {1,1,1}
})
self.createButton({ self.createButton({
label = cardsList, label = 'Market Deck:',
click_function = "none", click_function = "none",
function_owner = self, function_owner = self,
position = {0,-0.1,0.15}, position = { 0, -0.1, -1.6 },
height = 0, height = 0,
width = 0, width = 0,
font_size = 115, font_size = 150,
font_color = {1,1,1} font_color = { 1, 1, 1 }
}) })
self.createButton({ self.createButton({
click_function = 'revealFirstTwoCards', label = cardsList,
function_owner = self, click_function = "none",
label = 'Reveal', function_owner = self,
position = {-0.85,0,1.6}, position = { 0, -0.1, 0.15 },
width = 375, height = 0,
height = 175, width = 0,
font_size = 90 font_size = 115,
}) font_color = { 1, 1, 1 }
})
self.createButton({ self.createButton({
click_function = 'swap', click_function = 'revealFirstTwoCards',
function_owner = self, function_owner = self,
label = 'Swap', label = 'Reveal',
position = {0,0,1.6}, position = { -0.85, 0, 1.6 },
width = 375, width = 375,
height = 175, height = 175,
font_size = 90 font_size = 90
}) })
self.createButton({ self.createButton({
click_function = 'finish', click_function = 'swap',
function_owner = self, function_owner = self,
label = 'Finish', label = 'Swap',
position = {0.85,0,1.6}, position = { 0, 0, 1.6 },
width = 375, width = 375,
height = 175, height = 175,
font_size = 90 font_size = 90
}) })
self.createButton({
click_function = 'finish',
function_owner = self,
label = 'Finish',
position = { 0.85, 0, 1.6 },
width = 375,
height = 175,
font_size = 90
})
end end
function takeDeckOut(guid, pos) function takeDeckOut(guid, pos)
local deck = self.takeObject({ guid = guid, position = pos, smooth = false }) local deck = self.takeObject({ guid = guid, position = pos, smooth = false })
for i = 1, #deck.getObjects() do for i = 1, #deck.getObjects() do
self.putObject(deck.takeObject({ position = pos + Vector(0, 0.1 * i, 0), smooth = false })) self.putObject(deck.takeObject({ position = pos + Vector(0, 0.1 * i, 0), smooth = false }))
end end
self.shuffle() self.shuffle()
end end
function getRevealedCards() function getRevealedCards()
local revealedCards = {} local revealedCards = {}
for _, pos in ipairs(revealCardPositions) do for _, pos in ipairs(revealCardPositions) do
for _, obj in ipairs(searchLib.atPosition(self.positionToWorld(pos), "isCard")) do for _, obj in ipairs(searchLib.atPosition(self.positionToWorld(pos), "isCard")) do
table.insert(revealedCards, obj.getGUID()) table.insert(revealedCards, obj.getGUID())
end
end end
end
return revealedCards return revealedCards
end end
function revealFirstTwoCards() function revealFirstTwoCards()
if movingCards or #getRevealedCards() > 0 then return end if movingCards or #getRevealedCards() > 0 then return end
for i, card in ipairs(self.getObjects()) do for i, card in ipairs(self.getObjects()) do
movingCards = true movingCards = true
self.takeObject({ self.takeObject({
index = 0, index = 0,
rotation = self.getRotation(), rotation = self.getRotation(),
position = self.positionToWorld(revealCardPositions[i]), position = self.positionToWorld(revealCardPositions[i]),
callback_function = function(obj) callback_function = function(obj)
obj.resting = true obj.resting = true
movingCards = false movingCards = false
end end
}) })
hiddenCards = hiddenCards - 1 hiddenCards = hiddenCards - 1
if i == 2 or #self.getObjects() == 0 then if i == 2 or #self.getObjects() == 0 then
break break
end
end end
end
refreshButtons() refreshButtons()
end end
function swap() function swap()
if movingCards then return end if movingCards then return end
local revealedCards = getRevealedCards() local revealedCards = getRevealedCards()
if #revealedCards == 2 then if #revealedCards == 2 then
for i, revealedCardGUID in ipairs(revealedCards) do for i, revealedCardGUID in ipairs(revealedCards) do
local revealedCard = getObjectFromGUID(revealedCardGUID) local revealedCard = getObjectFromGUID(revealedCardGUID)
revealedCard.setPositionSmooth(self.positionToWorld(revealCardPositionsSwap[i]), false, false) revealedCard.setPositionSmooth(self.positionToWorld(revealCardPositionsSwap[i]), false, false)
end
end end
end
end end
function finish() function finish()
if movingCards then return end if movingCards then return end
local revealedCards = getRevealedCards() local revealedCards = getRevealedCards()
movingCards = true movingCards = true
for i, revealedCardGUID in ipairs(revealedCards) do for i, revealedCardGUID in ipairs(revealedCards) do
self.putObject(getObjectFromGUID(revealedCardGUID)) self.putObject(getObjectFromGUID(revealedCardGUID))
end end
Wait.time( Wait.time(
function() function()
movingCards = false movingCards = false
end, end,
0.75) 0.75)
end end
function resetHelper() function resetHelper()
for i, card in ipairs(self.getObjects()) do for i, card in ipairs(self.getObjects()) do
self.takeObject({ self.takeObject({
index = 0, index = 0,
smooth = false, smooth = false,
rotation = self.getRotation(), rotation = self.getRotation(),
position = self.positionToWorld(revealCardPositions[2]) position = self.positionToWorld(revealCardPositions[2])
})
end
self.clearButtons()
self.createButton({
label = 'Underworld Market\nHelper',
click_function = "none",
function_owner = self,
position = {0,-0.1,-1.6},
height = 0,
width = 0,
font_size = 145,
font_color = {1,1,1}
}) })
end
hiddenCards = 10 self.clearButtons()
isSetup = false
movingCards = false
self.reset() self.createButton({
label = 'Underworld Market\nHelper',
click_function = "none",
function_owner = self,
position = { 0, -0.1, -1.6 },
height = 0,
width = 0,
font_size = 145,
font_color = { 1, 1, 1 }
})
print('Underworld Market Helper: Helper has been reset.') hiddenCards = 10
isSetup = false
movingCards = false
self.reset()
print('Underworld Market Helper: Helper has been reset.')
end end

View File

@ -483,13 +483,12 @@ modeData = {
} }
function onSave() function onSave()
local globalState = JSON.encode(SPAWNED_PLAYER_CARD_GUIDS) return JSON.encode(SPAWNED_PLAYER_CARD_GUIDS)
return globalState
end end
function onLoad(save_state) function onLoad(savedData)
if save_state ~= '' then if savedData and savedData ~= '' then
SPAWNED_PLAYER_CARD_GUIDS = JSON.decode(save_state) SPAWNED_PLAYER_CARD_GUIDS = JSON.decode(savedData)
else else
SPAWNED_PLAYER_CARD_GUIDS = {} SPAWNED_PLAYER_CARD_GUIDS = {}
end end

View File

@ -22,7 +22,14 @@ local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1, z = 10.38 }
local isReshuffling = false local isReshuffling = false
local collisionEnabled = false local collisionEnabled = false
local currentScenario, useFrontData, tokenData local currentScenario, useFrontData, tokenData
local TRASH, DATA_HELPER
function onSave()
return JSON.encode({
currentScenario = currentScenario,
useFrontData = useFrontData,
tokenData = tokenData
})
end
function onLoad(savedData) function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then
@ -31,20 +38,9 @@ function onLoad(savedData)
useFrontData = loadedState.useFrontData or true useFrontData = loadedState.useFrontData or true
tokenData = loadedState.tokenData or {} tokenData = loadedState.tokenData or {}
end end
TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
DATA_HELPER = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper")
Wait.time(function() collisionEnabled = true end, 0.1) Wait.time(function() collisionEnabled = true end, 0.1)
end end
function onSave()
return JSON.encode({
currentScenario = currentScenario,
useFrontData = useFrontData,
tokenData = tokenData
})
end
--------------------------------------------------------- ---------------------------------------------------------
-- collison and container event handling -- collison and container event handling
--------------------------------------------------------- ---------------------------------------------------------
@ -182,6 +178,7 @@ end
-- draw the provided card to the requesting playermat -- draw the provided card to the requesting playermat
function actualEncounterCardDraw(card, params) function actualEncounterCardDraw(card, params)
local metadata = JSON.decode(card.getGMNotes()) or {} local metadata = JSON.decode(card.getGMNotes()) or {}
local DATA_HELPER = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper")
-- draw hidden cards facedown -- draw hidden cards facedown
local faceUpRotation = 0 local faceUpRotation = 0
@ -249,6 +246,7 @@ end
-- removes tokens from the provided card/deck -- removes tokens from the provided card/deck
function removeTokensFromObject(object) function removeTokensFromObject(object)
local TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
for _, obj in ipairs(searchLib.onObject(object)) do for _, obj in ipairs(searchLib.onObject(object)) do
if obj.getGUID() ~= "4ee1f2" and -- table if obj.getGUID() ~= "4ee1f2" and -- table
obj ~= self and obj ~= self and

View File

@ -89,13 +89,9 @@ function onLoad(savedData)
pitch = loadedData.pitch pitch = loadedData.pitch
distance = loadedData.distance distance = loadedData.distance
else else
local allColors = Player.getColors() -- initialize tables with defaults
for _, color in ipairs(Player.getColors()) do
for _, color in ipairs(allColors) do
-- default state for claims
claims[color] = {} claims[color] = {}
-- default state for visibility
visibility[color] = { full = false, play = false } visibility[color] = { full = false, play = false }
end end
end end

View File

@ -3,7 +3,12 @@ local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local typeIndex, selectionIndex, plainNameCache local typeIndex, selectionIndex, plainNameCache
function onSave() return JSON.encode({ typeIndex = typeIndex, selectionIndex = selectionIndex }) end function onSave()
return JSON.encode({
typeIndex = typeIndex,
selectionIndex = selectionIndex
})
end
function onLoad(savedData) function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then

View File

@ -23,7 +23,9 @@ inputParameters.scale = { 0.1, 1, 0.1 }
inputParameters.color = { 0.9, 0.7, 0.5 } inputParameters.color = { 0.9, 0.7, 0.5 }
inputParameters.font_color = { 0, 0, 0 } inputParameters.font_color = { 0, 0, 0 }
function onSave() return JSON.encode({ spawnAll, searchExact, inputParameters.value }) end function onSave()
return JSON.encode({ spawnAll, searchExact, inputParameters.value })
end
function onLoad(savedData) function onLoad(savedData)
local loadedData = JSON.decode(savedData) local loadedData = JSON.decode(savedData)