Background music per arena

master
Zughy 2020-12-01 21:30:27 +00:00
parent 729cb61156
commit 691edf8a41
12 changed files with 267 additions and 6 deletions

View File

@ -14,6 +14,7 @@
* [1.2.2.4 Arena properties](#1224-arena-properties)
* [1.2.2.5 Spawners](#1225-spawners)
* [1.2.2.6 Signs](#1226-signs)
* [1.2.2.7 Music](#1227-music)
* [1.2.3 Enabling an arena](#123-enabling-an-arena)
* [1.3 Arena phases](#13-arena-phases)
* [2. Minigame configuration](#2-minigame-configuration)
@ -54,6 +55,7 @@ An arena is a table having as a key an ID and as a value its parameters. They ar
* `min_players`: (string) default is 2. When this value is reached, a queue starts
* `initial_time`: (int) in seconds. It's `nil` when the mod doesn't keep track of time, it's 0 when the mod does it incrementally and it's inherited by the mod if the mod has a timer. In this case, every arena can have its specific value. By default time tracking is disabled, hence it's `nil`
* `current_time`: (int) in seconds. It requires `initial_time` and it exists only when a game is in progress, keeping track of the current time
* `bgm`: (table) contains the information about the audio track to play while in game
* `in_queue`: (bool) about phases, look at "Arena phases" down below
* `in_loading`: (bool)
* `in_game`: (bool)
@ -155,6 +157,9 @@ ChatCmdBuilder.new("NAMEOFYOURCOMMAND", function(cmd)
##### 1.2.2.6 Signs
`arena_lib.set_sign(sender, <pos, remove>, <mod, arena_name>)` via chat uses `sender`, `mod` and `arena_name`, while the editor `pos` and `remove` (hence the weird subdivision). When used via chat, it takes the block the player is pointing at in a 5 blocks radius. If the block is a sign, it then creates (or remove if already set) the "arena sign".
##### 1.2.2.7 Music
`arena_lib.set_bgm(sender, mod, arena_name, track, volume, pitch)` sets the background music of the arena. The audio file (`track`) must be inside the `sounds` folder of the minigame mod (NOT arena_lib's), and `.ogg` shall be omitted from the string
#### 1.2.3 Enabling an arena
When a sign has been set, it won't work. This because an arena must be enabled manually via
`arena_lib.enable_arena(sender, mod, arena_name)` or by using the Enable and Leave button in the editor.

View File

@ -78,6 +78,27 @@ minetest.register_tool("arena_lib:editor_signs", {
minetest.register_tool("arena_lib:editor_bgm", {
description = S("BGM"),
inventory_image = "arenalib_editor_bgm.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user)
arena_lib.HUD_send_msg("hotbar", user:get_player_name(), S("Background music"))
minetest.after(0, function()
arena_lib.give_bgm_tools(user)
end)
end
})
minetest.register_tool("arena_lib:editor_settings", {
description = S("Settings"),

View File

@ -6,9 +6,9 @@ local editor_tools = {
"arena_lib:editor_players",
"arena_lib:editor_spawners",
"arena_lib:editor_signs",
"arena_lib:editor_bgm",
"arena_lib:editor_settings",
"",
"",
"arena_lib:editor_info",
"arena_lib:editor_enable",
"arena_lib:editor_quit"

172
_editor/tools_bgm.lua Normal file
View File

@ -0,0 +1,172 @@
local S = minetest.get_translator("arena_lib")
local function get_bgm_formspec() end
local function calc_gain() end
local function calc_pitch() end
local audio_currently_playing = {} -- KEY p_name; VALUE sound handle
local bgm_tools = {
"arena_lib:bgm_set",
"",
"",
"",
"",
"",
"",
"arena_lib:editor_return",
"arena_lib:editor_quit",
}
minetest.register_tool("arena_lib:bgm_set", {
description = S("Set BGM"),
inventory_image = "arenalib_editor_bgm.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
local mod = user:get_meta():get_string("arena_lib_editor.mod")
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
minetest.show_formspec(user:get_player_name(), "arena_lib:bgm", get_bgm_formspec(arena))
end
})
function arena_lib.give_bgm_tools(player)
player:get_inventory():set_list("main", bgm_tools)
end
----------------------------------------------
---------------FUNZIONI LOCALI----------------
----------------------------------------------
function get_bgm_formspec(arena)
local arena_bgm = ""
local arena_volume = 100
local arena_pitch = 50
if arena.bgm then
arena_bgm = arena.bgm.track
arena_volume = arena.bgm.gain * 100
arena_pitch = arena.bgm.pitch * 50
end
local formspec = {
"formspec_version[4]",
"size[7,7]",
"bgcolor[;neither]",
"style_type[image_button;border=false;bgimg=blank.png]",
"label[0.5,0.5;" .. S("Audio file") .. "]",
"field[0.5,0.8;6,0.6;bgm;;" .. arena_bgm .. "]",
"label[0.5,2.2;" .. S("Volume") .. "]",
"label[0.22,2.61;0]",
"label[6.55,2.61;100]",
"scrollbaroptions[max=100;smallstep=1;largestep=10;arrows=hide]",
"scrollbar[0.5,2.5;6,0.2;;gain;" .. arena_volume .. "]",
"label[0.5,3.2;" .. S("Pitch") .. "]",
"label[0.22,3.61;0]",
"label[6.68,3.61;2]",
"scrollbar[0.5,3.5;6,0.2;;pitch;" .. arena_pitch .. "]",
"container[3.05,4.3]",
"image_button[0,0;0.4,0.4;arenalib_tool_bgm_test.png;play;]",
"image_button[0.5,0;0.4,0.4;arenalib_tool_bgm_test_stop.png;stop;]",
"container_end[]",
"button[2.75,6.2;1.5,0.5;apply;Apply]",
"field_close_on_enter[bgm;false]",
"field_close_on_enter[gain;false]",
"field_close_on_enter[pitch;false]"
}
return table.concat(formspec, "")
end
function calc_gain(field)
return minetest.explode_scrollbar_event(field).value / 100
end
function calc_pitch(field)
return minetest.explode_scrollbar_event(field).value / 50
end
----------------------------------------------
---------------GESTIONE CAMPI-----------------
----------------------------------------------
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()
-- 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
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] This audio track doesn't exist!")))
return end
if audio_currently_playing[p_name] then
minetest.sound_stop(audio_currently_playing[p_name])
end
audio_currently_playing[p_name] = minetest.sound_play(fields.bgm, {
to_player = p_name,
gain = calc_gain(fields.gain),
pitch = calc_pitch(fields.pitch),
loop = true
})
-- se abbandono o premo stop, l'eventuale audio si interrompe
elseif fields.stop or fields.quit then
if audio_currently_playing[p_name] then
minetest.sound_stop(audio_currently_playing[p_name])
audio_currently_playing[p_name] = nil
end
-- applico il tutto
elseif fields.apply then
local mod = player:get_meta():get_string("arena_lib_editor.mod")
local arena_name = player:get_meta():get_string("arena_lib_editor.arena")
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
-- se il campo è vuoto, rimuovo la musica di sottofondo
if fields.bgm == "" then
arena_lib.set_bgm(p_name, mod, arena_name, nil, _, _ , true)
-- se non esiste il file audio, annullo
elseif not io.open(minetest.get_modpath(mod) .. "/sounds/" .. fields.bgm .. ".ogg", "r") then
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] This audio track doesn't exist!")))
return
-- sennò applico la traccia indicata
else
arena_lib.set_bgm(p_name, mod, arena_name, fields.bgm, calc_gain(fields.gain), calc_pitch(fields.pitch), true)
end
if audio_currently_playing[p_name] then
minetest.sound_stop(audio_currently_playing[p_name])
audio_currently_playing[p_name] = nil
end
minetest.close_formspec(p_name, "arena_lib:bgm")
end
end)

45
api.lua
View File

@ -24,7 +24,7 @@ local function time_start() end
local players_in_game = {} -- KEY: player name, VALUE: {(string) minigame, (int) arenaID}
local players_in_queue = {} -- KEY: player name, VALUE: {(string) minigame, (int) arenaID}
local players_temp_storage = {} -- KEY: player_name, VALUE: {(int) hotbar_slots, (string) hotbar_background_image, (string) hotbar_selected_image}
local players_temp_storage = {} -- KEY: player_name, VALUE: {(int) hotbar_slots, (string) hotbar_background_image, (string) hotbar_selected_image, (int) bgm_handle}
local arena_default = {
name = "",
@ -38,6 +38,7 @@ local arena_default = {
spawn_points = {}, -- KEY: ids, VALUE: {pos, teamID}
max_players = 4,
min_players = 2,
bgm = nil,
initial_time = nil,
current_time = nil,
in_queue = false,
@ -801,6 +802,30 @@ end
function arena_lib.set_bgm(sender, mod, arena_name, track, volume, pitch, in_editor)
local arena_ID, arena = arena_lib.get_arena_by_name(mod, arena_name)
if not in_editor then
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
end
if bgm == nil then
arena.bgm = nil
else
arena.bgm = {
track = track,
gain = volume,
pitch = pitch
}
end
update_storage(false, mod, arena_ID, arena)
minetest.chat_send_player(sender, arena_lib.mods[mod].prefix .. S("Background music of arena @1 successfully overwritten", arena.name))
end
function arena_lib.set_timer(sender, mod, arena_name, timer, in_editor)
local arena_ID, arena = arena_lib.get_arena_by_name(mod, arena_name)
@ -1902,6 +1927,18 @@ end
function operations_before_entering_arena(mod_ref, mod, arena, arena_ID, p_name)
players_temp_storage[p_name] = {}
-- applico eventuale musica di sottofondo
if arena.bgm then
players_temp_storage[p_name].bgm_handle = minetest.sound_play(arena.bgm.track, {
gain = arena.bgm.gain,
pitch = arena.bgm.pitch,
to_player = p_name,
loop = true,
})
end
local player = minetest.get_player_by_name(p_name)
-- nascondo i nomi se l'opzione è abilitata
@ -1924,7 +1961,6 @@ function operations_before_entering_arena(mod_ref, mod, arena, arena_ID, p_name)
-- cambio l'eventuale hotbar
if mod_ref.hotbar then
players_temp_storage[p_name] = {}
local hotbar = mod_ref.hotbar
if hotbar.slots then
@ -2023,6 +2059,11 @@ function operations_before_leaving_arena(mod_ref, arena, p_name)
-- riattivo la minimappa eventualmente disattivata
player:hud_set_flags({minimap = true})
-- disattivo eventuale musica di sottofondo
if arena.bgm then
minetest.sound_stop(players_temp_storage[p_name].bgm_handle)
end
-- svuoto lo storage temporaneo
players_temp_storage[p_name] = nil
end

View File

@ -14,6 +14,7 @@ dofile(modpath .. "/utils.lua")
dofile(modpath .. "/_dependencies/parties.lua")
dofile(modpath .. "/_editor/editor_main.lua")
dofile(modpath .. "/_editor/editor_icons.lua")
dofile(modpath .. "/_editor/tools_bgm.lua")
dofile(modpath .. "/_editor/tools_players.lua")
dofile(modpath .. "/_editor/tools_settings.lua")
dofile(modpath .. "/_editor/tools_sign.lua")

View File

@ -1,6 +1,6 @@
# version 4.2.0-dev
# version 4.3.0-dev
# author(s): Joaquín Villalba (Dragonop)
# reviewer(s):
# reviewer(s): Zughy
# textdomain: arena_lib
# api.lua
@ -34,6 +34,7 @@ Sign of arena @1 successfully removed=Cartel de la arena @1 eliminado correctame
[!] There is already a sign for this arena!=[!] ¡Ya existe un cartel para este arena!
[!] There is no sign to remove assigned to @1!=[!] ¡No hay un cartel para eliminar asignado a @1!
Sign of arena @1 successfully set=Cartel de arena @1 establecido correctamente
Background music of arena @1 successfully overwritten=Música de fondo de arena @1 sobrescrita con éxito
[!] Timers are not enabled in this mod!=[!] ¡Los temporizadores no están habilitados en este mod!
Arena @1's timer is now @2 seconds=El temporizador de la arena @1 es ahora @2 segundos
[!] Insufficient spawners, the arena can't be enabled!=[!] ¡Spawners insuficientes, la arena no puede ser habilitada!
@ -165,6 +166,12 @@ Go back=Regresar
Enable and leave=Habilitar y salir
Leave the editor=Salir del editor
# _editor/tools_bgm.lua
Audio file=Archivo de audio
Volume=Volumen
Pitch=Tono
[!] This audio track doesn't exist!=[!] ¡Esta pista de audio no existe!
# _editor/tools_players.lua
Change the current number=Cambiar el número actual
Teams: on (click to toggle off)=Equipos: activados (click para desactivar)

View File

@ -34,6 +34,7 @@ Sign of arena @1 successfully removed=Cartello dell'arena @1 rimosso con success
[!] There is already a sign for this arena!=[!] Esiste già un cartello per quest'arena!
[!] There is no sign to remove assigned to @1!=[!] Non c'è nessun cartello da rimuovere assegnato a @1!
Sign of arena @1 successfully set=Cartello dell'arena @1 impostato con successo
Background music of arena @1 successfully overwritten=Musica di sottofondo dell'arena @1 sovrascritta con successo
[!] Timers are not enabled in this mod!=[!] I timer non sono abilitati in questa mod!
Arena @1's timer is now @2 seconds=Il timer dell'arena @1 è ora @2 secondi
[!] Insufficient spawners, the arena can't be enabled!=[!] Spawner insufficienti, l'arena non può essere abilitata!
@ -165,6 +166,12 @@ Go back=Torna indietro
Enable and leave=Abilita ed esci
Leave the editor=Esci dall'editor
# _editor/tools_bgm.lua
Audio file=File audio
Volume=Volume
Pitch=Tono
[!] This audio track doesn't exist!=[!] Questa traccia audio non esiste!
# _editor/tools_players.lua
Change the current number=Cambia il numero attuale
Teams: on (click to toggle off)=Squadre: attive (premi per disattivare)

View File

@ -1,4 +1,4 @@
# version 4.2.0-dev
# version 4.3.0-dev
# author(s):
# reviewer(s):
# textdomain: arena_lib
@ -34,6 +34,7 @@ Sign of arena @1 successfully removed=
[!] There is already a sign for this arena!=
[!] There is no sign to remove assigned to @1!=
Sign of arena @1 successfully set=
Background music of arena @1 successfully overwritten=
[!] Timers are not enabled in this mod!=
Arena @1's timer is now @2 seconds=
[!] Insufficient spawners, the arena can't be enabled!=
@ -165,6 +166,12 @@ Go back=
Enable and leave=
Leave the editor=
# _editor/tools_bgm.lua
Audio file=
Volume=
Pitch=
[!] This audio track doesn't exist!=
# _editor/tools_players.lua
Change the current number=
Teams: on (click to toggle off)=

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B