From 1206232e9887de92027819a833d884958c0e6325 Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Wed, 8 Jun 2022 18:45:15 +0200 Subject: [PATCH] Proper file structure --- README.md | 2 +- SETTINGS.lua | 25 +++++++++++ config.txt | 18 -------- init.lua | 6 ++- src/api.lua | 36 +++++++++++++-- src/{settings.lua => items.lua} | 0 src/load_config.lua | 78 --------------------------------- 7 files changed, 63 insertions(+), 102 deletions(-) create mode 100644 SETTINGS.lua delete mode 100644 config.txt rename src/{settings.lua => items.lua} (100%) delete mode 100644 src/load_config.lua diff --git a/README.md b/README.md index f3278da..abd8ba6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Easily manage your mini-games on Minetest ## Customisation -Check config.txt to change spawn point, to add more items in the hotbar or to change physics values +Check SETTINGS.lua to change spawn point, add more items in the hotbar, and more --- diff --git a/SETTINGS.lua b/SETTINGS.lua new file mode 100644 index 0000000..7e8344b --- /dev/null +++ b/SETTINGS.lua @@ -0,0 +1,25 @@ +hub_manager.settings = {} + +-- spawn point +hub_manager.settings.hub_spawn_point = vector.new(-205, 9, 204) + +-- hotbar additional items +hub_manager.settings.hotbar_items = { + "", + "", + "", + "", + "", + "", + "" +} + +-- physics whilst in the lobby +hub_manager.settings.physics = { + speed=1, + jump=1, + gravity=1, + sneak=true, + sneak_glitch=false, + new_move=true +} diff --git a/config.txt b/config.txt deleted file mode 100644 index 3f95a78..0000000 --- a/config.txt +++ /dev/null @@ -1,18 +0,0 @@ -hub_spawn_point = -3.5, 3.0, -20.5 - -# hotbar additional items. The number corresponds with the number of the slot -1= -2= -3= -4= -5= -6= -7= - -# physics overrides while in the lobby -speed=1 -jump=1 -gravity=1 -sneak=true -sneak_glitch=false -new_move=true diff --git a/init.lua b/init.lua index 9b15b4b..48e39ec 100644 --- a/init.lua +++ b/init.lua @@ -1,13 +1,15 @@ local version = "0.1.0-dev" local modpath = minetest.get_modpath("hub_manager") local srcpath = modpath .. "/src/" +hub_manager = {} + +dofile(modpath .. "/SETTINGS.lua") dofile(srcpath .. "/api.lua") dofile(srcpath .. "/chat.lua") dofile(srcpath .. "/chatcmdbuilder.lua") dofile(srcpath .. "/commands.lua") -dofile(srcpath .. "/load_config.lua") +dofile(srcpath .. "/items.lua") dofile(srcpath .. "/player_manager.lua") -dofile(srcpath .. "/settings.lua") minetest.log("action", "[HUB_MANAGER] Mod initialised, running version " .. version) diff --git a/src/api.lua b/src/api.lua index 88fb062..2596571 100644 --- a/src/api.lua +++ b/src/api.lua @@ -1,4 +1,20 @@ -hub_manager = {} +local settings = table.copy(hub_manager.settings) + + + +---------------------------------------------- +-----------------GETTERS---------------------- +---------------------------------------------- + +function hub_manager.get_hub_spawn_point() + return settings.hub_spawn_point +end + + + +function hub_manager.get_additional_items() + return settings.hotbar_items +end @@ -13,6 +29,18 @@ end + + +---------------------------------------------- +-----------------SETTERS---------------------- +---------------------------------------------- + +function hub_manager.set_hub_physics(player) + player:set_physics_override(settings.physics) +end + + + function hub_manager.set_items(player) local inv = player:get_inventory() @@ -29,8 +57,10 @@ function hub_manager.set_items(player) local additional_items = hub_manager.get_additional_items() -- eventuali oggetti aggiuntivi - for i = 1, 7 do - hotbar_items[i] = additional_items[i] + for i = 1, #additional_items do + if additional_items[i] ~= "" then + hotbar_items[i] = additional_items[i] + end end inv:set_list("main", hotbar_items) diff --git a/src/settings.lua b/src/items.lua similarity index 100% rename from src/settings.lua rename to src/items.lua diff --git a/src/load_config.lua b/src/load_config.lua deleted file mode 100644 index 75fbfd1..0000000 --- a/src/load_config.lua +++ /dev/null @@ -1,78 +0,0 @@ -local config_file = io.open(minetest.get_modpath("hub_manager") .. "/config.txt", "r") - -assert(config_file ~= nil, "CAN'T LOAD HUB_MANAGER, config.txt IS MISSING!") - -local data = string.split(config_file:read("*all"), "\n") - -local hub_spawn_point = minetest.string_to_pos(string.match(data[1], "= (.*)")) -local additional_items = {} -local physics = {} - --- oggetti -for i = 3, 9 do - additional_items[i-2] = string.match(data[i], "=(.*)") -end - --- fisica -for i = 11, 13 do - physics[string.match(data[i], "(.*)=")] = tonumber(string.match(data[i], "=(.*)")) -end - -local sneak = string.match(data[14], "=(.*)") -local sneak_glitch = string.match(data[15], "=(.*)") -local new_move = string.match(data[16], "=(.*)") - -if sneak == "true" then - physics.sneak = true -else - physics.sneak = false -end - -if sneak_glitch == "true" then - physics.sneak_glitch = true -else - physics.sneak_glitch = false -end - -if new_move == "true" then - physics.new_move = true -else - physics.new_move = false -end - -config_file:close() - - - - -function hub_manager.apply_hub_physics(player) - player:set_physics_override(physics) -end - - - ----------------------------------------------- ------------------GETTERS---------------------- ----------------------------------------------- - -function hub_manager.get_hub_spawn_point() - return hub_spawn_point -end - - - -function hub_manager.get_additional_items() - return additional_items -end - - - - - ----------------------------------------------- ------------------SETTERS---------------------- ----------------------------------------------- - -function hub_manager.set_hub_physics(player) - player:set_physics_override(physics) -end