From 8a3945b83db1bf2db22c33eb71ea8f81e4e5f8b3 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Mon, 29 Apr 2019 11:07:48 +0200 Subject: [PATCH] initial files --- api.lua | 15 ++++++ builtin.lua | 20 +++++++ depends.txt | 2 + form.lua | 94 +++++++++++++++++++++++++++++++++ init.lua | 16 ++++++ license.txt | 56 ++++++++++++++++++++ readme.md | 39 ++++++++++++++ soundblock.lua | 55 +++++++++++++++++++ textures/soundblocks_block.png | Bin 0 -> 179 bytes 9 files changed, 297 insertions(+) create mode 100644 api.lua create mode 100644 builtin.lua create mode 100644 depends.txt create mode 100644 form.lua create mode 100644 init.lua create mode 100644 license.txt create mode 100644 readme.md create mode 100644 soundblock.lua create mode 100644 textures/soundblocks_block.png diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..a27515a --- /dev/null +++ b/api.lua @@ -0,0 +1,15 @@ + +--[[ +def = { + length = 2, -- seconds + filenames = { + "default_glass_footstep.ogg" + }, + key = "default_glass_footsteps", -- internal name + name = "Glass footsteps" -- display name +} +--]] + +soundblocks.register = function(def) + soundblocks.sounds[def.key] = def +end diff --git a/builtin.lua b/builtin.lua new file mode 100644 index 0000000..f7449a4 --- /dev/null +++ b/builtin.lua @@ -0,0 +1,20 @@ + + +soundblocks.register({ + length = 2, + filename = "default_glass_footstep.ogg", + key = "default_glass_footsteps", + name = "Glass footsteps" +}) + + +soundblocks.register({ + length = 2, + filenames = { + "default_grass_footstep.1.ogg", + "default_grass_footstep.2.ogg", + "default_grass_footstep.3.ogg" + }, + key = "default_grass_footstep", + name = "Grass footsteps" +}) diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..b07e150 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +default? +mesecons? diff --git a/form.lua b/form.lua new file mode 100644 index 0000000..d0712c6 --- /dev/null +++ b/form.lua @@ -0,0 +1,94 @@ + +local FORMNAME = "soundblock_config" + +--[[ +config options: +* mesecon-behavior: [repeat, single] +* state: [off, mesecon, on] + +* interval-from +* interval-to + +* gain +* hear-distance +* randomize-position 0...64 + +--]] + + +soundblocks.showform = function(pos, node, player) + + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local has_override = minetest.check_player_privs(player, "protection_bypass") + + -- check if plain user rightclicks + if player:get_player_name() ~= owner and not has_override then + return + end + + local selected_sound_key = meta:get_string("selected_sound_key") + local selected_sound = 0 + + -- sound list + local sound_list = "textlist[0,1;5,6;sounds;" + for i,sound in ipairs(soundblocks.sounds) do + if selected_sound_key == sound.key then + selected_sound = i + end + + sound_list = sound_list .. i .. ": " .. minetest.formspec_escape(sound.name) + if i < #soundblocks.sounds then + sound_list = sound_list .. "," + end + end + sound_list = sound_list .. ";" .. selected_sound .. "]"; + + local formspec = "size[8,8;]" .. + --left + "label[0,0;Mission editor]" .. + "button[5.5,1;2,1;add;Add]" .. + "button[5.5,2;2,1;edit;Edit]" .. + "button[5.5,3;2,1;up;Up]" .. + "button[5.5,4;2,1;down;Down]" .. + "button[5.5,5;2,1;remove;Remove]" .. + steps_list .. + "button_exit[0,7;8,1;save;Save and validate]" + + minetest.show_formspec(player:get_player_name(), + FORMNAME .. ";" .. minetest.pos_to_string(pos), + formspec + ) + +end + + + +minetest.register_on_player_receive_fields(function(player, formname, fields) + local parts = formname:split(";") + local name = parts[1] + if name ~= FORMNAME then + return + end + + local pos = minetest.string_to_pos(parts[2]) + local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + local has_override = minetest.check_player_privs(player, "protection_bypass") + + if not has_override and minetest.is_protected(pos, player:get_player_name()) then + return + end + + if fields.sounds then + parts = fields.steps:split(":") + if parts[1] == "CHG" then + local selected_sound = tonumber(parts[2]) + --TODO + end + end + + --TODO + + +end) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..2163382 --- /dev/null +++ b/init.lua @@ -0,0 +1,16 @@ + +soundblocks = { + sounds = {} +} + +local MP = minetest.get_modpath("soundblocks") +dofile(MP.."/api.lua") +dofile(MP.."/form.lua") +dofile(MP.."/soundblock.lua") + +if minetest.get_modpath("default") then + dofile(MP.."/builtin.lua") +end + + +print("[OK] Soundblocks") diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..795da89 --- /dev/null +++ b/license.txt @@ -0,0 +1,56 @@ +License of source code +---------------------- + +The MIT License (MIT) +Copyright (C) 2018-2019 Thomas Rudin + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +For more details: +https://opensource.org/licenses/MIT + + +Licenses of media (textures) +---------------------------- + +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +Copyright (C) 2019 Thomas Rudin + +You are free to: +Share — copy and redistribute the material in any medium or format. +Adapt — remix, transform, and build upon the material for any purpose, even commercially. +The licensor cannot revoke these freedoms as long as you follow the license terms. + +Under the following terms: + +Attribution — You must give appropriate credit, provide a link to the license, and +indicate if changes were made. You may do so in any reasonable manner, but not in any way +that suggests the licensor endorses you or your use. + +ShareAlike — If you remix, transform, or build upon the material, you must distribute +your contributions under the same license as the original. + +No additional restrictions — You may not apply legal terms or technological measures that +legally restrict others from doing anything the license permits. + +Notices: + +You do not have to comply with the license for elements of the material in the public +domain or where your use is permitted by an applicable exception or limitation. +No warranties are given. The license may not give you all of the permissions necessary +for your intended use. For example, other rights such as publicity, privacy, or moral +rights may limit how you use the material. diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f92dfaa --- /dev/null +++ b/readme.md @@ -0,0 +1,39 @@ + +A soundblock that emits sounds with given interval or per mesecon signal + +## Api + +Register custom sounds: + +```lua +soundblocks.register({ + length = 2, + filename = "default_glass_footstep.ogg", + key = "default_glass_footsteps", + name = "Glass footsteps" +}) + + +soundblocks.register({ + length = 2, + filenames = { + "default_grass_footstep.1.ogg", + "default_grass_footstep.2.ogg", + "default_grass_footstep.3.ogg" + }, + key = "default_grass_footstep", + name = "Grass footsteps" +}) + +``` + + + +# License + +See `license.txt` + +## textures/soundblock_block.png + +* DWYWPL +* https://github.com/minetest-mods/mysoundblocks diff --git a/soundblock.lua b/soundblock.lua new file mode 100644 index 0000000..c721af8 --- /dev/null +++ b/soundblock.lua @@ -0,0 +1,55 @@ + +-- minetest.sound_play("vacuum_hiss", {pos = pos, gain = 0.5, max_hear_distance=16}) +-- local timer = minetest.get_node_timer(pos) +-- timer:start(3) + + +minetest.register_node("soundblocks:block", { + description = "Sound Block", + tiles = {"soundblocks_block.png"}, + is_ground_content = false, + groups = { oddly_breakable_by_hand = 1 }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("selected_sound_key", "") + end, + + can_dig = function(pos,player) + if player and player:is_player() and minetest.is_protected(pos, player:get_player_name()) then + -- protected + return false + end + + return true + end, + + on_timer = function(pos, elapsed) + --TODO + end, + + mesecons = {effector = { + action_on = function (pos, node) + local meta = minetest.get_meta(pos) + --TODO + update_infotext(meta) + end, + action_off = function (pos, node) + local meta = minetest.get_meta(pos) + --TODO + update_infotext(meta) + end + }}, + + on_rightclick = soundblocks.showform +}) + + +minetest.register_craft({ + output = "soundblocks:block", + recipe = { + {"default:steel_ingot", "default:steelblock", "default:steel_ingot"}, + {"default:steel_ingot", "default:glass", "default:steel_ingot"}, + {"default:steel_ingot", "default:steelblock", "default:steel_ingot"}, + }, +}) diff --git a/textures/soundblocks_block.png b/textures/soundblocks_block.png new file mode 100644 index 0000000000000000000000000000000000000000..7b108abddc6cfddb81ea03c6fafe91b754ed54b3 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|Y)RhkE