reworking variable names

This commit is contained in:
Chr1Z93 2023-05-08 13:53:38 +02:00
parent bcfd405651
commit d50f34bdc0
2 changed files with 106 additions and 246 deletions

View File

@ -1,79 +1,75 @@
local playmatApi = require("playermat/PlaymatApi") local playmatApi = require("playermat/PlaymatApi")
fullButtonData = { fullButtonData = {
{ id = "1", width = "84", height = "33", offsetX = "1", offsetY = "2" }, -- Act/Agenda { id = "1", width = "84", height = "33", offset = "1 2" }, -- Act/Agenda
{ id = "2", width = "78", height = "69", offsetX = "1", offsetY = "-62" }, -- Map { id = "2", width = "78", height = "69", offset = "1 -62" }, -- Map
{ id = "3", width = "70", height = "36", offsetX = "-36", offsetY = "-126" }, -- White { id = "3", width = "70", height = "36", offset = "-38 -126" }, -- White
{ id = "4", width = "70", height = "36", offsetX = "39", offsetY = "-126" }, -- Orange { id = "4", width = "70", height = "36", offset = "38 -126" }, -- Orange
{ id = "5", width = "36", height = "70", offsetX = "-62", offsetY = "-66" }, -- Green { id = "5", width = "36", height = "70", offset = "-63 -66" }, -- Green
{ id = "6", width = "36", height = "70", offsetX = "64", offsetY = "-66" }, -- Red { id = "6", width = "36", height = "70", offset = "63 -66" }, -- Red
{ id = "7", width = "38", height = "38", offsetX = "-64", offsetY = "-3" }, -- Victory { id = "7", width = "38", height = "38", offset = "-65 -3" }, -- Victory
{ id = "8", width = "40", height = "40", offsetX = "66", offsetY = "-3" }, -- Guide { id = "8", width = "40", height = "40", offset = "65 -3" }, -- Guide
{ id = "9", width = "56", height = "16", offsetX = "1", offsetY = "-20" }, -- Player count { id = "9", width = "56", height = "16", offset = "1 -20" }, -- Player count
{ id = "10", width = "36", height = "16", offsetX = "1", offsetY = "-102" }, -- Bless/Curse { id = "10", width = "36", height = "16", offset = "1 -102" }, -- Bless/Curse
{ id = "11", width = "168", height = "56", offsetX = "1", offsetY = "47" }, -- Scenarios { id = "11", width = "168", height = "56", offset = "1 47" }, -- Scenarios
{ id = "12", width = "52", height = "53", offsetX = "-154", offsetY = "134" }, -- Player card panel { id = "12", width = "52", height = "53", offset = "-154 134" }, -- Player card panel
{ id = "13", width = "22", height = "22", offsetX = "-116", offsetY = "132" }, -- Search card panel { id = "13", width = "22", height = "22", offset = "-116 132" }, -- Search card panel
{ id = "14", width = "120", height = "75", offsetX = "-152", offsetY = "70" }, -- Player card display { id = "14", width = "120", height = "75", offset = "-152 70" }, -- Player card display
{ id = "15", width = "40", height = "54", offsetX = "-150", offsetY = "-38" }, -- Deck builder { id = "15", width = "40", height = "54", offset = "-150 -38" }, -- Deck builder
{ id = "16", width = "104", height = "84", offsetX = "-154", offsetY = "-114" }, -- Rules area { id = "16", width = "104", height = "84", offset = "-154 -114" }, -- Rules area
{ id = "17", width = "100", height = "170", offsetX = "152", offsetY = "72" }, -- Cycle area { id = "17", width = "100", height = "170", offset = "152 72" }, -- Cycle area
{ id = "18", width = "56", height = "60", offsetX = "182", offsetY = "-124" }, -- Additions { id = "18", width = "56", height = "60", offset = "182 -124" }, -- Additions
{ id = "19", width = "20", height = "20", offsetX = "-8", offsetY = "150" }, -- Shrink { id = "19", width = "20", height = "20", offset = "-8 150" }, -- Shrink
{ id = "20", width = "20", height = "20", offsetX = "12", offsetY = "150" } -- Close { id = "20", width = "20", height = "20", offset = "12 150" } -- Close
} }
playButtonData = { playButtonData = {
{ id = "1", width = "80", height = "33", offsetX = "0", offsetY = "55" }, { id = "1", width = "80", height = "33", offset = "0 55" },
{ id = "2", width = "78", height = "70", offsetX = "0", offsetY = "-8" }, { id = "2", width = "78", height = "70", offset = "0 -8" },
{ id = "3", width = "68", height = "32", offsetX = "-36", offsetY = "-71" }, { id = "3", width = "68", height = "32", offset = "-36 -71" },
{ id = "4", width = "68", height = "32", offsetX = "36", offsetY = "-71" }, { id = "4", width = "68", height = "32", offset = "36 -71" },
{ id = "5", width = "35", height = "66", offsetX = "-65", offsetY = "-10" }, { id = "5", width = "35", height = "66", offset = "-65 -10" },
{ id = "6", width = "35", height = "66", offsetX = "65", offsetY = "-10" }, { id = "6", width = "35", height = "66", offset = "65 -10" },
{ id = "7", width = "38", height = "38", offsetX = "-66", offsetY = "52" }, { id = "7", width = "38", height = "38", offset = "-66 52" },
{ id = "8", width = "38", height = "38", offsetX = "66", offsetY = "52" }, { id = "8", width = "38", height = "38", offset = "66 52" },
{ id = "9", width = "50", height = "12", offsetX = "0", offsetY = "33" }, { id = "9", width = "50", height = "12", offset = "0 33" },
{ id = "10", width = "32", height = "12", offsetX = "0", offsetY = "-48" }, { id = "10", width = "32", height = "12", offset = "0 -48" },
{ id = "19", width = "20", height = "20", offsetX = "-10", offsetY = "80" }, { id = "19", width = "20", height = "20", offset = "-10 80" },
{ id = "20", width = "20", height = "20", offsetX = "10", offsetY = "80" } { id = "20", width = "20", height = "20", offset = "10 80" }
} }
defaultCameraParams = { defaultCameraParams = {
{ position = { -1.626, -2.5, 0 }, pitch = 74, yaw = 90, distance = 18 }, -- 1. ActAgenda { position = { -1.6, 1.55, 0 }, distance = 18 }, -- 1. ActAgenda
{ position = { -27.822, -2.5, 0.424 }, pitch = 74, yaw = 90, distance = -1 }, -- 2. Map { position = { -28, 1.55, 0.42 }, distance = -1 }, -- 2. Map
{ position = { -31.592, -2.5, 26.392 }, pitch = 74, yaw = 180, distance = -1 }, -- 3. Green playmat { position = { -31.6, 1.55, 26.4 }, distance = -1 }, -- 3. Green playmat
{ position = { -55.026, -2.5, 12.052 }, pitch = 74, yaw = 90, distance = -1 }, -- 4. White playmat { position = { -55, 1.55, 12.05 }, distance = -1 }, -- 4. White playmat
{ position = { -55.026, -2.5, -11.479 }, pitch = 74, yaw = 90, distance = -1 }, -- 5. Orange playmat { position = { -55, 1.55, -11.48 }, distance = -1 }, -- 5. Orange playmat
{ position = { -31.592, -2.5, -26.392 }, pitch = 74, yaw = 0, distance = -1 }, -- 6. Red playmat { position = { -31.6, 1.55, -26.4 }, distance = -1 }, -- 6. Red playmat
{ position = { -3.029, 1.652, 24.296 }, pitch = 74, yaw = 90, distance = 16 }, -- 7. Victory / SetAside { position = { -3, 1.55, 30 }, distance = 16 }, -- 7. Victory / SetAside
{ position = { -2.936, 1.552, -26.757 }, pitch = 74, yaw = 90, distance = 16 }, -- 8. Guide { position = { -3, 1.55, -26.76 }, distance = 16 }, -- 8. Guide
{ position = { -11.833, 1.491, -0.145 }, pitch = 74, yaw = 90, distance = 10 }, -- 9. Player count { position = { -11.83, 1.55, 0 }, distance = 10 }, -- 9. Player count
{ position = { -48.352, 1.552, -0.055 }, pitch = 74, yaw = 90, distance = 10 }, -- 10. Bless/Curse { position = { -48.35, 1.55, 0 }, distance = 10 }, -- 10. Bless/Curse
{ position = { 12.560, 1.912, 0.458 }, pitch = 74, yaw = 90, distance = 35 }, -- 11. Scenarios { position = { 12.56, 1.55, 0 }, distance = 45 }, -- 11. Scenarios
{ position = { 57.835, 1.552, 75.385 }, pitch = 74, yaw = 90, distance = 22 }, -- 12. Player card panel { position = { 57.8, 1.55, 71 }, distance = 22 }, -- 12. Player card panel
{ position = { 60.377, 1.552, 55.941 }, pitch = 74, yaw = 90, distance = 10 }, -- 13. Card search panel { position = { 60.38, 1.55, 56 }, distance = 10 }, -- 13. Card search panel
{ position = { 27.482, 1.480, 71.057 }, pitch = 74, yaw = 90, distance = 35 }, -- 14. Player card area { position = { 27.48, 1.55, 71 }, distance = 35 }, -- 14. Player card area
{ position = { -19.481, 1.552, 70.880 }, pitch = 74, yaw = 90, distance = 22 }, -- 15. Deck builder { position = { -19.48, 1.55, 71 }, distance = 22 }, -- 15. Deck builder
{ position = { -52.918, 1.478, 70.899 }, pitch = 74, yaw = 90, distance = 42 }, -- 16. Rules area { position = { -52.92, 1.55, 71 }, distance = 42 }, -- 16. Rules area
{ position = { 24.551, 2.222, -71.284 }, pitch = 60, yaw = 90, distance = 60 }, -- 17. Cycle area { position = { 26, 1.55, -71 }, distance = 65 }, -- 17. Cycle area
{ position = { -59.077, 1.462, -85.472 }, pitch = 74, yaw = 90, distance = 27 } -- 18. Additions { position = { -59.08, 1.55, -83 }, distance = 27 } -- 18. Additions
} }
local cameraParams = { {}, {}, {}, {} }
local playermatData = { {}, {}, {}, {} } local playermatData = { {}, {}, {}, {} }
local editing = false local editing = false
local claiming = false local claiming = false
local visibility = {}
local claims = {}
function onSave() function onSave()
local allclaims = {}
for i = 1, 4 do
table.insert(allclaims, playermatData[i].claims)
end
return JSON.encode({ return JSON.encode({
cameras = cameraParams, cameras = cameraParams,
fullVis = fullVisibility, visibility = visibility,
playVis = playVisibility, claims = claims
claims = allclaims
}) })
end end
@ -81,92 +77,16 @@ function onLoad(savedData)
if savedData ~= "" then if savedData ~= "" then
local loadedData = JSON.decode(savedData) local loadedData = JSON.decode(savedData)
cameraParams = loadedData.cameras cameraParams = loadedData.cameras
fullVisibility = loadedData.fullVis visibility = loadedData.visibility
playVisibility = loadedData.playVis claims = loadedData.claims
for i = 1, 4 do
playermatData[i].claims = loadedData.claims[i]
end
else else
cameraParams = { {}, {}, {}, {} } resetCameras()
for i = 1, 4 do
for j = 1, #defaultCameraParams do
cameraParams[i][j] = defaultCameraParams[j]
end
end
fullVisibility = { false, false, false, false }
playVisibility = { false, false, false, false }
resetClaimColors() resetClaimColors()
end end
createTileButtons()
updateOverlay() updateOverlay()
end end
function createTileButtons()
local buttonParameters = {}
buttonParameters.function_owner = self
buttonParameters.label = ""
-- index 0: Full Area
buttonParameters.tooltip = "Display full overlay"
buttonParameters.click_function = "displayFull"
buttonParameters.position = { x = 0, y = 0.1, z = -0.63 }
buttonParameters.height = 70
buttonParameters.width = 700
buttonParameters.color = { 1, 0, 0, 0 }
self.createButton(buttonParameters)
-- index 1: Play Area
buttonParameters.tooltip = "Display only play area"
buttonParameters.click_function = "displayPlayArea"
buttonParameters.position = { x = 0, y = 0.1, z = -0.39 }
self.createButton(buttonParameters)
-- index 2: Close Overlay
buttonParameters.tooltip = "Close overlay"
buttonParameters.click_function = "closeOverlay"
buttonParameters.position = { x = 0, y = 0.1, z = -0.16 }
self.createButton(buttonParameters)
-- index 3: Modify Camera
buttonParameters.tooltip = "Modify a camera position"
buttonParameters.click_function = "beginSetCamera"
buttonParameters.position = { x = 0, y = 0.1, z = 0.19 }
self.createButton(buttonParameters)
-- index 4: Claim a color
buttonParameters.tooltip = "Claim a color (you will switch to this color when clicking in the overlay)"
buttonParameters.click_function = "beginClaimColor"
buttonParameters.width = 475
buttonParameters.position = { x = -0.22, y = 0.1, z = 0.42 }
self.createButton(buttonParameters)
-- index 4: Reset color claims
buttonParameters.tooltip = "Reset all color claims"
buttonParameters.click_function = "resetClaimColors"
buttonParameters.width = 230
buttonParameters.position = { x = 0.48, y = 0.1, z = 0.42 }
self.createButton(buttonParameters)
-- index 5: Reset camera positions
buttonParameters.tooltip = "Reset camera positions to default"
buttonParameters.click_function = "resetCameras"
buttonParameters.width = 700
buttonParameters.position = { x = 0, y = 0.1, z = 0.78 }
self.createButton(buttonParameters)
end
function displayFull(_, color)
setVisibility("full", color)
end
function displayPlayArea(_, color)
setVisibility("play", color)
end
function closeOverlay(_, color) function closeOverlay(_, color)
setVisibility("close", color) setVisibility("close", color)
end end
@ -174,39 +94,24 @@ end
function cycleVisibility(color) function cycleVisibility(color)
setVisibility("next", color) setVisibility("next", color)
end end
function setVisibility(type, color) function setVisibility(type, color)
local colors = getColors(color) local visibility[color] = { full = false, play = false }
local visibility
if type == "full" then
visibility = { full = true, play = false }
elseif type == "play" then
visibility = { full = false, play = true }
else
visibility = { full = false, play = false }
end
for _, v in ipairs(colors) do
if v > 0 then
-- override visibility to cycle to the next
if type == "next" then if type == "next" then
if fullVisibility[v] then if visibility[color].full then
visibility = { full = false, play = true } visibility[color] = { full = false, play = true }
elseif playVisibility[v] then elseif visibility[color].play then
visibility = { full = false, play = false } visibility[color] = { full = false, play = false }
else else
visibility = { full = true, play = false } visibility[color] = { full = true, play = false }
end
end
fullVisibility[v] = visibility.full
playVisibility[v] = visibility.play
end end
end end
updateOverlay() updateOverlay()
end end
function getColors(color) function getIndices(color)
local playerCount = #getSeatedPlayers() local playerCount = #getSeatedPlayers()
if playerCount == 0 then if playerCount == 0 then
@ -218,25 +123,21 @@ function getColors(color)
end end
end end
function resetCameras(_, color) function resetCameras()
local colors = getColors(color) for v = 1, 4 do
cameraParams[v] = {}
for iv, v in ipairs(colors) do
if v > 0 then
for i = 1, #defaultCameraParams do for i = 1, #defaultCameraParams do
cameraParams[v][i] = {}
cameraParams[v][i].position = defaultCameraParams[i].position cameraParams[v][i].position = defaultCameraParams[i].position
cameraParams[v][i].pitch = defaultCameraParams[i].pitch cameraParams[v][i].pitch = 75
cameraParams[v][i].yaw = defaultCameraParams[i].yaw cameraParams[v][i].yaw = 90
cameraParams[v][i].distance = defaultCameraParams[i].distance cameraParams[v][i].distance = defaultCameraParams[i].distance
end end
end end
end
end end
function resizeOverlay(object, color) function resizeOverlay(object, color)
local colors = getColors(color) for _, v in ipairs(getIndices(color)) do
for _, v in ipairs(colors) do
if v > 0 then if v > 0 then
local full = fullVisibility[v] local full = fullVisibility[v]
fullVisibility[v] = not full fullVisibility[v] = not full
@ -344,7 +245,7 @@ function updateXMLbuttons(type)
id = d.id, id = d.id,
height = d.height, height = d.height,
width = d.width, width = d.width,
offsetXY = d.offsetX .. " " .. d.offsetY, offsetXY = d.offset,
color = color color = color
} }
}) })
@ -381,9 +282,7 @@ function buttonClicked(player, _, idValue)
selectedEditButton = buttonID selectedEditButton = buttonID
else else
if buttonID == selectedEditButton and editDistance > 0 then if buttonID == selectedEditButton and editDistance > 0 then
local colors = getColors(color) for _, v in ipairs(getIndices(color)) do
for _, v in ipairs(colors) do
cameraParams[v][selectedEditButton].position = editPos cameraParams[v][selectedEditButton].position = editPos
cameraParams[v][selectedEditButton].pitch = editPitch cameraParams[v][selectedEditButton].pitch = editPitch
cameraParams[v][selectedEditButton].yaw = editYaw cameraParams[v][selectedEditButton].yaw = editYaw
@ -425,33 +324,20 @@ function buttonClicked(player, _, idValue)
claiming = false claiming = false
updateOverlay() updateOverlay()
else else
loadCamera(player, _, idValue) loadCamera(player, _, buttonID)
end end
end end
function loadCamera(player, _, idValue) function loadCamera(player, _, index)
local index = tonumber(idValue)
local playerColor = player.color local playerColor = player.color
local playerIndex = getIndexForPlayerColor(playerColor) local playerIndex = getIndexForPlayerColor(playerColor)
-- only do map zooming if the camera hasn't been specially set by user -- only do map zooming if the camera hasn't been specially set by user
if index == 2 and cameraParams[playerIndex][index].distance <= 0 then if index == 2 and cameraParams[playerIndex][index].distance <= 0 then
local mapObjects = Physics.cast({ local zone = getObjectFromGUID("a2f932")
origin = { x = -29.2, y = 0, z = 0.0 }, local minX, minZ, maxX, maxZ = 100, 100, -100, -100
direction = { x = 0, y = 1, z = 0 },
type = 3,
size = { x = 36, y = 5, z = 31.4 },
orientation = { x = 0, y = 90, z = 0 }
})
local minX = 100
local maxX = -100
local minZ = 100
local maxZ = -100
for _, v in pairs(mapObjects) do
local obj = v.hit_object
for _, obj in pairs(zone.getObjects()) do
if obj.type == 'Card' or obj.type == 'Infinite' then if obj.type == 'Card' or obj.type == 'Infinite' then
local bounds = obj.getBounds() local bounds = obj.getBounds()
local x1 = bounds['center'][1] - bounds['size'][1] / 2 local x1 = bounds['center'][1] - bounds['size'][1] / 2
@ -466,51 +352,34 @@ function loadCamera(player, _, idValue)
end end
end end
if minX < 100 then
local dx = maxX - minX
local dz = (maxZ - minZ) / 1.6 -- screen ratio * 1.2 (for my macbook pro, no idea how to generalize this)
player.lookAt({ player.lookAt({
position = { (minX + maxX) / 2, 0, (minZ + maxZ) / 2 }, position = { (minX + maxX) / 2, 0, (minZ + maxZ) / 2 },
pitch = 74, pitch = 75,
yaw = 90, yaw = 90,
distance = 0.96 * math.max(dx, dz) + 5 distance = 0.96 * math.max(maxX - minX, (maxZ - minZ) / 1.6) + 5
}) })
else
player.lookAt({ position = { -30.667, 0, 0 }, pitch = 74, yaw = 90, distance = 32 })
end
elseif index >= 3 and index <= 6 then elseif index >= 3 and index <= 6 then
local newMatIndex = index - 2 -- mat index 1 - 4 local newMatIndex = index - 2 -- mat index 1 - 4
local newMatColor = getPlayerColorForIndex(newMatIndex) local newMatColor = getPlayerColorForIndex(newMatIndex)
if newMatColor ~= nil then if newMatColor ~= nil and (#getSeatedPlayers() == 1 or playermatData[playerIndex].claims[newMatIndex]) then
local playerCount = #getSeatedPlayers()
if playerCount <= 1 or playermatData[playerIndex].claims[newMatIndex] then
player.changeColor(newMatColor) player.changeColor(newMatColor)
end end
end
if cameraParams[newMatIndex][index].distance <= 0 then if cameraParams[newMatIndex][index].distance <= 0 then
local divisor, minX, maxX, minZ, maxZ local divisor, minX, maxX, minZ, maxZ
for i, v in pairs(playmatApi.searchPlaymat(newMatColor)) do for _, v in pairs(playmatApi.searchPlaymat(newMatColor)) do
local bounds = v.hit_object.getBounds() local bounds = v.hit_object.getBounds()
local x1 = bounds['center'][1] - bounds['size'][1] / 2 local x1 = bounds['center'][1] - bounds['size'][1] / 2
local x2 = bounds['center'][1] + bounds['size'][1] / 2 local x2 = bounds['center'][1] + bounds['size'][1] / 2
local z1 = bounds['center'][3] - bounds['size'][3] / 2 local z1 = bounds['center'][3] - bounds['size'][3] / 2
local z2 = bounds['center'][3] + bounds['size'][3] / 2 local z2 = bounds['center'][3] + bounds['size'][3] / 2
if i == 1 then minX = math.min(x1, minX or x1)
minX = x1 maxX = math.max(x2, maxX or x2)
maxX = x2 minZ = math.min(z1, minZ or z1)
minZ = z1 maxZ = math.max(z2, maxZ or z2)
maxZ = z2
else
minX = math.min(x1, minX)
maxX = math.max(x2, maxX)
minZ = math.min(z1, minZ)
maxZ = math.max(z2, maxZ)
end
end end
-- White/Orange -- White/Orange
@ -521,14 +390,12 @@ function loadCamera(player, _, idValue)
divisor = {x = 1.6, z = 1} divisor = {x = 1.6, z = 1}
end end
local rotation = playmatApi.returnRotation()
-- need to wait if the player color changed -- need to wait if the player color changed
Wait.frames( Wait.frames(
function() player.lookAt({ function() player.lookAt({
position = { (minX + maxX) / 2, 0, (minZ + maxZ) / 2 }, position = { (minX + maxX) / 2, 0, (minZ + maxZ) / 2 },
pitch = 75.823, pitch = 75,
yaw = rotation.y + 180, yaw = playmatApi.returnRotation(newMatColor).y + 180,
distance = 0.64 * math.max((maxX - minX) / divisor.x, (maxZ - minZ) / divisor.z) + 7 distance = 0.64 * math.max((maxX - minX) / divisor.x, (maxZ - minZ) / divisor.z) + 7
}) })
end, 2) end, 2)
@ -541,9 +408,6 @@ function loadCamera(player, _, idValue)
end end
function beginSetCamera(object, color) function beginSetCamera(object, color)
if #getSeatedPlayers() == 0 then return end
if getIndexForPlayerColor(color) < 0 then return end
editing = true editing = true
updateOverlay() updateOverlay()
end end
@ -563,15 +427,11 @@ function updateEditCamera(params)
end end
function beginClaimColor() function beginClaimColor()
if #getSeatedPlayers() == 0 then return end
claiming = true claiming = true
updateOverlay() updateOverlay()
end end
function resetClaimColors() function resetClaimColors()
if #getSeatedPlayers() == 0 then return end
for i = 1, 4 do for i = 1, 4 do
for j = 1, 4 do for j = 1, 4 do
playermatData[i].claims = {} playermatData[i].claims = {}

View File

@ -46,8 +46,8 @@
onClick="onClick_toggleUi(Options)"/> onClick="onClick_toggleUi(Options)"/>
</VerticalLayout> </VerticalLayout>
<!-- Navigation Overlay button (not visibly to Grey) --> <!-- Navigation Overlay button (not visibly to Grey and Black) -->
<Panel visibility="White|Brown|Red|Orange|Yellow|Green|Teal|Blue|Purple|Pink|Black" <Panel visibility="White|Brown|Red|Orange|Yellow|Green|Teal|Blue|Purple|Pink"
color="#000000" color="#000000"
outlineSize="1 1" outlineSize="1 1"
outline="#303030" outline="#303030"