Skip to content

Commit

Permalink
option to restart from current level, closes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
cornernote committed Aug 16, 2015
1 parent 7842ea9 commit cda3509
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
14 changes: 10 additions & 4 deletions skyblock_levels/register_misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ minetest.register_on_dieplayer(function(player)
local player_name = player:get_player_name()
-- empty inventory
skyblock.levels.empty_inventory(player)
-- reset feats
skyblock.feats.reset(player_name)
-- init level1
skyblock.levels[1].init(player_name)

-- back to beginning
if skyblock.levels.restart_on_die then
skyblock.feats.reset(player_name)
else
skyblock.feats.reset_level(player_name)
end

-- back to start of this level

end)

-- player receive fields
Expand Down
13 changes: 13 additions & 0 deletions skyblock_levels/skyblock.feats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ end
function skyblock.feats.set_level(player_name, level)
if skyblock.levels[level] then
skyblock.feats.set(0, player_name, 'level', level)
players_feat[player_name][level] = {}
skyblock.levels[level].init(player_name)
skyblock.feats.update(player_name)
return true
end
end
Expand All @@ -38,6 +40,17 @@ function skyblock.feats.reset(player_name)
players_feat[player_name] = {}
skyblock.feats.save(players_feat[player_name], player_name)
skyblock.feats.update(player_name)
skyblock.levels[1].init(player_name)
end

-- reset level
function skyblock.feats.reset_level(player_name)
skyblock.log('skyblock.feats.reset_level('..player_name..')')
local level = skyblock.feats.get_level(player_name)
players_feat[player_name][level] = {}
skyblock.feats.save(players_feat[player_name], player_name)
skyblock.feats.update(player_name)
skyblock.levels[level].init(player_name)
end

-- update feats
Expand Down
8 changes: 8 additions & 0 deletions skyblock_levels/skyblock.levels.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ License: GPLv3

skyblock.levels = {}

--
-- CONFIG OPTIONS
--

-- true to restart from level1, false to restart from current level
skyblock.levels.restart_on_die = minetest.setting_getbool('skyblock.levels.restart_on_die')


--
-- Functions
--
Expand Down

0 comments on commit cda3509

Please sign in to comment.