mirror of
https://github.com/D00Med/scifi_nodes.git
synced 2025-02-05 20:30:21 +01:00
add ambience sounds and helper function (#87)
* add ambience sounds and helper function * minor tweaks * fix deps --------- Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
This commit is contained in:
parent
62037ad60a
commit
d531ad4eda
@ -49,6 +49,9 @@ CC BY 3.0
|
|||||||
|
|
||||||
CC0
|
CC0
|
||||||
* scifi_nodes_digicode.ogg https://freesound.org/people/benjaminharveydesign/sounds/315921/
|
* scifi_nodes_digicode.ogg https://freesound.org/people/benjaminharveydesign/sounds/315921/
|
||||||
|
* scifi_nodes_ambience_fan.ogg https://freesound.org/people/itinerantmonk108/sounds/554430/
|
||||||
|
* scifi_nodes_ambience_vent.ogg https://freesound.org/people/kentspublicdomain/sounds/324665/
|
||||||
|
* scifi_nodes_ambience_engine.ogg https://freesound.org/people/firestorm185/sounds/423221/
|
||||||
|
|
||||||
|
|
||||||
# Contributors:
|
# Contributors:
|
||||||
|
73
ambience.lua
Normal file
73
ambience.lua
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
-- currently playing sounds per mapblock
|
||||||
|
-- mapblock_pos[number]
|
||||||
|
local currently_playing = {}
|
||||||
|
|
||||||
|
-- clear the currently playing tracker every few seconds
|
||||||
|
local function clear_currently_playing()
|
||||||
|
currently_playing = {}
|
||||||
|
minetest.after(5, clear_currently_playing)
|
||||||
|
end
|
||||||
|
minetest.after(5, clear_currently_playing)
|
||||||
|
|
||||||
|
-- mapblock resolution
|
||||||
|
local function get_key(pos)
|
||||||
|
return minetest.pos_to_string(vector.round(vector.divide(pos, 16)))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function add_currently_playing(pos, value)
|
||||||
|
local key = get_key(pos)
|
||||||
|
local count = currently_playing[key]
|
||||||
|
if not count then
|
||||||
|
-- new entry
|
||||||
|
count = value
|
||||||
|
else
|
||||||
|
-- update entry
|
||||||
|
count = count + value
|
||||||
|
end
|
||||||
|
currently_playing[key] = count
|
||||||
|
end
|
||||||
|
|
||||||
|
-- limit plaing sounds per mapblock
|
||||||
|
local function can_play(pos)
|
||||||
|
local count = currently_playing[get_key(pos)]
|
||||||
|
return not count or count < 25
|
||||||
|
end
|
||||||
|
|
||||||
|
-- register ambience sounds with node-timer
|
||||||
|
function scifi_nodes.register_ambience(nodename, soundname, opts)
|
||||||
|
assert(opts)
|
||||||
|
opts.interval = opts.interval or 60
|
||||||
|
|
||||||
|
local function play(pos)
|
||||||
|
minetest.sound_play(soundname ,{
|
||||||
|
max_hear_distance = opts.max_hear_distance or 16,
|
||||||
|
pos = pos,
|
||||||
|
gain = opts.gain or 0.7
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.override_item(nodename, {
|
||||||
|
on_timer = function(pos)
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
|
||||||
|
if not can_play(pos) then
|
||||||
|
-- too many sounds playing, recheck again soon
|
||||||
|
timer:start(1)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- increment usage count
|
||||||
|
add_currently_playing(pos, 1)
|
||||||
|
play(pos)
|
||||||
|
|
||||||
|
-- restart timer
|
||||||
|
timer:start(opts.interval)
|
||||||
|
end,
|
||||||
|
on_construct = function(pos)
|
||||||
|
play(pos)
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
timer:start(opts.interval)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
1
init.lua
1
init.lua
@ -20,6 +20,7 @@ if minetest.get_modpath("default") then
|
|||||||
dofile(MP.."/chest.lua")
|
dofile(MP.."/chest.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dofile(MP.."/ambience.lua")
|
||||||
dofile(MP.."/plants.lua")
|
dofile(MP.."/plants.lua")
|
||||||
dofile(MP.."/models.lua")
|
dofile(MP.."/models.lua")
|
||||||
dofile(MP.."/nodes.lua")
|
dofile(MP.."/nodes.lua")
|
||||||
|
21
nodes.json
21
nodes.json
@ -25,7 +25,12 @@
|
|||||||
"texture_name": "white2"
|
"texture_name": "white2"
|
||||||
},
|
},
|
||||||
"engine": {
|
"engine": {
|
||||||
"description": "Engine"
|
"description": "Engine",
|
||||||
|
"ambience": {
|
||||||
|
"scifi_nodes_ambience_engine": {
|
||||||
|
"interval": 16.1
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"wall": {
|
"wall": {
|
||||||
"description": "metal wall"
|
"description": "metal wall"
|
||||||
@ -58,7 +63,12 @@
|
|||||||
"description": "transparent vent",
|
"description": "transparent vent",
|
||||||
"texture_name": "vent2",
|
"texture_name": "vent2",
|
||||||
"texture_modifier": "^[makealpha:33,33,33",
|
"texture_modifier": "^[makealpha:33,33,33",
|
||||||
"drawtype": "glasslike"
|
"drawtype": "glasslike",
|
||||||
|
"ambience": {
|
||||||
|
"scifi_nodes_ambience_vent": {
|
||||||
|
"interval": 4.2
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"stripes": {
|
"stripes": {
|
||||||
"description": "hazard stripes",
|
"description": "hazard stripes",
|
||||||
@ -261,7 +271,12 @@
|
|||||||
"light": 5
|
"light": 5
|
||||||
},
|
},
|
||||||
"fan": {
|
"fan": {
|
||||||
"description": "Fan"
|
"description": "Fan",
|
||||||
|
"ambience": {
|
||||||
|
"scifi_nodes_ambience_fan": {
|
||||||
|
"interval": 7
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"ppllght": {
|
"ppllght": {
|
||||||
"description": "Purple wall light",
|
"description": "Purple wall light",
|
||||||
|
@ -537,7 +537,8 @@ for name, def in pairs(nodes) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- register node
|
-- register node
|
||||||
minetest.register_node("scifi_nodes:"..name, node_def)
|
local nodename = "scifi_nodes:" .. name
|
||||||
|
minetest.register_node(nodename , node_def)
|
||||||
|
|
||||||
-- unified dyes registration
|
-- unified dyes registration
|
||||||
if def.colorable and has_unifieddyes_mod then
|
if def.colorable and has_unifieddyes_mod then
|
||||||
@ -574,6 +575,12 @@ for name, def in pairs(nodes) do
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if def.ambience then
|
||||||
|
for soundname, opts in pairs(def.ambience) do
|
||||||
|
scifi_nodes.register_ambience(nodename, soundname, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- advtrains platform registration
|
-- advtrains platform registration
|
||||||
if has_advtrains_mod and def.advtrains_platform then
|
if has_advtrains_mod and def.advtrains_platform then
|
||||||
advtrains.register_platform("scifi_nodes", "scifi_nodes:" .. name)
|
advtrains.register_platform("scifi_nodes", "scifi_nodes:" .. name)
|
||||||
|
BIN
sounds/scifi_nodes_ambience_engine.ogg
Normal file
BIN
sounds/scifi_nodes_ambience_engine.ogg
Normal file
Binary file not shown.
BIN
sounds/scifi_nodes_ambience_fan.ogg
Normal file
BIN
sounds/scifi_nodes_ambience_fan.ogg
Normal file
Binary file not shown.
BIN
sounds/scifi_nodes_ambience_vent.ogg
Normal file
BIN
sounds/scifi_nodes_ambience_vent.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user