From eca5ef38e9935d1d89cf3dea8dd967fcad839992 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Wed, 18 Oct 2023 11:12:15 +0200 Subject: [PATCH] invert super_sam -> highscore dep cycle --- mods/super_sam/.luacheckrc | 2 +- mods/super_sam/init.lua | 1 - mods/super_sam/intro.lua | 16 ++++++++++++---- mods/super_sam/mod.conf | 2 +- mods/super_sam/score.lua | 13 +++++++++++++ mods/super_sam_highscore/.luacheckrc | 5 ++++- .../board.lua} | 2 +- mods/super_sam_highscore/format.lua | 13 ------------- mods/super_sam_highscore/highscore.lua | 2 +- mods/super_sam_highscore/init.lua | 2 +- mods/super_sam_highscore/intro.lua | 5 +++++ mods/super_sam_highscore/mod.conf | 1 + mods/super_sam_hud/init.lua | 2 +- 13 files changed, 41 insertions(+), 25 deletions(-) rename mods/{super_sam/highscore.lua => super_sam_highscore/board.lua} (86%) delete mode 100644 mods/super_sam_highscore/format.lua create mode 100644 mods/super_sam_highscore/intro.lua diff --git a/mods/super_sam/.luacheckrc b/mods/super_sam/.luacheckrc index af4c30d..6095b18 100644 --- a/mods/super_sam/.luacheckrc +++ b/mods/super_sam/.luacheckrc @@ -19,5 +19,5 @@ read_globals = { -- mods "player_api", "worldedit", - "super_sam_highscore", "mtt", "controls", "unified_inventory" + "mtt", "controls", "unified_inventory" } diff --git a/mods/super_sam/init.lua b/mods/super_sam/init.lua index 38f4735..a17ac47 100644 --- a/mods/super_sam/init.lua +++ b/mods/super_sam/init.lua @@ -41,7 +41,6 @@ dofile(MP .. "/shoot.lua") -- nodes, items, etc dofile(MP .. "/items.lua") dofile(MP .. "/tools.lua") -dofile(MP .. "/highscore.lua") if minetest.get_modpath("mtt") then dofile(MP .. "/mtt.lua") diff --git a/mods/super_sam/intro.lua b/mods/super_sam/intro.lua index ed90054..f6e54ed 100644 --- a/mods/super_sam/intro.lua +++ b/mods/super_sam/intro.lua @@ -1,6 +1,11 @@ +local intro_formspec_handlers = {} + +function super_sam.add_intro_formspec_handler(fn) + table.insert(intro_formspec_handlers, fn) +end function super_sam.show_intro(playername) - minetest.show_formspec(playername, "intro", [[ + local fs = [[ size[12,13;] label[0,0.1;Super sam intro (get here again with the /intro command)] button_exit[10,0;2,1;start;Start] @@ -16,10 +21,13 @@ function super_sam.show_intro(playername) label[6.6,5;Speed increase] image[10,3;2,2;super_sam_items.png^[sheet:6x5:2,2] label[10,5;Higher jumps] + ]] + + for _, fn in ipairs(intro_formspec_handlers) do + fs = fn(fs) + end - label[0,6.1;Current highscore top 5 (also available with /highscore)] - ]] .. super_sam_highscore.get_highscore_formspec_fragment("total", 0, 7, 11.7, 6, 5) .. [[ - ]]) + minetest.show_formspec(playername, "intro", fs) end minetest.register_chatcommand("intro", { diff --git a/mods/super_sam/mod.conf b/mods/super_sam/mod.conf index afaa727..cbb06da 100644 --- a/mods/super_sam/mod.conf +++ b/mods/super_sam/mod.conf @@ -1,3 +1,3 @@ name = super_sam -depends = player_api, super_sam_highscore, controls +depends = player_api, controls optional_depends = worldedit, mtt, unified_inventory \ No newline at end of file diff --git a/mods/super_sam/score.lua b/mods/super_sam/score.lua index 4c2cef7..4575b86 100644 --- a/mods/super_sam/score.lua +++ b/mods/super_sam/score.lua @@ -12,3 +12,16 @@ end function super_sam.add_score(name, score) super_sam.set_score(name, super_sam.get_score(name) + score) end + +-- http://lua-users.org/lists/lua-l/2006-01/msg00525.html +local function format_thousand(v) + local s = string.format("%d", math.floor(v)) + local pos = string.len(s) % 3 + if pos == 0 then pos = 3 end + return string.sub(s, 1, pos) + .. string.gsub(string.sub(s, pos+1), "(...)", "'%1") +end + +function super_sam.format_score(score) + return "$ " .. format_thousand(score) +end diff --git a/mods/super_sam_highscore/.luacheckrc b/mods/super_sam_highscore/.luacheckrc index 1cadaf9..98585c8 100644 --- a/mods/super_sam_highscore/.luacheckrc +++ b/mods/super_sam_highscore/.luacheckrc @@ -10,5 +10,8 @@ read_globals = { -- Minetest "minetest", "vector", "ItemStack", "dump", "dump2", - "VoxelArea", "AreaStore" + "VoxelArea", "AreaStore", + + -- deps + "super_sam" } diff --git a/mods/super_sam/highscore.lua b/mods/super_sam_highscore/board.lua similarity index 86% rename from mods/super_sam/highscore.lua rename to mods/super_sam_highscore/board.lua index 8d84a63..6efc549 100644 --- a/mods/super_sam/highscore.lua +++ b/mods/super_sam_highscore/board.lua @@ -1,7 +1,7 @@ local coin_texture = "super_sam_items.png^[sheet:6x5:4,3" -super_sam_highscore.register_node("super_sam:highscore", { +super_sam_highscore.register_node(":super_sam:highscore", { description = "Highscore board", inventory_image = coin_texture, wield_image = coin_texture, diff --git a/mods/super_sam_highscore/format.lua b/mods/super_sam_highscore/format.lua deleted file mode 100644 index 1427336..0000000 --- a/mods/super_sam_highscore/format.lua +++ /dev/null @@ -1,13 +0,0 @@ - --- http://lua-users.org/lists/lua-l/2006-01/msg00525.html -local function format_thousand(v) - local s = string.format("%d", math.floor(v)) - local pos = string.len(s) % 3 - if pos == 0 then pos = 3 end - return string.sub(s, 1, pos) - .. string.gsub(string.sub(s, pos+1), "(...)", "'%1") -end - -function super_sam_highscore.format_score(score) - return "$ " .. format_thousand(score) -end diff --git a/mods/super_sam_highscore/highscore.lua b/mods/super_sam_highscore/highscore.lua index 1509de8..0bcaacd 100644 --- a/mods/super_sam_highscore/highscore.lua +++ b/mods/super_sam_highscore/highscore.lua @@ -82,7 +82,7 @@ function super_sam_highscore.get_highscore_formspec_fragment(levelname, x, y, si -- bronze color = "#CD7F32" end - list = list .. color .. "," .. super_sam_highscore.format_score(entry.score) .. "," .. + list = list .. color .. "," .. super_sam.format_score(entry.score) .. "," .. entry.name .. "," .. os.date('%Y-%m-%d %H:%M:%S', entry.timestamp) .. "," if i > entries then diff --git a/mods/super_sam_highscore/init.lua b/mods/super_sam_highscore/init.lua index d5e226d..bff202f 100644 --- a/mods/super_sam_highscore/init.lua +++ b/mods/super_sam_highscore/init.lua @@ -4,6 +4,6 @@ super_sam_highscore = { local MP = minetest.get_modpath(minetest.get_current_modname()) -dofile(MP .. "/format.lua") dofile(MP .. "/highscore.lua") dofile(MP .. "/node.lua") +dofile(MP .. "/board.lua") diff --git a/mods/super_sam_highscore/intro.lua b/mods/super_sam_highscore/intro.lua new file mode 100644 index 0000000..48640b2 --- /dev/null +++ b/mods/super_sam_highscore/intro.lua @@ -0,0 +1,5 @@ + +super_sam.add_intro_formspec_handler(function(fs) + return fs .. [[label[0,6.1;Current highscore top 5 (also available with /highscore)] + ]] .. super_sam_highscore.get_highscore_formspec_fragment("total", 0, 7, 11.7, 6, 5) +end) \ No newline at end of file diff --git a/mods/super_sam_highscore/mod.conf b/mods/super_sam_highscore/mod.conf index 06bb5a4..b0b9b0a 100644 --- a/mods/super_sam_highscore/mod.conf +++ b/mods/super_sam_highscore/mod.conf @@ -1 +1,2 @@ name = super_sam_highscore +depends = super_sam \ No newline at end of file diff --git a/mods/super_sam_hud/init.lua b/mods/super_sam_hud/init.lua index 3ae336f..a8bb2a3 100644 --- a/mods/super_sam_hud/init.lua +++ b/mods/super_sam_hud/init.lua @@ -187,7 +187,7 @@ function super_sam_hud.update_player_hud(player) player:hud_change(data.health_text, "text", "x" .. hp) end if data.score_text then - player:hud_change(data.score_text, "text", super_sam_highscore.format_score(super_sam.get_score(playername))) + player:hud_change(data.score_text, "text", super_sam.format_score(super_sam.get_score(playername))) end if data.level_text then local level = super_sam_level.get_current_level(player)