Skip to content

Commit

Permalink
lots of save stuff - now saves level tree & last selected levels
Browse files Browse the repository at this point in the history
  • Loading branch information
lilybeevee committed Oct 10, 2019
1 parent cee608a commit 305c6ab
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 84 deletions.
7 changes: 3 additions & 4 deletions editor/loadscene.lua
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,9 @@ function scene.buildUI()
local oy = 4
if world ~= "" then
if load_mode == "play" and love.filesystem.getInfo(world_parent .. "/" .. world .. "/" .. "overworld.txt") then
local overworld_file_name = love.filesystem.read(world_parent .. "/" .. world .. "/" .. "overworld.txt")
if love.filesystem.getInfo(world_parent .. "/" .. world .. "/" .. overworld_file_name .. ".bab") then
loadLevels({overworld_file_name}, "play")
end
local overworld = love.filesystem.read(world_parent .. "/" .. world .. "/" .. "overworld.txt")
loadWorld(overworld)
playing_world = true
end

local title_y = oy
Expand Down
20 changes: 20 additions & 0 deletions game/movement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ function doMovement(movex, movey, key)
next_levels, next_level_objs = getNextLevels()

if movex == 0 and movey == 0 and #next_levels > 0 then
local going_up = false
if #level_tree > 0 then
if type(level_tree[1]) == "table" then
going_up = eq(level_tree[1], next_levels)
elseif #next_levels == 1 then
going_up = level_tree[1] == next_levels[1]
end
end
if not going_up then
table.insert(level_tree, 1, getMapEntry())
else
table.remove(level_tree, 1)
end
if playing_world then
if #next_levels == 1 then
writeSaveFile(next_levels[1], {"levels", level_name, "selected"})
else
writeSaveFile(next_levels, {"levels", level_name, "selected"})
end
end
loadLevels(next_levels, nil, next_level_objs)
return
end
Expand Down
91 changes: 50 additions & 41 deletions game/scene.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ function scene.resetStuff(forTime)
next_levels, next_level_objs = getNextLevels()
first_turn = false
window_dir = 0


if playing_world then
saveWorld()
selectLastLevels()
end
end

function scene.keyPressed(key, isrepeat)
Expand Down Expand Up @@ -863,7 +867,7 @@ function scene.draw(dt)
local sprite

if type(sprite_name) ~= "table" then
if sprite_name == "lvl" and readSaveFile(unit.special.level, "won") then
if sprite_name == "lvl" and readSaveFile{"levels", unit.special.level, "won"} then
sprite_name = "lvl_won"
end
local frame = (unit.frame + anim_stage) % 3 + 1
Expand Down Expand Up @@ -1151,7 +1155,7 @@ function scene.draw(dt)

if unit.name == "lvl" and unit.special.visibility == "open" then
love.graphics.push()
if readSaveFile(unit.special.level, "won") then
if readSaveFile{"levels", unit.special.level, "won"} then
local r,g,b,a = love.graphics.getColor()
love.graphics.setColor(r,g,b, a*0.4)
end
Expand Down Expand Up @@ -1923,19 +1927,19 @@ function scene.draw(dt)
if pause then

local current_level = level_name
if readSaveFile(level_name, "won") then
if readSaveFile{"levels", level_name, "won"} then
current_level = current_level.." (won) "
end
if readSaveFile(level_name, "clear") then
if readSaveFile{"levels", level_name, "clear"} then
current_level = current_level.." (cleared) "
end
if readSaveFile(level_name, "complete") then
if readSaveFile{"levels", level_name, "complete"} then
current_level = current_level.." (complete) "
end
if readSaveFile(level_name, "bonus") then
if readSaveFile{"levels", level_name, "bonus"} then
current_level = current_level.." (bonused) "
end
local tfs = readSaveFile(level_name, "transform")
local tfs = readSaveFile{"levels", level_name, "transform"}
if tfs then
local tfstr = ""
for _,tf in ipairs(tfs) do
Expand Down Expand Up @@ -2153,57 +2157,62 @@ function scene.checkInput()
end

function escResult(do_actual, xwx)
if (was_using_editor) then
if (do_actual) then
if was_using_editor then
if do_actual then
load_mode = "edit"
new_scene = editor
else
return "the editor"
end
else
if (win_reason == "nxt" and level_next_level ~= nil and level_next_level ~= "") then
if (do_actual) then
-- i dont know what this is :owoXD:
if win_reason == "nxt" and level_next_level ~= nil and level_next_level ~= "" then
if do_actual then
loadLevels({level_next_level}, "play", nil, xwx)
return
else
return level_next_level
end
elseif (level_parent_level == nil or level_parent_level == "") then
if (parent_filename ~= nil and parent_filename ~= "") then
if (do_actual) then
loadLevels(parent_filename:split("|"), "play", nil, xwx)
else
return parent_filename
end
else
if (do_actual) then
load_mode = "play"
new_scene = loadscene
if (love.filesystem.getInfo(world_parent .. "/" .. world .. "/" .. "overworld.txt")) then
world = ""
elseif #level_tree > 0 then
local parent = level_tree[1]
local seen = true
if type(parent) == "table" then
for _,name in ipairs(parent) do
if not readSaveFile{"levels", name, "seen"} then
seen = false
break
end
else
return "the level selection menu"
end
end
else
if (readSaveFile(level_parent_level, "seen")) then
if (do_actual) then
loadLevels({level_parent_level}, "play", nil, xwx)
else
return level_parent_level
end
else
if (do_actual) then
load_mode = "play"
new_scene = loadscene
if (love.filesystem.getInfo(world_parent .. "/" .. world .. "/" .. "overworld.txt")) then
world = ""
seen = readSaveFile{"levels", parent, "seen"}
end
if seen then
if do_actual then
if type(parent) == "table" then
loadLevels(parent, "play", nil, xwx)
else
loadLevels({parent}, "play", nil, xwx)
end
table.remove(level_tree, 1)
return
else
return "the level selection menu"
if type(parent) == "table" then
return table.concat(parent, " & ")
else
return parent
end
end
end
end
if do_actual then
load_mode = "play"
new_scene = loadscene
if (love.filesystem.getInfo(world_parent .. "/" .. world .. "/" .. "overworld.txt")) then
world = ""
end
else
return "the level selection menu"
end
end
end

Expand Down
33 changes: 19 additions & 14 deletions game/unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ function updateUnits(undoing, big_update)
local stuff = getUnitsOnTile(unit.x, unit.y, nil, true, nil, nil, hasProperty(unit,"big"))
for _,on in ipairs(stuff) do
if hasU(on) and sameFloat(unit, on) then
writeSaveFile(level_name, "bonus", true)
writeSaveFile(true, {"levels", level_name, "bonus"})
if timecheck(unit,"be",":o") and (timecheckUs(on)) then
table.insert(to_destroy, unit)
playSound("bonus")
Expand Down Expand Up @@ -1883,7 +1883,7 @@ function levelBlock()
local lvlsafe = hasRule(outerlvl,"got","lvl") or hasProperty(outerlvl,"protecc")

if hasProperty(outerlvl,"notranform") then
writeSaveFile(level_name,"transform",nil)
writeSaveFile(nil, {"levels", level_name, "transform"})
end

if hasProperty(outerlvl, "loop") then
Expand Down Expand Up @@ -2090,7 +2090,7 @@ function levelBlock()
local yous = getUs()
for _,unit in ipairs(yous) do
if sameFloat(unit,outerlvl) and inBounds(unit.x,unit.y) then
writeSaveFile(level_name, "bonus", true)
writeSaveFile(true, {"levels", level_name, "bonus"})
destroyLevel("bonus")
if not lvlsafe then return 0,0 end
end
Expand Down Expand Up @@ -3000,7 +3000,7 @@ function deleteUnit(unit,convert,undoing,gone)
end
end

function moveUnit(unit,x,y,portal)
function moveUnit(unit,x,y,portal,instant)
--print("moving:", unit.fullname, unit.x, unit.y, "to:", x, y)
--when empty moves, swap it with the empty in its destination tile, to preserve the invariant 'there is exactly empty per tile'
--also, keep empty out of units_by_tile - it will be added in getUnitsOnTile
Expand Down Expand Up @@ -3054,7 +3054,7 @@ function moveUnit(unit,x,y,portal)
end

-- putting portal check above same-position check to give portal effect through one-tile gap
if portal and portal.is_portal and x - portal.x == dirs8[portal.dir][1] and y - portal.y == dirs8[portal.dir][2] then
if portal and portal.is_portal and x - portal.x == dirs8[portal.dir][1] and y - portal.y == dirs8[portal.dir][2] and not instant then
if unit.type == "text" or rules_effecting_names[unit.name] or rules_effecting_names[unit.fullname] then
should_parse_rules = true
end
Expand All @@ -3074,7 +3074,7 @@ function moveUnit(unit,x,y,portal)
unit.draw.rotation = (unit.rotatdir - 1) * 45
tweens["unit:dir:" .. unit.tempid] = nil
end
elseif x ~= unit.x or y ~= unit.y then
elseif (x ~= unit.x or y ~= unit.y) and not instant then
if unit.type == "text" or rules_effecting_names[unit.name] or rules_effecting_names[unit.fullname] then
should_parse_rules = true
end
Expand All @@ -3096,6 +3096,9 @@ function moveUnit(unit,x,y,portal)
end)
end
end
elseif instant then
unit.draw.x = x
unit.draw.y = y
end

unit.x = x
Expand All @@ -3111,7 +3114,9 @@ function moveUnit(unit,x,y,portal)
end
end

do_move_sound = true
if not instant then
do_move_sound = true
end
end

function updateDir(unit, dir, force)
Expand Down Expand Up @@ -3357,9 +3362,9 @@ function doWin(result_, payload_)
if doing_past_turns then
past_queued_wins[result] = payload
elseif result == "won" and payload == false then
if readSaveFile(level_name,"won") then
if readSaveFile{"levels",level_name,"won"} then
playSound("unwin")
writeSaveFile(level_name,"won",false)
writeSaveFile(false, {"levels",level_name,"won"})
end
else
won_this_session = true
Expand All @@ -3369,7 +3374,7 @@ function doWin(result_, payload_)
win_size = 0
playSound("win")
if (not replay_playback) then
writeSaveFile(level_name, result, payload)
writeSaveFile(payload, {"levels", level_name, result})
love.filesystem.createDirectory("levels")
local to_save = replay_string
local rng_cache_populated = false
Expand All @@ -3388,10 +3393,10 @@ function doWin(result_, payload_)
end

function doXWX()
writeSaveFile(level_name,"seen",nil)
writeSaveFile(level_name,"won",nil)
writeSaveFile(level_name,"bonus",nil)
writeSaveFile(level_name,"transform",nil)
writeSaveFile(nil,{"levels",level_name,"seen"})
writeSaveFile(nil,{"levels",level_name,"won"})
writeSaveFile(nil,{"levels",level_name,"bonus"})
writeSaveFile(nil,{"levels",level_name,"transform"})
escResult(true, true)
end

Expand Down
10 changes: 10 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ bab arguments!
print(colr.green("✓ discord rpc initialized"))
end

if not love.filesystem.getInfo("profiles") then
love.filesystem.createDirectory("profiles")
print(colr.green("✓ created profiles directory"))
end

if not love.filesystem.getInfo("profiles/" .. profile.name) then
love.filesystem.createDirectory("profiles/" .. profile.name)
print(colr.green("✓ created '"..profile.name.."' profile directory"))
end

if is_mobile then
love.window.setMode(640, 360)
end
Expand Down
2 changes: 1 addition & 1 deletion officialworlds/bab be u/overworld.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
prison
bab be u,mapp
1 change: 0 additions & 1 deletion ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ end

function ui.textInput(text)
if ui.editing then
print("inputtt " ..text)
ui.editing:textInput(text)
return true
end
Expand Down
Loading

0 comments on commit 305c6ab

Please sign in to comment.