Add chat_settings ingredient and deprecate all the single chat ingredients (e.g. chat_all_prefix)

This commit is contained in:
marco_a 2024-02-08 18:44:15 +01:00
parent 512765b7dd
commit 5987bac9b3
4 changed files with 109 additions and 50 deletions

19
DOCS.md
View File

@ -65,13 +65,18 @@ The second field, on the contrary, is a table of optional parameters: they defin
* `teams`: (table) contains team names. If not declared, your minigame won't have teams and the table will be equal to `{-1}`. You can add as many teams as you like, as the number of spawners (and players) will be multiplied by the number of teams (so `max_players = 4` * 3 teams = 12 players in total)
* `variable_teams_amount`: (boolean) whether to support a variable amount of teams per arena. It requires `teams`. Default is `false`
* `teams_color_overlay`: (table) [color strings](https://drafts.csswg.org/css-color/#named-colors). It applies a color overlay onto the players' skin according to their team, to better distinguish them. It requires `teams`. Default is `nil`
* `is_team_chat_default`: (bool) whether players messages in a game should be sent to their teammates only. It requires `teams`, default is false
* `chat_all_prefix`: (string) prefix for every message sent in arena, team chat aside. Default is `[arena] ` (geolocalised)
* `chat_team_prefix`: (string) prefix for every message sent in the team chat. Default is `[team] ` (geolocalised)
* `chat_spectate_prefix`: (string) prefix for every message sent in the spectate chat. Default is `[spectator]` (geolocalised)
* `chat_all_color`: (string) color for every message sent in arena, team chat aside. Default is white (`"#ffffff"`)
* `chat_team_color`: (string) color for every message sent in the team chat. Default is light sky blue (`"#ddfdff"`)
* `chat_spectate_color`: color for every message sent in the spectate chat. Default is gray (`"#dddddd"`)
* `chat_settings`: (table) several chat options. Default fields are:
```lua
{
prefix_all = "[arena] " -- prefix for every global message sent in arena. Default is automatically translated
prefix_team = "[team] " -- ^ but for teams
prefix_spectate = "[spectator] " -- ^ but for spectators
color_all = "#ffffff" -- white
color_team = "#ddfdff" -- light blue
color_spectate = "#dddddd" -- gray
is_team_chat_default = false -- whether players messages should be sent to their teammates only (teams must be enabled)
}
```
* `custom_messages`: (table) series of messages to optionally customise the minigame experience. Beware:
* Default fields are:
```lua

View File

@ -7,6 +7,7 @@ local function load_settings() end
local function init_storage() end
local function update_storage() end
local function file_exists() end
local function deprecated_chat_settings() end
local function deprecated_spawner_ID_param() end
local function deprecated_sound_table_entry_exists() end
local function check_for_properties() end
@ -106,6 +107,38 @@ function arena_lib.register_minigame(mod, def)
def.hud_flags[k] = false
end
end
def.chat_settings = def.chat_settings or {}
if def.chat_all_prefix then
def.chat_settings.prefix_all = def.chat_all_prefix
minetest.log("warning", "[ARENA_LIB] (" .. mod .. ") chat_all_prefix is deprecated. Use chat_settings = {prefix_all = \"some prefix\"} instead")
end
if def.chat_team_prefix then
def.chat_settings.prefix_team = def.chat_team_prefix
minetest.log("warning", "[ARENA_LIB] (" .. mod .. ") chat_team_prefix is deprecated. Use chat_settings = {prefix_team = \"some prefix\"} instead")
end
if def.chat_spectate_prefix then
def.chat_settings.prefix_spectate = def.chat_spectate_prefix
minetest.log("warning", "[ARENA_LIB] (" .. mod .. ") chat_spectate_prefix is deprecated. Use chat_settings = {prefix_spectate = \"some prefix\"} instead")
end
if def.chat_all_color then
def.chat_settings.color_all = def.chat_all_color
minetest.log("warning", "[ARENA_LIB] (" .. mod .. ") chat_all_color is deprecated. Use chat_settings = {color_all = \"some color\"} instead")
end
if def.chat_team_color then
def.chat_settings.color_team = def.chat_team_color
minetest.log("warning", "[ARENA_LIB] (" .. mod .. ") chat_team_color is deprecated. Use chat_settings = {color_team = \"some color\"} instead")
end
if def.chat_spectate_color then
def.chat_settings.color_spectate = def.chat_spectate_color
minetest.log("warning", "[ARENA_LIB] (" .. mod .. ") chat_spectate_color is deprecated. Use chat_settings = {color_spectate = \"some color\"} instead")
end
--^------------------ LEGACY UPDATE, to remove in 9.0 -------------------^
arena_lib.mods[mod] = {}
@ -125,13 +158,15 @@ function arena_lib.register_minigame(mod, def)
mod_ref.teams = {-1}
mod_ref.variable_teams_amount = false
mod_ref.teams_color_overlay = nil
mod_ref.is_team_chat_default = false
mod_ref.chat_all_prefix = "[" .. S("arena") .. "] "
mod_ref.chat_team_prefix = "[" .. S("team") .. "] "
mod_ref.chat_spectate_prefix = "[" .. S("spectator") .. "] "
mod_ref.chat_all_color = "#ffffff"
mod_ref.chat_team_color = "#ddfdff"
mod_ref.chat_spectate_color = "#dddddd"
mod_ref.chat_settings = {
prefix_all = "[" .. S("arena") .. "] ",
prefix_team = "[" .. S("team") .. "] ",
prefix_spectate = "[" .. S("spectator") .. "] ",
color_all = "#ffffff",
color_team = "#ddfdff",
color_spectate = "#dddddd",
is_team_chat_default = false
}
mod_ref.messages = {
eliminated = NS("@1 has been eliminated"),
eliminated_by = NS("@1 has been eliminated by @2"), -- I won't include `kicked` and `kicked_by` as it's more of a maintenance function
@ -200,35 +235,42 @@ function arena_lib.register_minigame(mod, def)
if def.teams_color_overlay then
mod_ref.teams_color_overlay = def.teams_color_overlay
end
end
if def.is_team_chat_default == true then
mod_ref.is_team_chat_default = true
if def.chat_settings and type(def.chat_settings) == "table" then
local settings = mod_ref.chat_settings
local new_settings = def.chat_settings
if new_settings.prefix_all then
settings.prefix_all = new_settings.prefix_all
end
if def.chat_team_prefix then
mod_ref.chat_team_prefix = def.chat_team_prefix
if new_settings.prefix_team then
settings.prefix_team = new_settings.prefix_team
end
if def.chat_team_color then
mod_ref.chat_team_color = def.chat_team_color
if new_settings.prefix_spectate then
settings.prefix_spectate = new_settings.prefix_spectate
end
if new_settings.color_all then
settings.color_all = new_settings.color_all
end
if new_settings.color_team then
settings.color_team = new_settings.color_team
end
if new_settings.color_spectate then
settings.color_spectate = new_settings.color_spectate
end
if new_settings.is_team_chat_default == true then
settings.is_team_chat_default = true
end
end
if def.chat_all_prefix then
mod_ref.chat_all_prefix = def.chat_all_prefix
end
if def.chat_all_color then
mod_ref.chat_all_color = def.chat_all_color
end
if def.chat_spectate_prefix then
mod_ref.chat_spectate_prefix = def.chat_spectate_prefix
end
if def.chat_spectate_color then
mod_ref.chat_spectate_color = def.chat_spectate_color
end
deprecated_chat_settings(mod_ref)
if def.custom_messages then
for k, msg in pairs(def.custom_messages) do
@ -1985,7 +2027,18 @@ function deprecated_sound_table_entry_exists(audio)
assert(type(audio) ~= "string", "[ARENA_LIB] since arena_lib 7.0 `sounds` entries must be tables. Check the new format in the arena_lib docs!")
end
function deprecated_chat_settings(mod_ref)
local chat_settings = mod_ref.chat_settings
mod_ref.chat_all_prefix = chat_settings.prefix_all
mod_ref.chat_team_prefix = chat_settings.prefix_team
mod_ref.chat_spectate_prefix = chat_settings.prefix_spectate
mod_ref.chat_all_color = chat_settings.color_all
mod_ref.chat_team_color = chat_settings.color_team
mod_ref.chat_spectate_color = chat_settings.color_spectate
mod_ref.is_team_chat_default = chat_settings.is_team_chat_default
end
function arena_lib.force_arena_ending(mod, arena, sender)
minetest.log("warning", "[ARENA_LIB] force_arena_ending is deprecated. Please use force_end instead")
arena_lib.force_end(sender, mod, arena)
end
end

View File

@ -9,16 +9,17 @@ minetest.register_on_mods_loaded(function()
if arena_lib.is_player_in_arena(p_name) then
local mod_ref = arena_lib.mods[arena_lib.get_mod_by_player(p_name)]
local arena = arena_lib.get_arena_by_player(p_name)
local settings = mod_ref.chat_settings
-- se è in celebrazione, tutti posson parlare con tutti
if arena.in_celebration then
local col, prefix
if arena_lib.is_player_spectating(p_name) then
col = mod_ref.chat_spectate_color
prefix = mod_ref.chat_spectate_prefix
col = settings.color_spectate
prefix = settings.prefix_spectate
else
col = mod_ref.chat_all_color
prefix = mod_ref.chat_all_prefix
col = settings.color_all
prefix = settings.prefix_all
end
arena_lib.send_message_in_arena(arena, "both", minetest.colorize(col, prefix .. minetest.format_chat_message(p_name, message)))
@ -27,17 +28,17 @@ minetest.register_on_mods_loaded(function()
if arena_lib.is_player_spectating(p_name) then
arena_lib.send_message_in_arena(arena, "spectators", minetest.colorize(mod_ref.chat_spectate_color, mod_ref.chat_spectate_prefix .. minetest.format_chat_message(p_name, message)))
arena_lib.send_message_in_arena(arena, "spectators", minetest.colorize(settings.color_spectate, settings.prefix_spectate .. minetest.format_chat_message(p_name, message)))
else
if arena.teams_enabled then
if mod_ref.is_team_chat_default then
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(mod_ref.chat_team_color, mod_ref.chat_team_prefix .. minetest.format_chat_message(p_name, message)), arena.players[p_name].teamID)
if settings.is_team_chat_default then
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(settings.color_team, settings.prefix_team .. minetest.format_chat_message(p_name, message)), arena.players[p_name].teamID)
else
arena_lib.send_message_in_arena(arena, "players", mod_ref.chat_all_prefix .. minetest.format_chat_message(p_name, message), arena.players[p_name].teamID)
arena_lib.send_message_in_arena(arena, "players", minetest.colorize("#ffdddd", mod_ref.chat_all_prefix .. minetest.format_chat_message(p_name, message)), arena.players[p_name].teamID, true)
arena_lib.send_message_in_arena(arena, "players", settings.prefix_all .. minetest.format_chat_message(p_name, message), arena.players[p_name].teamID)
arena_lib.send_message_in_arena(arena, "players", minetest.colorize("#ffdddd", settings.prefix_all .. minetest.format_chat_message(p_name, message)), arena.players[p_name].teamID, true)
end
else
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(mod_ref.chat_all_color, mod_ref.chat_all_prefix .. minetest.format_chat_message(p_name, message)))
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(settings.color_all, settings.prefix_all .. minetest.format_chat_message(p_name, message)))
end
return true
end

View File

@ -284,10 +284,10 @@ minetest.register_chatcommand("all", {
return false end
local msg = string.match(param, ".*")
local mod_ref = arena_lib.mods[arena_lib.get_mod_by_player(name)]
local chat_settings = arena_lib.mods[arena_lib.get_mod_by_player(name)].chat_settings
local arena = arena_lib.get_arena_by_player(name)
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(mod_ref.chat_all_color, mod_ref.chat_all_prefix .. minetest.format_chat_message(name, msg)))
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(chat_settings.color_all, chat_settings.prefix_all .. minetest.format_chat_message(name, msg)))
return true
end
})
@ -312,7 +312,7 @@ minetest.register_chatcommand("t", {
return false end
local msg = string.match(param, ".*")
local mod_ref = arena_lib.mods[arena_lib.get_mod_by_player(name)]
local chat_settings = arena_lib.mods[arena_lib.get_mod_by_player(name)].chat_settings
local arena = arena_lib.get_arena_by_player(name)
local teamID = arena.players[name].teamID
@ -320,7 +320,7 @@ minetest.register_chatcommand("t", {
arena_lib.print_error(name, S("Teams are not enabled!"))
return false end
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(mod_ref.chat_team_color, mod_ref.chat_team_prefix .. minetest.format_chat_message(name, msg)), teamID)
arena_lib.send_message_in_arena(arena, "players", minetest.colorize(chat_settings.color_team, chat_settings.prefix_team .. minetest.format_chat_message(name, msg)), teamID)
return true
end
})