From 28b8fcb3394b57c121575c6619f2643af9877c02 Mon Sep 17 00:00:00 2001 From: sys4-fr Date: Sat, 8 Sep 2018 16:37:15 +0200 Subject: [PATCH] =?UTF-8?q?Remplissage=20du=20d=C3=A9p=C3=B4t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 40 ++++++ depends.txt | 1 + init.lua | 230 ++++++++++++++++++++++++++++++++ textures/soundset_menu_icon.png | Bin 0 -> 1154 bytes 4 files changed, 271 insertions(+) create mode 100755 README.md create mode 100755 depends.txt create mode 100755 init.lua create mode 100644 textures/soundset_menu_icon.png diff --git a/README.md b/README.md new file mode 100755 index 0000000..6f4003d --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +soundset MOD for MINETEST +======================== + +by Mg (@LeMagnesium) and @crabman77 + +YOUR mod can use THIS mod to have a volume that's adjustable by the player(s) + +EXAMPLE + +minetest.sound_play("music_file", {to_player=player:get_player_name(),gain=sounds.get_gain(player:get_player_name(), "music")}) + +OR + +minetest.sound_play("mob_sound", {to_player=player:get_player_name(),gain=sounds.get_gain(player:get_player_name(), "mobs")}) + +OR + +minetest.sound_play("wind_sound", {to_player=player:get_player_name(),gain=sounds.get_gain(player:get_player_name(), "ambience")}) + + + + +commandchat + +/soundset : display menu + +/soundsetg : display player config + +/soundsets : set volume + + + +Licenses images: + Author : Obani CC-BY + +0.1 - Initial Release + +0.2 - change default volume to 50, add serialise|deserialise to read|write config file + +0.3 - add menu setting and button for unified_inventory and chatcommand to display menu diff --git a/depends.txt b/depends.txt new file mode 100755 index 0000000..20b7c42 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +unified_inventory? diff --git a/init.lua b/init.lua new file mode 100755 index 0000000..ac8edec --- /dev/null +++ b/init.lua @@ -0,0 +1,230 @@ +minetest.log("action","[mod soundset] Loading...") + +soundset = {} +soundset.file = minetest.get_worldpath() .. "/sounds_config.txt" +soundset.gainplayers = {} +local tmp = {} +tmp["music"] = {} +tmp["ambience"] = {} +tmp["other"] = {} + +local function save_sounds_config() + local input = io.open(soundset.file, "w") + if input then + input:write(minetest.serialize(soundset.gainplayers)) + input:close() + else + minetest.log("action","echec d'ouverture (mode:w) de " .. soundset.file) + end +end + + +local function load_sounds_config() + local file = io.open(soundset.file, "r") + if file then + soundset.gainplayers = minetest.deserialize(file:read("*all")) + file:close() + end + if soundset.gainplayers == nil or type(soundset.gainplayers) ~= "table" then + soundset.gainplayers = {} + end +end + +load_sounds_config() + +soundset.set_sound = function(name, param) + if param == "" then + minetest.chat_send_player(name, "/setsound ") + return + end + local param_name, param_value = param:match("^(%S+)%s(%S+)$") + if param_name == nil or param_value == nil then + minetest.chat_send_player(name, "invalid param, /setsound ") + return + end + + if param_name ~= "music" and param_name ~= "ambience" and param_name ~= "mobs" and param_name ~= "other" then + minetest.chat_send_player(name, "invalid param " .. param_name) + return + end + local value = tonumber(param_value) + if value == nil then + minetest.chat_send_player(name, "invalid value, " ..param_value .. " must be number") + return + end + + if value < 0 then + value = 0 + elseif value > 100 then + value = 100 + end + + if soundset.gainplayers[name][param_name] == value then + minetest.chat_send_player(name, "volume " .. param_name .. " already set to " .. value) + return + end + + soundset.gainplayers[name][param_name] = value + minetest.chat_send_player(name, "sound " .. param_name .. " set to " .. value) + save_sounds_config() +end + + +soundset.get_gain = function(name, sound_type) + if name == nil or name == "" then + return 1 + end + if not soundset.gainplayers[name] then return 1 end + local gain = soundset.gainplayers[name][sound_type] + if gain == nil then + return 1 + end + return gain/100 +end + +local inc = function(value) + value = value + 5 + if value > 100 then + value = 100 + end + return value +end + +local dec = function(value) + value = value - 5 + if value < 0 then + value = 0 + end + return value +end + + +local formspec = "size[6,6]".. + "label[2,0;Sound Menu]".. + "label[0,1.2;MUSIC]".. + "button[1.6,1;1,1;vmusic;-]".. + "label[2.7,1.2;%s]".. + "button[3.5,1;1,1;vmusic;+]".. + "label[0,2.2;AMBIENCE]".. + "button[1.6,2;1,1;vambience;-]".. + "label[2.7,2.2;%s]".. + "button[3.5,2;1,1;vambience;+]".. + "label[0,3.2;OTHER]".. + "button[1.6,3;1,1;vother;-]".. + "label[2.7,3.2;%s]".. + "button[3.5,3;1,1;vother;+]".. + "button_exit[0.5,5.2;1.5,1;abort;Abort]".. + "button_exit[4,5.2;1.5,1;abort;Ok]" + + +local on_show_settings = function(name, music, ambience, other) + tmp["music"][name] = music + tmp["ambience"][name] = ambience + tmp["other"][name] = other + minetest.show_formspec( name, "soundset:settings", string.format(formspec, tostring(music), tostring(ambience), tostring(other) )) +end + +local clear_tmp = function(name) + tmp["music"][name] = nil + tmp["ambience"][name] = nil + tmp["other"][name] = nil +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "soundset:settings" then + local name = player:get_player_name() + if not name or name == "" then return end + local fmusic = tmp["music"][name] or 50 + local fambience = tmp["ambience"][name] or 50 + local fother = tmp["other"][name] or 50 + if fields["abort"] == "Ok" then + if soundset.gainplayers[name]["music"] ~= fmusic or soundset.gainplayers[name]["ambience"] ~= fambience or soundset.gainplayers[name]["other"] ~= fother then + soundset.gainplayers[name]["music"] = fmusic + soundset.gainplayers[name]["ambience"] = fambience + soundset.gainplayers[name]["other"] = fother + save_sounds_config() + end + clear_tmp(name) + return + elseif fields["abort"] == "Abort" then + clear_tmp(name) + return + elseif fields["vmusic"] == "+" then + fmusic = inc(fmusic) + elseif fields["vmusic"] == "-" then + fmusic = dec(fmusic) + elseif fields["vambience"] == "+" then + fambience = inc(fambience) + elseif fields["vambience"] == "-" then + fambience = dec(fambience) + elseif fields["vother"] == "+" then + fother = inc(fother) + elseif fields["vother"] == "-" then + fother = dec(fother) + elseif fields["quit"] == "true" then + clear_tmp(name) + return + else + return + end + + on_show_settings(name, fmusic, fambience, fother) + end +end) + + +if (minetest.get_modpath("unified_inventory")) then + unified_inventory.register_button("menu_soundset", { + type = "image", + image = "soundset_menu_icon.png", + tooltip = "sounds menu ", + show_with = false, --Modif MFF (Crabman 30/06/2015) + action = function(player) + local name = player:get_player_name() + if not name then return end + on_show_settings(name, soundset.gainplayers[name]["music"], soundset.gainplayers[name]["ambience"], soundset.gainplayers[name]["other"]) + end, + }) +end + +minetest.register_chatcommand("soundset", { + params = "", + description = "Display volume menu formspec", + privs = {interact=true}, + func = function(name, param) + if not name then return end + on_show_settings(name, soundset.gainplayers[name]["music"], soundset.gainplayers[name]["ambience"], soundset.gainplayers[name]["other"]) + end +}) + + +minetest.register_chatcommand("soundsets", { + params = " ", + description = "Set volume sound ", + privs = {interact=true}, + func = soundset.set_sound, +}) + +minetest.register_chatcommand("soundsetg", { + params = "", + description = "Display volume sound ", + privs = {interact=true}, + func = function(name, param) + local conf = "" + for k, v in pairs(soundset.gainplayers[name]) do + conf = conf .. " " .. k .. ":" .. v + end + minetest.chat_send_player(name, "sounds conf " .. conf) + minetest.log("action","Player ".. name .. " sound conf " .. conf) + end +}) + +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + if soundset.gainplayers[name] == nil then + soundset.gainplayers[name] = { ["music"] = 50, ["ambience"] = 50, ["mobs"] = 50, ["other"] = 50 } + end +end) + +minetest.log("action","[mod soundset] Loaded") + diff --git a/textures/soundset_menu_icon.png b/textures/soundset_menu_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..797921615826ac021971dcb48e8219869032e695 GIT binary patch literal 1154 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+yeRz&I(uC&cyt|NlUdp$nLpnAq6Z z*xA`RI5;>tIVB|}rKF_f<>i%>l$4c~RaI5h)YLRIG_+g($p8XB6Kn%dghy1Kf0dU_^K zoH%vr)alcw&zLb|{`~nXR;<{tVZ-Llo40M-wqwVR!-o%_JbCiesZ*yC&YuSFYT+apUgYyZ7(kfAZwXvuDrVym|Bf{rgX!K7IcD`TO_pKY#xG_3PK4 zKY#xH`v;7U_H(?8f$?Eq666=mz{teL%_Ar*E-hndWMUQ&6&;(LQc_k^+tAeAJ9+Ai zS@Y&ETfTGezT+oOo;rQz>b2`PZr;B8@X@nZuiw6V|Ld=d^_~|D3`_~0E{-7;jBl?! z4;S_oIsS3?O_dfKPR5`L7lFX09bSefHw8_a@5)jg_-4_HgoF2XYn=PPR?fEgoyyFU zZ>sIyf3HsaK4))n=48j}=La^JKl4A|$M?0Y+(l!GN7@D^*9+5?vh&upsHs&wN>L8u zSYSA{bj8vVNj7CoqvB7Y5?6o48hMCZ3^MeJ@{||bV|FP+x_#9?f_V*YG*@z;#x;$6FrE zYn(l;(J=ObrJht=Vi=oE?1RL+?lG+9TFi%c9Wa{4QqFv50uRp%Ch-p;1?dOAo^n{O z_Tl4!KmG@68Wu&f-7>YmEPF@fj;)53$0~L_lWCVrYzW7(r68e4YVTIVoTHFQl+fSb&! z$?KF_qPnD>2s+uD79Cn+p=UbrL*mKqpkUA2rvCdisx~}O_tehX{7UV_fxBVNfu`># zL{^#eoXX5PdGcMmTR_Le-XH&eUvSZUK56U!ZGKLHHz#%mX!xzlK7DSlvGL@`)n&Qw dy)LQkjsGy?x~_OmG8?EE@pScbS?83{1OQiD#z+7F literal 0 HcmV?d00001