Clean indentation

This commit is contained in:
Carl Philipp Klemm 2025-07-17 00:10:23 +02:00
parent fd7a38f407
commit 2426302dd8

126
main.lua
View file

@ -10,21 +10,21 @@ end
-- App -- App
hands = {"hand/right","hand/left"} hands = {"hand/right","hand/left"}
limbs = { limbs = {
"head", "head",
"hand/left", "hand/left",
"hand/right", "hand/right",
"hand/left/grip", "hand/left/grip",
"hand/right/grip", "hand/right/grip",
"elbow/left", "elbow/left",
"elbow/right", "elbow/right",
"shoulder/left", "shoulder/left",
"shoulder/right", "shoulder/right",
"chest", "chest",
"waist", "waist",
"knee/left", "knee/left",
"knee/right", "knee/right",
"foot/left", "foot/left",
"foot/right" "foot/right"
} }
configDirs = {} configDirs = {}
@ -98,9 +98,9 @@ function getClosestDistanceToPerimeter(x, y, z, points)
end end
function getButton(method,button,devices) function getButton(method,button,devices)
for _,device in ipairs(devices) do for _,device in ipairs(devices) do
if method(device,button) == true then return device end if method(device,button) == true then return device end
end end
end end
function drawSinglePointGrid(pass, point1, point2, cornerColor, miscColor) function drawSinglePointGrid(pass, point1, point2, cornerColor, miscColor)
@ -181,34 +181,34 @@ function lovr.load()
} }
-- Helper function to read file with fallback to default -- Helper function to read file with fallback to default
local function loadSetting(filename, default, parser) local function loadSetting(filename, default, parser)
print("Checking file:", filename) print("Checking file:", filename)
if not lovr.filesystem.isFile(filename) then if not lovr.filesystem.isFile(filename) then
print("File doesn't exist, creating:", filename) print("File doesn't exist, creating:", filename)
local valueToSave local valueToSave
if type(default) == "table" then if type(default) == "table" then
valueToSave = json.encode(default) valueToSave = json.encode(default)
else else
valueToSave = tostring(default) valueToSave = tostring(default)
end end
local success = lovr.filesystem.write(filename, valueToSave) local success = lovr.filesystem.write(filename, valueToSave)
print("Write success:", success, "for", filename, "with value:", valueToSave) print("Write success:", success, "for", filename, "with value:", valueToSave)
return default return default
end end
-- File exists, try to read it -- File exists, try to read it
local content = lovr.filesystem.read(filename) local content = lovr.filesystem.read(filename)
if content and parser then if content and parser then
local success, value = pcall(parser, content) local success, value = pcall(parser, content)
if success then return value end if success then return value end
elseif content then elseif content then
return content return content
end end
return default return default
end end
-- Initialize settings with fallbacks -- Initialize settings with fallbacks
settings = { settings = {
@ -304,37 +304,37 @@ function modeConfigure(pass)
end end
end end
local inputDev = getButton(lovr.headset.wasReleased,settings.action_button,hands) local inputDev = getButton(lovr.headset.wasReleased,settings.action_button,hands)
if inputDev ~= nil and lovr.headset.isTracked(inputDev) then if inputDev ~= nil and lovr.headset.isTracked(inputDev) then
local cx, _, cz = lovr.headset.getPosition(inputDev) local cx, _, cz = lovr.headset.getPosition(inputDev)
table.insert(settings.points,{cx,cz}) table.insert(settings.points,{cx,cz})
end end
inputDev = getButton(lovr.headset.isDown,settings.action_button,hands) inputDev = getButton(lovr.headset.isDown,settings.action_button,hands)
if inputDev ~= nil then if inputDev ~= nil then
saveProg = saveProg - (deltaTime / 3) saveProg = saveProg - (deltaTime / 3)
if saveProg <= 0 then if saveProg <= 0 then
local floorSpacePoints = {} local floorSpacePoints = {}
for _,point in ipairs(settings.points) do for _,point in ipairs(settings.points) do
local floorSpacePoint = lovr.math.vec3(point[1], 0, point[2]):transform(floorMatrixInv) local floorSpacePoint = lovr.math.vec3(point[1], 0, point[2]):transform(floorMatrixInv)
local x, _, z = floorSpacePoint:unpack() local x, _, z = floorSpacePoint:unpack()
table.insert(floorSpacePoints,{x,z}) table.insert(floorSpacePoints,{x,z})
end end
lovr.filesystem.write("points.json", json.encode(floorSpacePoints)) lovr.filesystem.write("points.json", json.encode(floorSpacePoints))
deinitConfigure() deinitConfigure()
modeDraw(pass) modeDraw(pass)
return return
end end
else else
saveProg = 1.0 saveProg = 1.0
end end
pass:setColor(1,0,0,0.5) pass:setColor(1,0,0,0.5)
for _,point in ipairs(settings.points) do for _,point in ipairs(settings.points) do
pass:sphere(point[1],1.5,point[2],0.1) pass:sphere(point[1],1.5,point[2],0.1)
end end
modeDraw(pass) modeDraw(pass)
end end
function modeDraw(pass) function modeDraw(pass)