Skip to content

Commit e0288b6

Browse files
committed
Merge branch 'master' into color-revert
2 parents ff351d2 + d612fcd commit e0288b6

9 files changed

+178
-37
lines changed

animation.lua

+13
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ instantkillplayer[:player] kills player(s)
7979
disablejumping disable jumping
8080
enablejumping enables jumping
8181
82+
autosave saves mappack progress
8283
changebackground:background changes background
8384
changeforeground:background changes foreground
8485
removecoins:amount removes coins
@@ -755,6 +756,18 @@ function animation:update(dt)
755756
objects["player"][i].speedy = tonumber(sy) or 0
756757
end
757758
end
759+
elseif v[1] == "autosave" then
760+
-- only save if the game is being played offline
761+
if not (CLIENT or SERVER or dcplaying) then
762+
-- don't save if the game is being played in the editor
763+
if not testlevel then
764+
writesuspendfile()
765+
end
766+
-- show notice regardless of whether player is in editor or not, to prove the function works while testing
767+
if v[2] == true then
768+
notice.new(TEXT["game saved!"], notice.white, 3)
769+
end
770+
end
758771
elseif v[1] == "changebackground" then
759772
if v[2] then
760773
loadcustombackground(v[2])

animationguiline.lua

+22
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,22 @@ table.insert(toenter, {name = "changebackground",
13901390
}
13911391
})
13921392

1393+
table.insert(toenter, {name = "autosave",
1394+
t = {
1395+
t="action",
1396+
nicename="save game progress",
1397+
entries={
1398+
{
1399+
t="text",
1400+
value=" and "
1401+
},
1402+
{
1403+
t="notifyplayer"
1404+
}
1405+
}
1406+
}
1407+
})
1408+
13931409
table.insert(toenter, {name = "changeforeground",
13941410
t = {
13951411
t="action",
@@ -2144,6 +2160,12 @@ function animationguiline:init(tabl, t2)
21442160
dropwidth = 6
21452161
args = {"both","none","1 only","2 only","gel"}
21462162
displayargs = {"both","none","1 only","2 only","gel"}
2163+
2164+
elseif v.t == "notifyplayer" then
2165+
dropdown = true
2166+
dropwidth = 24
2167+
args = {true, false}
2168+
displayargs = {"notify the player", "don't notify the player"}
21472169
end
21482170

21492171
if dropdown then

game.lua

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local queuespritebatchupdate = false
22

3-
function game_load(suspended)
3+
function game_load(suspended, deletesuspend)
44
scrollfactor = 0
55
scrollfactory = 0
66
scrollfactor2 = 0
@@ -48,6 +48,7 @@ function game_load(suspended)
4848
continuesublevelmusic = false
4949
nolowtime = false
5050
nocoinlimit = false
51+
alwaysdeletesuspend = false
5152
setphysics(1)
5253
if not dcplaying then
5354
loadmappacksettings()
@@ -97,6 +98,11 @@ function game_load(suspended)
9798
marioworld = suspended
9899
end
99100

101+
if deletesuspend or alwaysdeletesuspend then
102+
-- On starting a new game, remove the old save
103+
love.filesystem.remove(savesfolder .. "/" .. mappack .. ".suspend")
104+
end
105+
100106
--remove custom sprites
101107
for i = smbtilecount+portaltilecount+1, #tilequads do
102108
tilequads[i] = nil
@@ -2862,13 +2868,10 @@ function game_draw()
28622868
love.graphics.setColor(255, 255, 255, 255)
28632869
properprint(">", (width*8*scale)-45*scale, (112*scale)-60*scale+(i-1)*25*scale)
28642870
end
2865-
if dcplaying and pausemenuoptions[i] == "suspend" then --restart instead of suspend
2871+
if dcplaying and pausemenuoptions[i] == "save game" then --restart instead of suspend
28662872
properprintF(TEXT["restart"], (width*8*scale)-35*scale, (112*scale)-60*scale+(i-1)*25*scale)
2867-
elseif (collectablescount[1] > 0 or collectablescount[2] > 0 or collectablescount[3] > 0 or collectablescount[4] > 0 or
2868-
collectablescount[5] > 0 or collectablescount[6] > 0 or collectablescount[7] > 0 or collectablescount[8] > 0 or
2869-
collectablescount[9] > 0 or collectablescount[10] > 0)
2870-
and pausemenuoptions[i] == "suspend" then --make it more obvious that you can save your progress
2871-
properprintF(TEXT["save game"], (width*8*scale)-35*scale, (112*scale)-60*scale+(i-1)*25*scale)
2873+
elseif alwaysdeletesuspend and pausemenuoptions[i] == "save game" then
2874+
properprintF(TEXT["suspend"], (width*8*scale)-35*scale, (112*scale)-60*scale+(i-1)*25*scale)
28722875
else
28732876
properprintF(TEXT[pausemenuoptions[i]], (width*8*scale)-35*scale, (112*scale)-60*scale+(i-1)*25*scale)
28742877
end
@@ -2929,14 +2932,12 @@ function game_draw()
29292932
love.graphics.rectangle("fill", (width*8*scale)-100*scale, (112*scale)-25*scale, 200*scale, 50*scale)
29302933
love.graphics.setColor(255, 255, 255, 255)
29312934
drawrectangle((width*8)-99, 112-24, 198, 48)
2932-
if (collectablescount[1] > 0 or collectablescount[2] > 0 or collectablescount[3] > 0 or collectablescount[4] > 0 or
2933-
collectablescount[5] > 0 or collectablescount[6] > 0 or collectablescount[7] > 0 or collectablescount[8] > 0 or
2934-
collectablescount[9] > 0 or collectablescount[10] > 0) then --make it more obvious that you can save your progress
2935-
properprintF(TEXT["save game? this will"], (width*8*scale)-utf8.len(TEXT["save game? this will"])*4*scale, (112*scale)-20*scale)
2936-
properprintF(TEXT["overwrite last save."], (width*8*scale)-utf8.len(TEXT["overwrite last save."])*4*scale, (112*scale)-10*scale)
2937-
else
2935+
if alwaysdeletesuspend then
29382936
properprintF(TEXT["suspend game? this can"], (width*8*scale)-utf8.len(TEXT["suspend game? this can"])*4*scale, (112*scale)-20*scale)
29392937
properprintF(TEXT["only be loaded once!"], (width*8*scale)-utf8.len(TEXT["only be loaded once!"])*4*scale, (112*scale)-10*scale)
2938+
else
2939+
properprintF(TEXT["save game? this will"], (width*8*scale)-utf8.len(TEXT["save game? this will"])*4*scale, (112*scale)-20*scale)
2940+
properprintF(TEXT["overwrite last save."], (width*8*scale)-utf8.len(TEXT["overwrite last save."])*4*scale, (112*scale)-10*scale)
29402941
end
29412942
if pausemenuselected2 == 1 then
29422943
properprintF(">", (width*8*scale)-51*scale, (112*scale)+4*scale)
@@ -5060,7 +5061,7 @@ function game_keypressed(key, textinput)
50605061
else
50615062
playmusic()
50625063
end
5063-
elseif pausemenuoptions[pausemenuselected] == "suspend" then
5064+
elseif pausemenuoptions[pausemenuselected] == "save game" then
50645065
if dcplaying then
50655066
pausemenuopen = false
50665067
updatesizes("reset")

gui.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ function guielement:keypress(key,textinput)
991991
if not (textinput and textinput == "forcetextinput") then
992992
local justchanged = false
993993
if not doubleinput then
994-
if doubleinputcheck and doubleinputcheck == key then
994+
if doubleinputcheck and key and doubleinputcheck:lower() == key:lower() then
995995
doubleinput = true
996996
justchanged = true
997997
end

languages/english.json

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"level editor": "level editor",
66
"select mappack": "select mappack",
77
"options": "options",
8+
"starting a new game will": "starting a new game will",
9+
"delete your existing save!": "delete your existing save!",
10+
"new game": "new game",
11+
"go back": "go back",
812
"select world": "select world",
913

1014
"^_Settings":"",
@@ -342,4 +346,5 @@
342346

343347
"^_Notices":"",
344348
"Map saved!": "Map saved!",
349+
"game saved!": "game saved!",
345350
}

main.lua

+28-9
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,11 @@ function love.load()
445445
soundenabled = true
446446
end
447447
love.filesystem.createDirectory("mappacks")
448+
love.filesystem.createDirectory("saves")
448449

449450
love.filesystem.createDirectory("alesans_entities")
450451
love.filesystem.createDirectory("alesans_entities/mappacks")
452+
love.filesystem.createDirectory("alesans_entities/saves")
451453
love.filesystem.createDirectory("alesans_entities/onlinemappacks")
452454
love.filesystem.createDirectory("alesans_entities/characters")
453455
love.filesystem.createDirectory("alesans_entities/hats")
@@ -477,6 +479,10 @@ function love.load()
477479
saveconfig()
478480
end
479481

482+
if love.filesystem.getInfo("suspend") then
483+
convertoldsuspendfile()
484+
end
485+
480486
loadingbardraw(1)
481487

482488
--check date for daily challenges
@@ -1601,6 +1607,7 @@ function loadconfig(nodefaultconfig)
16011607
end
16021608
elseif s2[1] == "modmappacks" then
16031609
mappackfolder = "alesans_entities/mappacks"
1610+
savesfolder = "alesans_entities/saves"
16041611
elseif s2[1] == "resizable" then
16051612
if s2[2] then
16061613
resizable = (s2[2] == "true")
@@ -1732,13 +1739,14 @@ function defaultconfig()
17321739
mappack = "smb"
17331740
vsync = false
17341741
mappackfolder = "mappacks"
1742+
savesfolder = "saves"
17351743
fourbythree = false
17361744
localnick = false
17371745

17381746
reachedworlds = {}
17391747
end
17401748

1741-
function suspendgame()
1749+
function writesuspendfile()
17421750
local st = {}
17431751
if marioworld == "M" then
17441752
marioworld = 8
@@ -1788,18 +1796,22 @@ function suspendgame()
17881796
st.mappackfolder = mappackfolder
17891797

17901798
local s = JSON:encode_pretty(st)
1791-
love.filesystem.write("suspend", s)
1792-
1799+
love.filesystem.write(savesfolder .. "/" .. mappack .. ".suspend", s)
1800+
end
1801+
1802+
function suspendgame()
1803+
writesuspendfile()
17931804
love.audio.stop()
17941805
menu_load()
17951806
end
17961807

17971808
function continuegame()
1798-
if not love.filesystem.getInfo("suspend") then
1809+
savefile = savesfolder .. "/" .. mappack .. ".suspend"
1810+
if not love.filesystem.getInfo(savefile) then
17991811
return
18001812
end
18011813

1802-
local s = love.filesystem.read("suspend")
1814+
local s = love.filesystem.read(savefile)
18031815
local st = JSON:decode(s)
18041816

18051817
mariosizes = {}
@@ -1836,10 +1848,6 @@ function continuegame()
18361848
end
18371849
mappack = st.mappack
18381850
mappackfolder = st.mappackfolder
1839-
1840-
if (not st.collectables) then --save the game if collectables are involved
1841-
love.filesystem.remove("suspend")
1842-
end
18431851

18441852
loadbackground("1-1.txt")
18451853

@@ -3110,6 +3118,17 @@ function disablecheats()
31103118
darkmode = false
31113119
end
31123120

3121+
function convertoldsuspendfile()
3122+
local s = love.filesystem.read("suspend")
3123+
local st = JSON:decode(s)
3124+
3125+
-- *ahem* sus. [crowd cheering]
3126+
local suspendedmappackfolder = st.mappackfolder
3127+
local suspendedmappack = st.mappack
3128+
love.filesystem.write(suspendedmappackfolder:gsub("mappacks", "saves") .. "/" .. suspendedmappack .. ".suspend", s)
3129+
love.filesystem.remove("suspend")
3130+
end
3131+
31133132
--sausage (don't ask)
31143133
function dothesausage(i)
31153134
if i then

mappack.lua

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function loadmappacksettings(suspended)
2626
continuesublevelmusic = true
2727
elseif s2[1] == "nolowtime" then
2828
nolowtime = true
29+
elseif s2[1] == "usesuspends" then
30+
alwaysdeletesuspend = true
2931
elseif s2[1] == "character" then
3032
for i = 1, players do
3133
setcustomplayer(s2[2], i)

0 commit comments

Comments
 (0)