initial files

master
NatureFreshMilk 2019-04-29 11:07:48 +02:00
commit 8a3945b83d
9 changed files with 297 additions and 0 deletions

15
api.lua Normal file
View File

@ -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

20
builtin.lua Normal file
View File

@ -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"
})

2
depends.txt Normal file
View File

@ -0,0 +1,2 @@
default?
mesecons?

94
form.lua Normal file
View File

@ -0,0 +1,94 @@
local FORMNAME = "soundblock_config"
--[[
config options:
* mesecon-behavior: [repeat, single]
* state: [off, mesecon, on]
* interval-from <float>
* interval-to <float>
* gain <float>
* hear-distance <int>
* randomize-position <int> 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)

16
init.lua Normal file
View File

@ -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")

56
license.txt Normal file
View File

@ -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.

39
readme.md Normal file
View File

@ -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

55
soundblock.lua Normal file
View File

@ -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"},
},
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B