From 6273c27d944151404ce046aab5a03043be7a17e8 Mon Sep 17 00:00:00 2001 From: cheapie Date: Sun, 4 Dec 2016 22:04:12 -0600 Subject: Add piezo beeper --- init.lua | 80 ++++++++++++++++++++++++++++++++ sounds/digistuff_piezo_fast_repeat.ogg | Bin 0 -> 5515 bytes sounds/digistuff_piezo_long_single.ogg | Bin 0 -> 6637 bytes sounds/digistuff_piezo_short_single.ogg | Bin 0 -> 4672 bytes sounds/digistuff_piezo_slow_repeat.ogg | Bin 0 -> 5219 bytes textures/digistuff_piezo_sides.png | Bin 0 -> 3187 bytes textures/digistuff_piezo_top.png | Bin 0 -> 2663 bytes 7 files changed, 80 insertions(+) create mode 100644 sounds/digistuff_piezo_fast_repeat.ogg create mode 100644 sounds/digistuff_piezo_long_single.ogg create mode 100644 sounds/digistuff_piezo_short_single.ogg create mode 100644 sounds/digistuff_piezo_slow_repeat.ogg create mode 100644 textures/digistuff_piezo_sides.png create mode 100644 textures/digistuff_piezo_top.png diff --git a/init.lua b/init.lua index a50af15..e9b1cf7 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,5 @@ digistuff = {} +digistuff.sounds_playing = {} digistuff.update_panel_formspec = function (pos,dispstr) local meta = minetest.get_meta(pos) @@ -676,3 +677,82 @@ minetest.register_node("digistuff:touchscreen", { }, }, }) + +minetest.register_node("digistuff:piezo", { + description = "Digilines Piezoelectric Beeper", + groups = {cracky=3}, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec","field[channel;Channel;${channel}") + end, + on_destruct = function(pos) + local pos_hash = minetest.hash_node_position(pos) + if digistuff.sounds_playing[pos_hash] then + minetest.sound_stop(digistuff.sounds_playing[pos_hash]) + digistuff.sounds_playing[pos_hash] = nil + end + end, + tiles = { + "digistuff_piezo_top.png", + "digistuff_piezo_sides.png", + "digistuff_piezo_sides.png", + "digistuff_piezo_sides.png", + "digistuff_piezo_sides.png", + "digistuff_piezo_sides.png" + }, + on_receive_fields = function(pos, formname, fields, sender) + local name = sender:get_player_name() + if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then + minetest.record_protection_violation(pos,name) + return + end + local meta = minetest.get_meta(pos) + if fields.channel then meta:set_string("channel",fields.channel) end + end, + digiline = + { + receptor = {}, + effector = { + action = function(pos,node,channel,msg) + local meta = minetest.get_meta(pos) + local setchan = meta:get_string("channel") + if channel ~= setchan then return end + if msg == "shortbeep" then + local pos_hash = minetest.hash_node_position(pos) + if digistuff.sounds_playing[pos_hash] then + minetest.sound_stop(digistuff.sounds_playing[pos_hash]) + digistuff.sounds_playing[pos_hash] = nil + end + minetest.sound_play({name = "digistuff_piezo_short_single",gain = 0.2},{pos = pos,max_hear_distance = 16}) + elseif msg == "longbeep" then + local pos_hash = minetest.hash_node_position(pos) + if digistuff.sounds_playing[pos_hash] then + minetest.sound_stop(digistuff.sounds_playing[pos_hash]) + digistuff.sounds_playing[pos_hash] = nil + end + minetest.sound_play({name = "digistuff_piezo_long_single",gain = 0.2},{pos = pos,max_hear_distance = 16}) + elseif msg == "fastrepeat" then + local pos_hash = minetest.hash_node_position(pos) + if digistuff.sounds_playing[pos_hash] then + minetest.sound_stop(digistuff.sounds_playing[pos_hash]) + digistuff.sounds_playing[pos_hash] = nil + end + digistuff.sounds_playing[pos_hash] = minetest.sound_play({name = "digistuff_piezo_fast_repeat",gain = 0.2},{pos = pos,max_hear_distance = 16,loop = true}) + elseif msg == "slowrepeat" then + local pos_hash = minetest.hash_node_position(pos) + if digistuff.sounds_playing[pos_hash] then + minetest.sound_stop(digistuff.sounds_playing[pos_hash]) + digistuff.sounds_playing[pos_hash] = nil + end + digistuff.sounds_playing[pos_hash] = minetest.sound_play({name = "digistuff_piezo_slow_repeat",gain = 0.2},{pos = pos,max_hear_distance = 16,loop = true}) + elseif msg == "stop" then + local pos_hash = minetest.hash_node_position(pos) + if digistuff.sounds_playing[pos_hash] then + minetest.sound_stop(digistuff.sounds_playing[pos_hash]) + digistuff.sounds_playing[pos_hash] = nil + end + end + end + }, + }, +}) diff --git a/sounds/digistuff_piezo_fast_repeat.ogg b/sounds/digistuff_piezo_fast_repeat.ogg new file mode 100644 index 0000000..be035da Binary files /dev/null and b/sounds/digistuff_piezo_fast_repeat.ogg differ diff --git a/sounds/digistuff_piezo_long_single.ogg b/sounds/digistuff_piezo_long_single.ogg new file mode 100644 index 0000000..435ac61 Binary files /dev/null and b/sounds/digistuff_piezo_long_single.ogg differ diff --git a/sounds/digistuff_piezo_short_single.ogg b/sounds/digistuff_piezo_short_single.ogg new file mode 100644 index 0000000..0178f15 Binary files /dev/null and b/sounds/digistuff_piezo_short_single.ogg differ diff --git a/sounds/digistuff_piezo_slow_repeat.ogg b/sounds/digistuff_piezo_slow_repeat.ogg new file mode 100644 index 0000000..1b35343 Binary files /dev/null and b/sounds/digistuff_piezo_slow_repeat.ogg differ diff --git a/textures/digistuff_piezo_sides.png b/textures/digistuff_piezo_sides.png new file mode 100644 index 0000000..7d66228 Binary files /dev/null and b/textures/digistuff_piezo_sides.png differ diff --git a/textures/digistuff_piezo_top.png b/textures/digistuff_piezo_top.png new file mode 100644 index 0000000..44f8e07 Binary files /dev/null and b/textures/digistuff_piezo_top.png differ -- cgit v1.2.3