Skip to content

Commit

Permalink
invert super_sam -> highscore dep cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 18, 2023
1 parent d135e52 commit eca5ef3
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion mods/super_sam/.luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ read_globals = {

-- mods
"player_api", "worldedit",
"super_sam_highscore", "mtt", "controls", "unified_inventory"
"mtt", "controls", "unified_inventory"
}
1 change: 0 additions & 1 deletion mods/super_sam/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 12 additions & 4 deletions mods/super_sam/intro.lua
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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", {
Expand Down
2 changes: 1 addition & 1 deletion mods/super_sam/mod.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = super_sam
depends = player_api, super_sam_highscore, controls
depends = player_api, controls
optional_depends = worldedit, mtt, unified_inventory
13 changes: 13 additions & 0 deletions mods/super_sam/score.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion mods/super_sam_highscore/.luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ read_globals = {
-- Minetest
"minetest", "vector", "ItemStack",
"dump", "dump2",
"VoxelArea", "AreaStore"
"VoxelArea", "AreaStore",

-- deps
"super_sam"
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
13 changes: 0 additions & 13 deletions mods/super_sam_highscore/format.lua

This file was deleted.

2 changes: 1 addition & 1 deletion mods/super_sam_highscore/highscore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mods/super_sam_highscore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
5 changes: 5 additions & 0 deletions mods/super_sam_highscore/intro.lua
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions mods/super_sam_highscore/mod.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
name = super_sam_highscore
depends = super_sam
2 changes: 1 addition & 1 deletion mods/super_sam_hud/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eca5ef3

Please sign in to comment.