BGM: added title and author attributes

master
marco_a 2021-01-18 21:32:28 +01:00
parent 1f6999fd5b
commit 6165e39535
3 changed files with 55 additions and 29 deletions

10
DOCS.md
View File

@ -268,7 +268,13 @@ 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. Audio tracks must be placed in the minigame `/sounds` path (not arena_lib's) in order to be found. Default is `nil`
* `bgm`: (table) contains the information about the audio track to play while in game. Audio tracks must be placed in the minigame `/sounds` path (not arena_lib's) in order to be found. Default is `nil`.
In-depth fields, all empty by default, are:
* `track`: (string) the audio file, without `.ogg`. Mandatory. If no track is specified, all the other fields will be consequently empty
* `title`: (string) the title to display in the infobox (right-clicking a sign)
* `author`: (string) the author to display in the infobox (right-clicking a sign)
* `gain`: (int) the volume of the track
* `pitch`: (int) the pitch of the track
* `in_queue`: (bool) about phases, look at "Arena phases" down below
* `in_loading`: (bool)
* `in_game`: (bool)
@ -369,7 +375,7 @@ ChatCmdBuilder.new("NAMEOFYOURCOMMAND", function(cmd)
`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".
##### 2.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. If `track` is nil, `arena.bgm` will be set to `nil` too
`arena_lib.set_bgm(sender, mod, arena_name, track, title, author, 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. If `track` is nil, `arena.bgm` will be set to `nil` too
#### 2.2.3 Enabling an arena
When a sign has been set, it won't work. This because an arena must be enabled manually via

View File

@ -54,39 +54,55 @@ end
function get_bgm_formspec(arena)
local arena_bgm = ""
local arena_volume = 100
local arena_pitch = 50
local bgm = ""
local bgm_title = ""
local bgm_author = ""
local bgm_volume = 100
local bgm_pitch = 50
if arena.bgm then
arena_bgm = arena.bgm.track
arena_volume = arena.bgm.gain * 100
arena_pitch = arena.bgm.pitch * 50
bgm = arena.bgm.track
bgm_title = arena.bgm.title or ""
bgm_author = arena.bgm.author or ""
bgm_volume = arena.bgm.gain * 100
bgm_pitch = arena.bgm.pitch * 50
end
local formspec = {
"formspec_version[4]",
"size[7,7]",
"size[7,7.5]",
"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 .. "]",
--"hypertext[0.5,1.5;6,2;audio_info;<style color=#cfc6b8>" .. S("leave empty to remove the current track") .. "</style>]", --TODO: waiting for 5.4 translation fix on hypertext elems
"hypertext[0.5,1.5;6,2;audio_info;<style color=#cfc6b8>(leave empty to remove the current track)</style>]",
"label[0.5,2.2;" .. S("Volume") .. "]",
"label[0.5,2.61;0]",
"label[6.14,2.61;100]",
-- area attributi
"container[0.5,0.5]",
"label[0,0;" .. S("Audio file") .. "]",
"field[0,0.41;6,0.6;bgm;;" .. bgm .. "]",
--"hypertext[-0.05,0.12;6,0.3;audio_info;<style size=13 font=mono color=#b7aca3>S("(leave empty to remove the current track)")</style>]", --TODO: waiting for 5.4 translation fix on hypertext elems
"hypertext[-0.05,0.12;6,0.3;audio_info;<style size=13 font=mono color=#b7aca3>(leave empty to remove the current track)</style>]",
"container[0,1.35]",
"label[0,0;" .. S("Title") .. "]",
"field[0,0.2;2.99,0.6;title;;" .. bgm_title .. "]",
"label[3,0;" .. S("Author") .. "]",
"field[3,0.2;3,0.6;author;;" .. bgm_author .. "]",
"container_end[]",
"container_end[]",
-- area ritocchi
"container[0.5,3.5]",
"label[0,0;" .. S("Volume") .. "]",
"label[0,0.41;0]",
"label[5.64,0.41;100]",
"scrollbaroptions[max=100;smallstep=1;largestep=10;arrows=hide]",
"scrollbar[0.9,2.5;5.2,0.2;;gain;" .. arena_volume .. "]",
"label[0.5,3.2;" .. S("Pitch") .. "]",
"label[0.5,3.61;0]",
"label[6.4,3.61;2]",
"scrollbar[0.9,3.5;5.2,0.2;;pitch;" .. arena_pitch .. "]",
"container[3.05,4.3]",
"scrollbar[0.4,0.3;5.2,0.2;;gain;" .. bgm_volume .. "]",
"label[0,1;" .. S("Pitch") .. "]",
"label[0,1.41;0]",
"label[5.9,1.41;2]",
"scrollbar[0.4,1.3;5.2,0.2;;pitch;" .. bgm_pitch .. "]",
"container[2.55,2.1]",
"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;" .. S("Apply") .."]",
"container_end[]",
"button[2.75,6.7;1.5,0.5;apply;" .. S("Apply") .."]",
"field_close_on_enter[bgm;false]",
"field_close_on_enter[gain;false]",
"field_close_on_enter[pitch;false]"
@ -154,14 +170,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- se il campo è vuoto, rimuovo la musica di sottofondo
if fields.bgm == "" then
arena_lib.set_bgm(p_name, mod, arena_name, nil, _, _ , true)
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)
local title = fields.title ~= "" and fields.title or nil
local author = fields.author ~= "" and fields.author or nil
arena_lib.set_bgm(p_name, mod, arena_name, fields.bgm, title, author, calc_gain(fields.gain), calc_pitch(fields.pitch), true)
end
if audio_currently_playing[p_name] then

10
api.lua
View File

@ -814,7 +814,7 @@ end
function arena_lib.set_bgm(sender, mod, arena_name, track, volume, pitch, in_editor)
function arena_lib.set_bgm(sender, mod, arena_name, track, title, author, volume, pitch, in_editor)
local arena_ID, arena = arena_lib.get_arena_by_name(mod, arena_name)
@ -826,9 +826,11 @@ function arena_lib.set_bgm(sender, mod, arena_name, track, volume, pitch, in_edi
arena.bgm = nil
else
arena.bgm = {
track = track,
gain = volume,
pitch = pitch
track = track,
title = title,
author = author,
gain = volume,
pitch = pitch
}
end