Custom lighting per arena

master
Zughy 2022-04-01 10:26:26 +00:00
parent b1a5386a3b
commit b0512d80d9
12 changed files with 215 additions and 7 deletions

View File

@ -35,6 +35,7 @@
* [2.2.2.9 Timers](#2229-timers)
* [2.2.2.10 Music](#22210-music)
* [2.2.2.11 Celestial vault](#22211-celestial-vault)
* [2.2.2.12 Lighting](#22212-lighting)
* [2.3 Arena phases](#23-arena-phases)
* [2.4 Spectate mode](#24-spectate-mode)
* [3. About the author(s)](#3-about-the-authors)
@ -443,6 +444,10 @@ By default, the arena's celestial vault reflects the celestial vault of the play
will increase the size of the sun inside the arena and hide the sunrise texture. `params` can also be `nil`, and in that case will remove any custom setting previously set.
Last but not least, the special element `"all"` allows you to change everything, and it needs a table with the following optional parameters: `{sky={...}, sun={...}, moon={...}, stars={...}, clouds={...}}`. If `params` is nil, it'll reset the whole celestial vault.
##### 2.2.2.12 Lighting
NOTE: EXPERIMENTAL FEATURE. EXPECT BREAKAGE IN THE FUTURE (according to the direction Minetest will choose to go with lighting)
By default, the arena's lighting settings reflect the lighting settings of the player before entering the match (meaning there are no default values inside arena_lib).
`arena_lib.set_lighting(sender, mod, arena_name, light_table)` allows you to override those settings. As for now, `light_table` only takes one field, `light`, a float between 0 and 1 that changes the intensity of the global lighting. If `light_table` is `nil`, it'll reset the whole lighting settings.
### 2.3 Arena phases
An arena comes in 4 phases, each one of them linked to a specific function:

View File

@ -20,6 +20,7 @@ dofile(srcpath .. "/editor/editor_main.lua")
dofile(srcpath .. "/editor/editor_icons.lua")
dofile(srcpath .. "/editor/tools_bgm.lua")
dofile(srcpath .. "/editor/tools_customise.lua")
dofile(srcpath .. "/editor/tools_lighting.lua")
dofile(srcpath .. "/editor/tools_players.lua")
dofile(srcpath .. "/editor/tools_settings.lua")
dofile(srcpath .. "/editor/tools_sign.lua")

View File

@ -37,6 +37,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
Lighting of arena @1 successfully overwritten=Illuminazione dell'arena @1 sovrascritta con successo
All=Tutto
Sky=Cielo
Sun=Sole
@ -199,6 +200,11 @@ Pitch=Tono
Apply=Applica
[!] This audio track doesn't exist!=[!] Questa traccia audio non esiste!
# editor/tools_lighting.lua
Lighting=Illuminazione
Global light=Luce globale
Shadows=Ombre
# 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

@ -37,6 +37,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=
Lighting of arena @1 successfully overwritten=
All=
Sky=
Sun=
@ -199,6 +200,11 @@ Pitch=
Apply=
[!] This audio track doesn't exist!=
# editor/tools_lighting.lua
Lighting=
Global light=
Shadows=
# editor/tools_players.lua
Change the current number=
Teams: on (click to toggle off)=

View File

@ -38,6 +38,7 @@ local arena_default = {
max_players = 4,
min_players = 2,
celestial_vault = {}, -- sky = {...}, sun = {...}, moon = {...}, stars = {...}, clouds = {...}
lighting = nil,
bgm = nil,
initial_time = nil,
current_time = nil,
@ -827,6 +828,29 @@ end
-- NOTE: è molto probabile che questa funzione verrà modificata con l'arrivo della 5.6,
-- dacché l'ho segnata come sperimentale (per esempio, arriverà set_lighting()
-- per modificare le ombre)
function arena_lib.set_lighting(sender, mod, arena_name, light_table, in_editor)
local 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 light_table ~= nil and type(light_table) ~= "table" then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!")))
return end
arena.lighting = light_table
update_storage(false, mod, id, arena)
minetest.chat_send_player(sender, arena_lib.mods[mod].prefix .. S("Lighting of arena @1 successfully overwritten", arena.name))
end
function arena_lib.set_celestial_vault(sender, mod, arena_name, element, params, in_editor)
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)

View File

@ -670,6 +670,20 @@ function operations_before_entering_arena(mod_ref, mod, arena, arena_ID, p_name)
local player = minetest.get_player_by_name(p_name)
-- cambio eventuale illuminazione
if arena.lighting then
players_temp_storage[p_name].lighting = {
light = player:get_day_night_ratio()
}
local lighting = arena.lighting
if lighting.light then
player:override_day_night_ratio(lighting.light)
end
--TODO MT 5.6: set_lighting (shadows)
end
-- cambio eventuale volta celeste
if next(arena.celestial_vault) then
local celvault = arena.celestial_vault
@ -811,8 +825,18 @@ end
-- reason parametro opzionale che passo solo quando potrebbe essersi disconnesso
function operations_before_leaving_arena(mod_ref, arena, p_name, reason)
-- disattivo eventuale musica di sottofondo
if arena.bgm then
minetest.sound_stop(players_temp_storage[p_name].bgm_handle)
end
local player = minetest.get_player_by_name(p_name)
-- reimposto eventuale illuminazione
if arena.lighting then
player:override_day_night_ratio(players_temp_storage[p_name].lighting.light)
end
-- reimposto eventuale volta celeste
if next(arena.celestial_vault) then
local celvault = arena.celestial_vault
@ -907,11 +931,6 @@ function operations_before_leaving_arena(mod_ref, arena, p_name, reason)
-- ripristino nomi
player:set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}})
-- 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

@ -155,6 +155,12 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
time = minetest.colorize("#eea160", S("Initial time: ")) .. minetest.colorize("#cfc6b8", arena.initial_time .. " (" .. S("current: ") .. current_time .. ")") .. "\n"
end
-- calcolo eventuale illuminazione personalizzata
local lighting = ""
if arena.lighting then
lighting = minetest.serialize(arena.lighting)
end
--calcolo proprietà
local properties = ""
for property, _ in pairs(mod_ref.properties) do
@ -221,6 +227,7 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
minetest.colorize("#eea160", S("Spawn points: ")) .. minetest.colorize("#cfc6b8", #arena.spawn_points .. " ( " .. spawners_pos .. ")") .. "\n" ..
time ..
minetest.colorize("#eea160", S("Custom sky: ")) .. minetest.colorize("#cfc6b8", minetest.serialize(arena.celestial_vault)) .. "\n" ..
minetest.colorize("#eea160", S("Custom lighting: ")) .. minetest.colorize("#cfc6b8", lighting) .. "\n" ..
minetest.colorize("#eea160", S("Properties: ")) .. minetest.colorize("#cfc6b8", properties) .. "\n" ..
minetest.colorize("#eea160", S("Temp properties: ")) .. minetest.colorize("#cfc6b8", temp_properties) .. "\n" ..
minetest.colorize("#eea160", S("Team properties: ")) .. minetest.colorize("#cfc6b8", team_properties)

View File

@ -102,6 +102,7 @@ function arena_lib.enter_editor(sender, mod, arena_name)
inv = player:get_inventory():get_list("main"),
pos = player:get_pos(),
celvault = p_cvault,
lighting = {light = player:get_day_night_ratio()},
hotbar_slots = player:hud_get_hotbar_itemcount(),
hotbar_bg = player:hud_get_hotbar_image()
}
@ -127,6 +128,11 @@ function arena_lib.enter_editor(sender, mod, arena_name)
if celvault.clouds then player:set_clouds(celvault.clouds) end
end
-- imposto luce
if arena.lighting then
player:override_day_night_ratio(arena.lighting.light)
end
-- se c'è almeno uno spawner, teletrasporto
if next(arena.spawn_points) then
player:set_pos(arena.spawn_points[next(arena.spawn_points)].pos)
@ -154,6 +160,7 @@ function arena_lib.quit_editor(player)
local inv = players_in_edit_mode[p_name].inv
local pos = players_in_edit_mode[p_name].pos
local celvault = table.copy(players_in_edit_mode[p_name].celvault)
local lighting = players_in_edit_mode[p_name].lighting
local hotbar_slots = players_in_edit_mode[p_name].hotbar_slots
local hotbar_bg = players_in_edit_mode[p_name].hotbar_bg
@ -184,6 +191,8 @@ function arena_lib.quit_editor(player)
player:set_clouds(celvault.clouds)
end
player:override_day_night_ratio(lighting.light)
-- restituisco l'inventario
minetest.after(0, function()
if not minetest.get_player_by_name(p_name) then return end

View File

@ -3,7 +3,7 @@ local S = minetest.get_translator("arena_lib")
local customise_tools = {
"arena_lib:customise_bgm",
"arena_lib:customise_sky",
"",
"arena_lib:customise_lighting",
"",
"",
"",

View File

@ -0,0 +1,131 @@
local S = minetest.get_translator("arena_lib")
local function fill_templight() end
local function get_lighting_formspec() end
local temp_light_settings = {} -- KEY = p_name; VALUE = {all the lighting settings}
minetest.register_tool("arena_lib:customise_lighting", {
description = S("Lighting"),
inventory_image = "arenalib_customise_lighting.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)
local p_name = user:get_player_name()
fill_templight(p_name, arena)
minetest.show_formspec(p_name, "arena_lib:lighting", get_lighting_formspec(p_name))
end
})
----------------------------------------------
---------------FUNZIONI LOCALI----------------
----------------------------------------------
function fill_templight(p_name, arena)
temp_light_settings[p_name] = not arena.lighting and {} or table.copy(arena.lighting)
end
function get_lighting_formspec(p_name)
local light = temp_light_settings[p_name].light or 50
--TODO MT 5.6: local shadows = 0
local formspec = {
"formspec_version[4]",
"size[7,4.5]",
"bgcolor[;neither]",
-- parametri vari
"container[0.5,0.5]",
"label[0,0;" .. S("Global light") .. "]",
"label[0,0.41;0]",
"label[5.64,0.41;1]",
"scrollbaroptions[max=100;smallstep=1;largestep=10;arrows=hide]",
"scrollbar[0.4,0.3;5.2,0.2;;light;" .. light .. "]",
"label[0,1;" .. S("Shadows") .. "]",
"hypertext[-0.05,1.3;6,0.3;audio_info;<style size=12 font=mono color=#b7aca3>(" .. S("coming with MT 5.6") .. ")</style>]",
--[["label[0,1.41;0]",
"label[5.9,1.41;1]",
"scrollbar[0.4,1.3;5.2,0.2;;shadows;" .. shadows .. "]",]]
"container_end[]",
"button[1.95,3.7;1.5,0.5;reset;" .. S("Reset") .."]",
"button[3.55,3.7;1.5,0.5;apply;" .. S("Apply") .."]",
}
return table.concat(formspec, "")
end
----------------------------------------------
---------------GESTIONE CAMPI-----------------
----------------------------------------------
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "arena_lib:lighting" then return end
local p_name = player:get_player_name()
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)
local light_table = arena.lighting or {}
-- se abbandona...
if fields.quit then
if next(light_table) then
player:override_day_night_ratio(light_table.light)
else
player:override_day_night_ratio(nil)
end
temp_light_settings[p_name] = nil
return
-- ...o se ripristina, non c'è bisogno di andare oltre
elseif fields.reset then
-- se la tabella non esiste, vuol dire che non c'è nulla da ripristinare (ed evito
-- che invii il messaggio di proprietà sovrascritte)
if arena.lighting then
arena_lib.set_lighting(p_name, mod, arena_name, nil, true)
end
player:override_day_night_ratio(nil)
minetest.show_formspec(p_name, "arena_lib:lighting", get_lighting_formspec(p_name))
return
end
--
-- aggiorna i vari parametri
--
if fields.light then
light_table.light = minetest.explode_scrollbar_event(fields.light).value / 100
end
-- applica
if fields.apply then
arena_lib.set_lighting(p_name, mod, arena_name, light_table, true)
end
player:override_day_night_ratio(light_table.light)
end)

View File

@ -649,7 +649,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
-- controlla i vari campi che aggiornano il formspec
-- controlla i vari campi che necessitano di ricaricare il formspec (le spunte)
if fields.sky_clouds then
temp_sky.clouds = fields.sky_clouds == "true" and true or false

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B