From ebde4407511a7255e1e5b6d897f81188c4fe2eb3 Mon Sep 17 00:00:00 2001 From: Fernando Carmona Varo Date: Sat, 24 Oct 2015 22:31:23 +0200 Subject: Some refactoring and organization, added api.lua --- myhighscore/scoreboard.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 myhighscore/scoreboard.lua (limited to 'myhighscore/scoreboard.lua') diff --git a/myhighscore/scoreboard.lua b/myhighscore/scoreboard.lua new file mode 100755 index 0000000..226e86a --- /dev/null +++ b/myhighscore/scoreboard.lua @@ -0,0 +1,64 @@ + + + + +local button_form = "size[6,8;]".. + "background[0,0;6,8;myhighscore_form_bg.png]".. + "label[1,0.5;HIGH SCORES]".. + "button[1,1;4,1;game;label]".. + "button_exit[4,7;1,2;exit;Exit]" + +--place holders +local game_name = "the game" +local game_player_name = "the player" +local game_player_score = "648138" + +local game_form = "size[6,8;]".. + "background[0,0;6,8;myhighscore_form_bg.png]".. + "label[1,0.5;HIGH SCORES FOR "..game_name.."]".. + "label[1,1.5;PLAYER]".. + "label[3.5,1.5;SCORE]".. + "label[0.5,2;"..game_player_name.."]".. + "label[3,2;"..game_player_score.."]".. + "button[2,7;1,2;back;Back]".. + "button_exit[4,7;1,2;exit;Exit]" + +minetest.register_node("myhighscore:score_board", { + description = "Score Board", + tiles = { + "myhighscore_top.png", + "myhighscore_back.png", + "myhighscore_side.png^[transformFX", + "myhighscore_side.png",y + "myhighscore_back.png", + "myhighscore_front.png", + }, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky = 1}, + node_box = { + type = "fixed", + fixed = { + {-0.375, -0.5, -0.5, 0.375, -0.1875, 0.5}, + {-0.375, -0.5, 0.1875, 0.375, 0.5, 0.5}, + {-0.1875, -0.5, -0.3125, -0.125, 0, -0.25}, + {-0.375, -0.5, 0, -0.3125, 0.5, 0.5}, + {0.3125, -0.5, 0, 0.375, 0.5, 0.5}, + {-0.375, 0.4375, 0, 0.375, 0.5, 0.5}, + } + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("formspec", button_form) + meta:set_string("infotext", "High Scores") + end, + on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.env:get_meta(pos) + if fields['game'] then + meta:set_string('formspec', game_form) + elseif fields["back"] then + meta:set_string('formspec', button_form) + end + end, +}) -- cgit v1.2.3 From 289cacf17a5812c5fb6cfc7134dedabfea0d86e7 Mon Sep 17 00:00:00 2001 From: Fernando Carmona Varo Date: Sun, 25 Oct 2015 02:51:44 +0200 Subject: Implemented myhighscores API, and used it in pacmine --- myhighscore/scoreboard.lua | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'myhighscore/scoreboard.lua') diff --git a/myhighscore/scoreboard.lua b/myhighscore/scoreboard.lua index 226e86a..38e659e 100755 --- a/myhighscore/scoreboard.lua +++ b/myhighscore/scoreboard.lua @@ -13,15 +13,26 @@ local game_name = "the game" local game_player_name = "the player" local game_player_score = "648138" -local game_form = "size[6,8;]".. - "background[0,0;6,8;myhighscore_form_bg.png]".. - "label[1,0.5;HIGH SCORES FOR "..game_name.."]".. - "label[1,1.5;PLAYER]".. - "label[3.5,1.5;SCORE]".. - "label[0.5,2;"..game_player_name.."]".. - "label[3,2;"..game_player_score.."]".. - "button[2,7;1,2;back;Back]".. - "button_exit[4,7;1,2;exit;Exit]" +local function get_formspec_for_game(name) + local def = myhighscore.registered_games[name] + local scores = myhighscore.scores[name] or {} + -- Obtain a comma separated list of scores to display + local scorelist = "" + for _,score in pairs(scores) do + scorelist = scorelist .. minetest.formspec_escape(score.player) .. + "\t\t\t\t " .. score.score .."," + end + + return "size[6,8;]".. + "background[0,0;6,8;myhighscore_form_bg.png]".. + "label[1,0.5;HIGH SCORES FOR "..def.description.."]".. + "label[1,1.5;PLAYER]".. + "label[3.5,1.5;SCORE]".. + "textlist[0.5,2;5,5;;"..scorelist.."]".. + "button[2,7;1,2;back;Back]".. + "button_exit[4,7;1,2;exit;Exit]" +end + minetest.register_node("myhighscore:score_board", { description = "Score Board", @@ -29,7 +40,7 @@ minetest.register_node("myhighscore:score_board", { "myhighscore_top.png", "myhighscore_back.png", "myhighscore_side.png^[transformFX", - "myhighscore_side.png",y + "myhighscore_side.png", "myhighscore_back.png", "myhighscore_front.png", }, @@ -56,7 +67,7 @@ minetest.register_node("myhighscore:score_board", { on_receive_fields = function(pos, formname, fields, sender) local meta = minetest.env:get_meta(pos) if fields['game'] then - meta:set_string('formspec', game_form) + meta:set_string('formspec', get_formspec_for_game("pacmine")) elseif fields["back"] then meta:set_string('formspec', button_form) end -- cgit v1.2.3