Add music player particles
This commit is contained in:
parent
1907498899
commit
bdd5b68ac3
@ -7,17 +7,56 @@ local S = minetest.get_translator("rp_music")
|
|||||||
local INFOTEXT_ON = S("Music Player (on)")
|
local INFOTEXT_ON = S("Music Player (on)")
|
||||||
local INFOTEXT_OFF = S("Music Player (off)")
|
local INFOTEXT_OFF = S("Music Player (off)")
|
||||||
local INFOTEXT_DISABLED = S("Music Player (disabled by server)")
|
local INFOTEXT_DISABLED = S("Music Player (disabled by server)")
|
||||||
|
local NOTES_PER_SECOND = 1
|
||||||
|
|
||||||
local music = {}
|
local music = {}
|
||||||
|
local particlespawners = {}
|
||||||
|
|
||||||
music.tracks = {
|
music.tracks = {
|
||||||
{ name = "music_catsong", length = 30.0 },
|
{ name = "music_catsong", length = 30.0, note_color = "#26b7dc", },
|
||||||
{ name = "music_greyarms", length = 82.0 },
|
{ name = "music_greyarms", length = 82.0, note_color = "#d8cb2b", },
|
||||||
}
|
}
|
||||||
|
|
||||||
music.volume = tonumber(minetest.settings:get("music_volume")) or 1.0
|
music.volume = tonumber(minetest.settings:get("music_volume")) or 1.0
|
||||||
music.volume = math.max(0.0, math.min(1.0, music.volume))
|
music.volume = math.max(0.0, math.min(1.0, music.volume))
|
||||||
|
|
||||||
|
|
||||||
|
local function note_particle(pos, texture, permanent)
|
||||||
|
local amount, time
|
||||||
|
if permanent then
|
||||||
|
amount = NOTES_PER_SECOND
|
||||||
|
time = 0
|
||||||
|
else
|
||||||
|
amount = 1
|
||||||
|
time = 0.01
|
||||||
|
end
|
||||||
|
return minetest.add_particlespawner({
|
||||||
|
amount = amount,
|
||||||
|
time = time,
|
||||||
|
pos = vector.add(pos, vector.new(0,-0.25,0)),
|
||||||
|
vel = vector.new(0, 1, 0),
|
||||||
|
exptime = 0.5,
|
||||||
|
size = 2,
|
||||||
|
drag = vector.new(2,2,2),
|
||||||
|
texture = {
|
||||||
|
name = texture,
|
||||||
|
alpha_tween = { 1, 0, start = 0.6 },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_note(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local track = meta:get_int("music_player_track")
|
||||||
|
local note = "rp_music_note.png"
|
||||||
|
local note_color
|
||||||
|
if music.tracks[track] then
|
||||||
|
note_color = music.tracks[track].note_color
|
||||||
|
note = note .. "^[multiply:"..note_color
|
||||||
|
end
|
||||||
|
return note
|
||||||
|
end
|
||||||
|
|
||||||
-- Array of music players
|
-- Array of music players
|
||||||
|
|
||||||
music.players = {}
|
music.players = {}
|
||||||
@ -34,6 +73,12 @@ if minetest.settings:get_bool("music_enable") then
|
|||||||
minetest.sound_stop(music.players[dp]["handle"])
|
minetest.sound_stop(music.players[dp]["handle"])
|
||||||
music.players[dp] = nil
|
music.players[dp] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local id = particlespawners[dp]
|
||||||
|
if id then
|
||||||
|
minetest.delete_particlespawner(id)
|
||||||
|
particlespawners[dp] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function music.start(pos)
|
function music.start(pos)
|
||||||
@ -71,6 +116,18 @@ if minetest.settings:get_bool("music_enable") then
|
|||||||
gain = music.volume,
|
gain = music.volume,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Spawn a single note immediately
|
||||||
|
local note = get_note(pos)
|
||||||
|
note_particle(pos, note)
|
||||||
|
|
||||||
|
-- Spawn a permanent particlespawner
|
||||||
|
if particlespawners[dp] then
|
||||||
|
-- Replace old particlespawener, if present
|
||||||
|
minetest.delete_particlespawner(particlespawners[dp])
|
||||||
|
end
|
||||||
|
local particle = note_particle(pos, note, true)
|
||||||
|
particlespawners[dp] = particle
|
||||||
end
|
end
|
||||||
|
|
||||||
function music.update(pos)
|
function music.update(pos)
|
||||||
@ -101,8 +158,10 @@ if minetest.settings:get_bool("music_enable") then
|
|||||||
|
|
||||||
if music.players[dp] == nil then
|
if music.players[dp] == nil then
|
||||||
music.start(pos)
|
music.start(pos)
|
||||||
|
return true
|
||||||
else
|
else
|
||||||
music.stop(pos)
|
music.stop(pos)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -207,6 +266,14 @@ else
|
|||||||
|
|
||||||
meta:set_string("infotext", INFOTEXT_DISABLED)
|
meta:set_string("infotext", INFOTEXT_DISABLED)
|
||||||
end,
|
end,
|
||||||
|
on_rightclick = function(pos, node, clicker)
|
||||||
|
if minetest.is_protected(pos, clicker:get_player_name()) and
|
||||||
|
not minetest.check_player_privs(clicker, "protection_bypass") then
|
||||||
|
minetest.record_protection_violation(pos, clicker:get_player_name())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
note_particle(pos, "rp_music_no_music.png")
|
||||||
|
end,
|
||||||
|
|
||||||
groups = {oddly_breakable_by_hand = 3, attached_node = 1, interactive_node = 1}
|
groups = {oddly_breakable_by_hand = 3, attached_node = 1, interactive_node = 1}
|
||||||
})
|
})
|
||||||
@ -221,18 +288,22 @@ crafting.register_craft(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Update nodes after the rename orgy after 1.5.3
|
-- Update music player infotexts
|
||||||
minetest.register_lbm(
|
minetest.register_lbm(
|
||||||
{
|
{
|
||||||
label = "Update music players",
|
label = "Update music players",
|
||||||
name = "rp_music:update_music_players",
|
name = "rp_music:update_music_players",
|
||||||
|
run_at_every_load = true,
|
||||||
nodenames = {"rp_music:player"},
|
nodenames = {"rp_music:player"},
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local def = minetest.registered_nodes[node.name]
|
local def = minetest.registered_nodes[node.name]
|
||||||
if minetest.settings:get_bool("music_enable") then
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
if minetest.settings:get_bool("music_enable") then
|
||||||
if meta:get_int("music_player_enabled") == 1 then
|
if meta:get_int("music_player_enabled") == 1 then
|
||||||
meta:set_string("infotext", INFOTEXT_ON)
|
meta:set_string("infotext", INFOTEXT_ON)
|
||||||
|
local particle = note_particle(pos, get_note(pos), true)
|
||||||
|
local hash = minetest.hash_node_position(pos)
|
||||||
|
particlespawners[hash] = particle
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", INFOTEXT_OFF)
|
meta:set_string("infotext", INFOTEXT_OFF)
|
||||||
end
|
end
|
||||||
|
BIN
mods/rp_music/textures/rp_music_no_music.png
Normal file
BIN
mods/rp_music/textures/rp_music_no_music.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 687 B |
BIN
mods/rp_music/textures/rp_music_note.png
Normal file
BIN
mods/rp_music/textures/rp_music_note.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 630 B |
Loading…
x
Reference in New Issue
Block a user