Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More readable options.txt #399

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 49 additions & 97 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1224,137 +1224,87 @@ function lovedraw()
end

function saveconfig()
local s = ""
--local baf = love.timer.getTime()
local fstring = string.rep("playercontrols:%s:right-%s,use-%s,aimy-%s,pause-%s,up-%s,run-%s,left-%s,aimx-%s,reload-%s,portal2-%s,portal1-%s,down-%s,jump-%s;\n", 4)
local ctable = {}
for i = 1, #controls do
s = s .. "playercontrols:" .. i .. ":"
local count = 0
table.insert(ctable, i)
for j, k in pairs(controls[i]) do
local c = ""
for l = 1, #controls[i][j] do
c = c .. controls[i][j][l]
if l ~= #controls[i][j] then
c = c .. "-"
end
end
s = s .. j .. "-" .. c
count = count + 1
s = s .. ","
table.insert(ctable, table.concat(k,"-"))
end
s = s:sub(1,-2) .. ";"
end

if mariocharacter then
s = s .. "mariocharacter:"
for i = 1, 4 do
if mariocharacter[i] then
s = s .. mariocharacter[i] .. ","
else
s = s .. "mario,"
end
end
s = s .. ";"
end

local s = string.format(fstring, unpack(ctable))

local s = string.format("%smariocharacter:%s;\n", s, table.concat(mariocharacter,","))

ctable = {}
fstring = "%s"
for i = 1, #mariocolors do
s = s .. "playercolors:" .. i .. ":"
fstring = string.format("%splayercolors:%s:%s;\n", fstring, i, string.rep("%s",#mariocolors[i],","))
for j = 1, #mariocolors[i] do
for k = 1, 3 do
s = s .. round(mariocolors[i][j][k] * 255)
if j == #mariocolors[i] and k == 3 then
s = s .. ";"
else
s = s .. ","
end
end
end
end

for i = 1, #portalhues do
s = s .. "portalhues:" .. i .. ":"
s = s .. round(portalhues[i][1], 4) .. "," .. round(portalhues[i][2], 4) .. ";"
end

for i = 1, #mariohats do
s = s .. "mariohats:" .. i
if #mariohats[i] > 0 then
s = s .. ":"
end
for j = 1, #mariohats[i] do
s = s .. mariohats[i][j]
if j == #mariohats[i] then
s = s .. ";"
else
s = s .. ","
local color = ""
for k = 1, #mariocolors[i][j] do
color = color .. tostring(round(mariocolors[i][j][k] * 255))
end
end

if #mariohats[i] == 0 then
s = s .. ";"
table.insert(ctable, color:sub(1, -2))
end
end
s = string.format(fstring, s, unpack(ctable))

local p = portalhues
fstring = "%sportalhues:1:%.2f,%.2f;\nportalhues:2:%.2f,%.2f;\nportalhues:3:%.2f,%.2f;\nportalhues:4:%.2f,%.2f;\n"
s = string.format(fstring, s, p[1][1],p[1][2], p[2][1],p[2][2], p[3][1],p[3][2], p[4][1],p[4][2])

fstring = "%smariohats:1:%s;\nmariohats:2:%s;\nmariohats:3:%s;\nmariohats:4:%s;\n"
s = string.format(fstring, s, table.concat(mariohats[1],","), table.concat(mariohats[2],","), table.concat(mariohats[3],","), table.concat(mariohats[4],","))

if resizable then
s = s .. "scale:2;"
s = s .. "scale:2;\n"
else
s = s .. "scale:" .. scale .. ";"
s = string.format("%sscale:%s;\n", s, scale)
end

s = s .. "letterbox:" .. tostring(letterboxfullscreen) .. ";"

s = s .. "shader1:" .. shaderlist[currentshaderi1] .. ";"
s = s .. "shader2:" .. shaderlist[currentshaderi2] .. ";"

s = s .. "volume:" .. volume .. ";"
s = s .. "mouseowner:" .. mouseowner .. ";"
s = s .. "letterbox:" .. tostring(letterboxfullscreen) .. ";\n"

s = string.format("%sshader1:%s;\nshader2:%s;\nvolume:%s;\nmouseowner:%s;\n", s, shaderlist[currentshaderi1], shaderlist[currentshaderi2], volume, mouseowner)

if mappackfolder == "alesans_entities/mappacks" then
s = s .. "modmappacks;"
s = s .. "modmappacks;\n"
end
s = s .. "mappack:" .. mappack .. ";"

s = string.format("%smappack:%s;\n", s, mappack)

if vsync then
s = s .. "vsync;"
s = s .. "vsync;\n"
end

if gamefinished then
s = s .. "gamefinished;"
s = s .. "gamefinished;\n"
end

--reached worlds
local tempstring = ""
fstring = "%sreachedworlds:%s:%s;\n"
for i, v in pairs(reachedworlds) do
s = s .. "reachedworlds:" .. i .. ":"

local n = math.max(8, #reachedworlds[i])

for j = 1, n do
if v[j] then
s = s .. 1
else
s = s .. 0
end

if j == n then
s = s .. ";"
else
s = s .. ","
end
end
local t = string.gsub(string.gsub(string.gsub(string.format(string.rep("%s",#v,","),unpack(v)), "true", "1"), "false", "0"), "nil", "0")
tempstring = string.format(fstring, tempstring, i, t)
end

s = s .. "resizable:" .. tostring(resizable) .. ";"
s = s .. tempstring

s = string.format("%sresizable:%s;\n", s, tostring(resizable))
if CurrentLanguage then
s = s .. "language:" .. CurrentLanguage .. ";"
s = string.format("%slanguage:%s;\n", s, CurrentLanguage)
end

if fourbythree then
s = s .. "fourbythree;"
s = s .. "fourbythree;\n"
end

if localnick then
s = s .. "localnick:" .. localnick .. ";"
s = string.format("%slocalnick:%s;\n", s, localnick)
end
love.filesystem.write("alesans_entities/options.txt", s)
--print("Config saved in " .. love.timer.getTime()-baf)
end

function loadconfig(nodefaultconfig)
Expand All @@ -1363,16 +1313,18 @@ function loadconfig(nodefaultconfig)
defaultconfig()
end

local s
local s, s1, s2, s3, s4
if love.filesystem.getInfo("alesans_entities/options.txt") then
s = love.filesystem.read("alesans_entities/options.txt")
elseif love.filesystem.getInfo("options.txt") then
s = love.filesystem.read("options.txt")
else
return
end


s = s:gsub(";\n", ";")
s1 = s:split(";")

for i = 1, #s1-1 do
s2 = s1[i]:split(":")

Expand Down