From 735d55627e808cd410a9830ed1dec3c415405896 Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Wed, 4 Jan 2023 10:44:49 +0000 Subject: [PATCH] load BGM from the world folder + move SETTINGS in the world folder --- DOCS.md | 2 +- IGNOREME/README.md | 3 ++ SETTINGS.lua => IGNOREME/SETTINGS.lua | 2 +- IGNOREME/instructions.txt | 3 ++ README.md | 4 +-- init.lua | 4 ++- src/_load.lua | 41 +++++++++++++++++++++++++ src/editor/tools_bgm.lua | 44 +++++++++++++++++++++++++-- 8 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 IGNOREME/README.md rename SETTINGS.lua => IGNOREME/SETTINGS.lua (97%) mode change 100755 => 100644 create mode 100644 IGNOREME/instructions.txt create mode 100644 src/_load.lua diff --git a/DOCS.md b/DOCS.md index c1624ce..321cf6e 100644 --- a/DOCS.md +++ b/DOCS.md @@ -90,7 +90,7 @@ The second field, on the contrary, is a table of optional parameters: they defin * `team_properties`: ^ (it won't work if `teams` hasn't been declared) ### 1.1 Per server configuration -There are also a couple of settings that can only be set in game via `/arenas settings`. This because different servers might need different parameters. They are: +There are also a couple of settings that can only be set in game via `/arenas settings `. This because different servers might need different parameters. They are: * `hub_spawn_point`: where players will be teleported when a match _in your mod_ ends. Default is `{ x = 0, y = 20, z = 0 }`. A bit of noise is applied on the x and z axis, ranging between `-1.5` and `1.5`. * `queue_waiting_time`: the time to wait before the loading phase starts. It gets triggered when the minimum amount of players has been reached to start the queue. Default is `10` diff --git a/IGNOREME/README.md b/IGNOREME/README.md new file mode 100644 index 0000000..f9ce600 --- /dev/null +++ b/IGNOREME/README.md @@ -0,0 +1,3 @@ +**EDITING THIS FOLDER IS USELESS, EDIT THE ONE CALLED arena_lib IN THE WORLD FOLDER INSTEAD** + +The first time the world is launched with `arena_lib` on, this folder is copy-pasted into the world folder (with the sole exception of this file). The purpose of this folder is to provide all the files and the structure to customise arena_lib. diff --git a/SETTINGS.lua b/IGNOREME/SETTINGS.lua old mode 100755 new mode 100644 similarity index 97% rename from SETTINGS.lua rename to IGNOREME/SETTINGS.lua index 1bb7761..9f17041 --- a/SETTINGS.lua +++ b/IGNOREME/SETTINGS.lua @@ -4,7 +4,7 @@ arena_lib.DEFAULT_ENTRANCE = "sign" -- The physics override to apply when a player leaves a match (whether by quitting, -- winning etc). This comes in handy for hybrid servers (i.e. survival/creative -- ones featuring some minigames). If you're aiming for a full minigame server, --- ignore this parameter and let the mod hub_manager supersede it => +-- ignore this parameter and let the mod Hub supersede it => -- https://gitlab.com/zughy-friends-minetest/hub-manager arena_lib.SERVER_PHYSICS = { speed = 1, diff --git a/IGNOREME/instructions.txt b/IGNOREME/instructions.txt new file mode 100644 index 0000000..10583e3 --- /dev/null +++ b/IGNOREME/instructions.txt @@ -0,0 +1,3 @@ +DO NOT rename folders or the mod won't be able to read them. + +/BGMs is where arenas BGMs shall be put (to then be assigned through the editor specific section). diff --git a/README.md b/README.md index 741ba69..3715cc2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It comes with an arena manager and a signs system. The latter creates a bridge i 1) Install it as any other mod -2) Check [SETTINGS.lua](SETTINGS.lua) +2) Launch the world at least once with arena_lib enabled and then check `worlds/nameofyourworld/arena_lib` to customise it 3) (modders only) Dive into the [full documentation](DOCS.md) to understand how to create minigames @@ -19,7 +19,7 @@ It comes with an arena manager and a signs system. The latter creates a bridge i * (optional) [Parties](https://gitlab.com/zughy-friends-minetest/parties) by me: use it to be sure to join the same arena/team with your friends #### Add-ons -[Hub](https://gitlab.com/zughy-friends-minetest/hub-manager) by me: use it if you're aiming for a full minigame server. It can't be set as an optional dependency, since arena_lib is a hard dependency of Hub in the first place (and MT doesn't like cross dependencies) +* [Hub](https://gitlab.com/zughy-friends-minetest/hub) by me: use it if you're aiming for a full minigame server. It can't be set as an optional dependency, since arena_lib is a hard dependency of Hub in the first place (and MT doesn't like cross dependencies) ### Known conflicts * `Beds` or any other mod overriding the default respawn system diff --git a/init.lua b/init.lua index e570a79..493db88 100755 --- a/init.lua +++ b/init.lua @@ -4,9 +4,11 @@ local srcpath = modpath .. "/src" arena_lib = {} -dofile(modpath .. "/SETTINGS.lua") +dofile(srcpath .. "/_load.lua") dofile(modpath .. "/libs/chatcmdbuilder.lua") +dofile(minetest.get_worldpath() .. "/arena_lib/SETTINGS.lua") + dofile(srcpath .. "/admin_tools/entrances.lua") dofile(srcpath .. "/admin_tools/minigame_settings.lua") dofile(srcpath .. "/api/core.lua") diff --git a/src/_load.lua b/src/_load.lua new file mode 100644 index 0000000..a7a86db --- /dev/null +++ b/src/_load.lua @@ -0,0 +1,41 @@ +local function load_world_folder() + local wrld_dir = minetest.get_worldpath() .. "/arena_lib" + local bgm_dir = wrld_dir .. "/BGM" + + local content = minetest.get_dir_list(wrld_dir) + local modpath = minetest.get_modpath("arena_lib") + + if not next(content) then + local src_dir = modpath .. "/IGNOREME" + minetest.cpdir(src_dir, wrld_dir) + os.remove(wrld_dir .. "/README.md") + + --v------------------ LEGACY UPDATE, to remove in 7.0 -------------------v + local old_settings = io.open(modpath .. "/SETTINGS.lua", "r") + + if old_settings then + minetest.safe_file_write(wrld_dir .. "/SETTINGS.lua", old_settings:read("*a")) + old_settings:close() + os.remove(modpath .. "/SETTINGS.lua") + end + --^------------------ LEGACY UPDATE, to remove in 7.0 -------------------^ + + else + -- aggiungi musiche come contenuti dinamici per non appesantire il server + local function iterate_dirs(dir) + for _, f_name in pairs(minetest.get_dir_list(dir, false)) do + minetest.dynamic_add_media({filepath = dir .. "/" .. f_name}, function(name) end) + end + for _, subdir in pairs(minetest.get_dir_list(dir, true)) do + iterate_dirs(dir .. "/" .. subdir) + end + end + + -- non si possono aggiungere contenuti dinamici all'avvio del server + minetest.after(0.1, function() + iterate_dirs(bgm_dir) + end) + end +end + +load_world_folder() diff --git a/src/editor/tools_bgm.lua b/src/editor/tools_bgm.lua index e8d3dc6..dc4b989 100755 --- a/src/editor/tools_bgm.lua +++ b/src/editor/tools_bgm.lua @@ -1,6 +1,7 @@ local S = minetest.get_translator("arena_lib") local function get_bgm_formspec() end +local function get_audio_file() end local function calc_gain() end local function calc_pitch() end @@ -95,6 +96,43 @@ end +function get_audio_file(bgm_dir, name, mod, p_name) + local content = minetest.get_dir_list(bgm_dir, false) + + local function iterate_dirs(dir) + for _, f_name in pairs(minetest.get_dir_list(dir, false)) do + local file = io.open(dir .. "/" .. name .. ".ogg", "r") + if file then + io.close(file) + return true + end + end + + for _, subdir in pairs(minetest.get_dir_list(dir, true)) do + if iterate_dirs(dir .. "/" .. subdir) then + return true + end + end + end + + local exists = iterate_dirs(bgm_dir) + + --v------------------ LEGACY UPDATE, to remove in 7.0 -------------------v (insieme a 'mod' e 'p_name' come parametro) + if not exists then + local deprecated_file = io.open(minetest.get_modpath(mod) .. "/sounds/" .. name .. ".ogg", "r") + if deprecated_file then + deprecated_file:close() + minetest.chat_send_player(p_name, minetest.colorize("#e6482e", "[arena_lib] loading sounds from the minigame folder is deprecated and it'll be removed in future versions: put it into the world folder instead!")) + exists = true + end + end + --^------------------ LEGACY UPDATE, to remove in 7.0 -------------------^ + + return exists +end + + + function calc_gain(field) return minetest.explode_scrollbar_event(field).value / 100 end @@ -115,13 +153,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "arena_lib:bgm" then return end local p_name = player:get_player_name() + local bgm_dir = minetest.get_worldpath() .. "/arena_lib/BGM/" -- se premo su icona "riproduci", riproduco audio if fields.play then - local mod = player:get_meta():get_string("arena_lib_editor.mod") - if not io.open(minetest.get_modpath(mod) .. "/sounds/" .. fields.bgm .. ".ogg", "r") then + if not get_audio_file(bgm_dir, fields.bgm, mod, p_name) then minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] This audio track doesn't exist!"))) return end @@ -154,7 +192,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.bgm == "" then arena_lib.set_bgm(p_name, mod, arena_name, nil, nil, nil, nil, nil, true) -- se non esiste il file audio, annullo - elseif not io.open(minetest.get_modpath(mod) .. "/sounds/" .. fields.bgm .. ".ogg", "r") then + elseif not get_audio_file(bgm_dir, fields.bgm, mod, p_name) then minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] This audio track doesn't exist!"))) return -- sennĂ² applico la traccia indicata