add leaderboard

This commit is contained in:
MisterE123 2021-03-11 16:57:11 -05:00
parent f0984828e5
commit 8e507f453a
4 changed files with 19 additions and 26 deletions

View File

@ -1,6 +1,9 @@
wormball = {}
wormball.HUD = {}
dofile(minetest.get_modpath("wormball") .. "/globals.lua")
wormball.storage = minetest.get_mod_storage()
wormball.arenas = {}
arena_lib.register_minigame("wormball", {
prefix = "[Wormball] ",
@ -33,6 +36,8 @@ dofile(minetest.get_modpath("wormball") .. "/globals.lua")
min_food_factor = 2,
min_food = 20,
singleplayer_leaderboard = {},
multi_scores = {},
-- highscores = {
-- {'pl_name_placeholder',0},
-- {'pl_name_placeholder',0},
@ -48,11 +53,12 @@ dofile(minetest.get_modpath("wormball") .. "/globals.lua")
-- },
},
temp_properties = {
mode = 'singleplayer',
dots = {},
num_players = 0,
time_to_next_elim = 60,
multi_scores = {},
},
initial_time = 300,

View File

@ -1,5 +1,5 @@
-- scoreboards
local storage = minetest.get_mod_storage()
local storage = wormball.storage
wormball.show_multi_scores = function( arena , player , scores )
@ -49,7 +49,7 @@ wormball.show_singleplayer_leaderboard = function( arena_name , playername )
if not arena_lib.get_arena_by_name('wormball', arena_name ) then return false end
local arena_id, arena = arena_lib.get_arena_by_name('wormball', arena_name )
local leaderboard = arena.singleplayer_leaderboard
--minetest.chat_send_all(dump(arena))
--minetest.chat_send_all(dump(arena.singleplayer_leaderboard))
local player_list = ""
if not leaderboard or not leaderboard[1] then return end
@ -201,16 +201,11 @@ arena_lib.on_celebration('wormball', function(arena, winner_name)
--arena_lib.change_arena_property('wormball' , 'wormball' , arena.name , "singleplayer_leaderboard" , leaderboard )
--save (update) the highscore data to disk
local wormball_highscores = storage:get_string("wormball_highscores") or {}
if wormball_highscores ~= {} then
wormball_highscores = minetest.deserialize(wormball_highscores)
end
arena.singleplayer_leaderboard = leaderboard
wormball_highscores [ arena.name ] = arena.singleplayer_leaderboard
local serial = minetest.serialize(arena.singleplayer_leaderboard)
local serial = minetest.serialize(wormball_highscores)
storage:set_string("wormball_highscores", serial)
storage:set_string(arena.name .. "_highscores", serial )

View File

@ -1,4 +1,5 @@
local storage = minetest.get_mod_storage()
local storage = wormball.storage
local function send_message(arena,num_str)
arena_lib.HUD_send_msg_all("title", arena, "Game Begins In "..num_str, 1,nil,0xFF0000)
-- ref: arena_lib.HUD_send_msg_all(HUD_type, arena, msg, <duration>, <sound>, <color>)
@ -8,18 +9,9 @@ arena_lib.on_load("wormball", function(arena)
-- load the saved highscore data from disk
local wormball_highscores = storage:get_string("wormball_highscores") or {}
local wormball_highscores = storage:get_string(arena.name .. "_highscores")
local leaderboard = {}
if wormball_highscores ~= {} then
wormball_highscores = minetest.deserialize(wormball_highscores)
local leaderboard = wormball_highscores [ arena.name ]
if not leaderboard then
leaderboard = {}
end
end
if wormball_highscores then leaderboard = minetest.deserialize( wormball_highscores ) end
arena.singleplayer_leaderboard = leaderboard

View File

@ -8,7 +8,7 @@ arena_lib.on_time_tick('wormball', function(arena)
----------------------------------------------
----------------------------------------------
local string = ""
if arena.mode == 'singleplayer' then
if arena.mode == 'singleplayer' and arena.singleplayer_leaderboard and arena.singleplayer_leaderboard [1] then
local leader = arena.singleplayer_leaderboard[1]
if leader then
string = "highscore: ".. leader[1] .. "\n"