Toggle sound traveler display.
parent
745dd67051
commit
5a915d0c2f
198
init.lua
198
init.lua
|
@ -3,6 +3,8 @@
|
|||
-- GPL3+
|
||||
gen_music = {}
|
||||
|
||||
local show_st = minetest.settings:get_bool("show_sound_traveler")
|
||||
|
||||
gen_music.songs = {}
|
||||
local mod_name = minetest.get_current_modname()
|
||||
local mod_path = minetest.get_modpath(mod_name)
|
||||
|
@ -99,82 +101,6 @@ for i = 1, #extra_sounds do
|
|||
end
|
||||
end
|
||||
|
||||
-- Sound Traveller
|
||||
local ps = function(pos)
|
||||
if math.random() < 0.8 then
|
||||
return
|
||||
end
|
||||
local s = -1
|
||||
if math.random() > 0.5 then
|
||||
s = 1
|
||||
end
|
||||
minetest.add_particle({
|
||||
pos = {
|
||||
x = math.random() * s + pos.x,
|
||||
y = math.random() * s + pos.y,
|
||||
z = math.random() * s + pos.z
|
||||
},
|
||||
velocity = {
|
||||
x = math.random() * s,
|
||||
y = math.random() * s,
|
||||
z = math.random() * s
|
||||
},
|
||||
acceleration = {
|
||||
x = math.random() * s,
|
||||
y = math.random() * s,
|
||||
z = math.random() * s
|
||||
},
|
||||
expirationtime = 1,
|
||||
size = 2,
|
||||
texture = "xdecor_glyph" .. math.random(1, 18) .. ".png",
|
||||
})
|
||||
end
|
||||
-- if show_sound_traveller
|
||||
minetest.register_entity("gen_music:sound_traveller", {
|
||||
visual = "sprite",
|
||||
visual_size = {x = 0.5, y = 0.5},
|
||||
collisionbox = {0},
|
||||
physical = false,
|
||||
textures = {"empty.png"},--default_mese_crystal.png"},
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
--self.pos = self.object:get_pos()
|
||||
end,
|
||||
on_step = function(self, dtime)
|
||||
--ps(self.pos)
|
||||
end,
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||
end,
|
||||
on_death = function(self, killer)
|
||||
end,
|
||||
on_rightclick = function(self, clicker)
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
end,
|
||||
})
|
||||
|
||||
gen_music.gs = function(object, song, loop)
|
||||
-- TODO Generate random sequence and ensemble based on
|
||||
-- found sounds, and extra_sounds.txt.
|
||||
if type(song) == "string" then
|
||||
song = gen_music.songs[song]
|
||||
end
|
||||
--print(dump(song))
|
||||
if not song then
|
||||
return
|
||||
end
|
||||
local gain = math.random()
|
||||
if gain > 0.67 then
|
||||
gain = 0.67
|
||||
end
|
||||
local play = minetest.sound_play
|
||||
local seq = {}
|
||||
local obj = {}
|
||||
if math.random() < 0.67 then
|
||||
minetest.after(math.random(), function()
|
||||
local p_pos = object:get_pos()
|
||||
if not p_pos then
|
||||
return
|
||||
end
|
||||
local jitter = function(j, p)
|
||||
local r = math.random()
|
||||
local s = j * -1
|
||||
|
@ -191,15 +117,101 @@ gen_music.gs = function(object, song, loop)
|
|||
return p - (1 * s)
|
||||
end
|
||||
end
|
||||
|
||||
-- Sound Traveler
|
||||
local ps = function(pos)
|
||||
if math.random() < 0.8 then
|
||||
return
|
||||
end
|
||||
local s = -1
|
||||
if math.random() > 0.5 then
|
||||
s = 1
|
||||
end
|
||||
minetest.add_particle({
|
||||
pos = {
|
||||
x = jitter(math.random(), math.random() * s + pos.x),
|
||||
y = jitter(math.random(), math.random() * s + pos.y),
|
||||
z = jitter(math.random(), math.random() * s + pos.z)
|
||||
},
|
||||
velocity = {
|
||||
x = jitter(math.random(), math.random() * s),
|
||||
y = jitter(math.random(), math.random() * s),
|
||||
z = jitter(math.random(), math.random() * s)
|
||||
},
|
||||
acceleration = {
|
||||
x = jitter(math.random(), math.random() * s),
|
||||
y = jitter(math.random(), math.random() * s),
|
||||
z = jitter(math.random(), math.random() * s)
|
||||
},
|
||||
expirationtime = 1,
|
||||
size = 2,
|
||||
texture = "xdecor_glyph" .. math.random(1, 18) .. ".png",
|
||||
glow = 10,
|
||||
})
|
||||
end
|
||||
local st_textures = {"empty.png"}
|
||||
local st_on_activate = function(self, staticdata, dtime_s) end
|
||||
local st_on_step = function(self, dtime) end
|
||||
if show_st then
|
||||
print("Showing Sound Travelers")
|
||||
st_textures = {"default_mese_crystal.png"}
|
||||
st_on_activate = function(self, staticdata, dtime_s)
|
||||
self.pos = self.object:get_pos()
|
||||
end
|
||||
st_on_step = function(self, dtime)
|
||||
ps(self.pos)
|
||||
end
|
||||
end -- ^ nil these after registry?
|
||||
minetest.register_entity("gen_music:sound_traveler", {
|
||||
visual = "sprite",
|
||||
visual_size = {x = 0.5, y = 0.5},
|
||||
collisionbox = {0},
|
||||
physical = false,
|
||||
textures = st_textures,
|
||||
on_activate = st_on_activate,
|
||||
on_step = st_on_step,
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||
end,
|
||||
on_death = function(self, killer)
|
||||
end,
|
||||
on_rightclick = function(self, clicker)
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
end,
|
||||
})
|
||||
|
||||
gen_music.gs = function(object, song, loop)
|
||||
if type(song) == "string" then
|
||||
song = gen_music.songs[song]
|
||||
end
|
||||
--print(dump(song))
|
||||
if not song then
|
||||
return
|
||||
end
|
||||
local gain = math.random()
|
||||
if gain > 0.67 then
|
||||
gain = 0.67
|
||||
end
|
||||
local play = minetest.sound_play
|
||||
local seq = {}
|
||||
local obj = {}
|
||||
-- r1
|
||||
--local prob = math.random()
|
||||
--if prob < 0.67 then
|
||||
minetest.after(math.random(), function()
|
||||
local p_pos = object:get_pos()
|
||||
if not p_pos then
|
||||
return
|
||||
end
|
||||
p_pos.x = jitter(math.random(), p_pos.x)
|
||||
p_pos.y = jitter(math.random(), p_pos.y)
|
||||
p_pos.z = jitter(math.random(), p_pos.z)
|
||||
|
||||
local function play_variable(ensemble, positional)
|
||||
local function play_variable(ensemble)
|
||||
-- New object.
|
||||
local obj_idx = #obj + 1
|
||||
obj[obj_idx] = minetest.add_entity(p_pos,
|
||||
"gen_music:sound_traveller", "")
|
||||
"gen_music:sound_traveler", "")
|
||||
local o_pos = obj[obj_idx]:get_pos()
|
||||
local d = vector.direction(p_pos, o_pos)
|
||||
d.x = jitter(math.random(), d.x)
|
||||
|
@ -228,7 +240,7 @@ gen_music.gs = function(object, song, loop)
|
|||
fade = fade,
|
||||
object = obj[obj_idx],
|
||||
})
|
||||
--print("Starting " .. seq[idx])
|
||||
print("Starting " .. seq[idx])
|
||||
if fade == 1 then
|
||||
minetest.sound_fade(seq[idx], 0.1, gain)
|
||||
end
|
||||
|
@ -251,39 +263,17 @@ gen_music.gs = function(object, song, loop)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
-- `Mese Music' by jas
|
||||
--[[
|
||||
if math.random() < 0.33 then
|
||||
play_variable({"phit", "phit", "phit", "phit"})
|
||||
minetest.after(math.random(), function()
|
||||
play_variable({"phit", "phit", "walkie_blip", "xdecor_enchanting", "mobs_spell"}, true)
|
||||
end)
|
||||
end
|
||||
if math.random() > 0.33 then
|
||||
minetest.after(math.random(), function()
|
||||
play_variable({"walkie_blip", "walkie_blip", "phit"}, true)
|
||||
end)
|
||||
end
|
||||
if math.random() > 0.5 then
|
||||
minetest.after(math.random(), function()
|
||||
play_variable({"xdecor_enchanting", "phit", "walkie_blip"}, false)
|
||||
end)
|
||||
end
|
||||
--]]
|
||||
|
||||
minetest.after(math.random(), function()
|
||||
for k, v in pairs(obj) do
|
||||
v:remove()
|
||||
end
|
||||
end)
|
||||
|
||||
end)
|
||||
end
|
||||
minetest.after(math.random(), function()
|
||||
--end
|
||||
minetest.after(1 + math.random() + math.random(), function()
|
||||
for idx = 1, #seq do
|
||||
minetest.after(math.random(), function()
|
||||
--print("Stopping " .. seq[idx])
|
||||
print("Stopping " .. seq[idx])
|
||||
minetest.sound_fade(seq[idx], -0.1, 0.0)
|
||||
minetest.after(math.random(), function()
|
||||
minetest.sound_stop(seq[idx])
|
||||
|
|
Loading…
Reference in New Issue