Music player selects random music on placement
This commit is contained in:
parent
e5b0a9183d
commit
55f5a54c29
@ -7,8 +7,11 @@ local S = minetest.get_translator("music")
|
|||||||
|
|
||||||
music = {}
|
music = {}
|
||||||
|
|
||||||
music.default_track = minetest.settings:get("music_track") or "music_catsong"
|
music.tracks = {
|
||||||
music.track_length = tonumber(minetest.settings:get("music_track_length")) or 30.0
|
{ name = "music_catsong", length = 30.0 },
|
||||||
|
{ name = "music_greyarms", length = 82.0 },
|
||||||
|
}
|
||||||
|
|
||||||
music.volume = tonumber(minetest.settings:get("music_volume")) or 1.0
|
music.volume = tonumber(minetest.settings:get("music_volume")) or 1.0
|
||||||
|
|
||||||
-- Array of music players
|
-- Array of music players
|
||||||
@ -36,10 +39,17 @@ if minetest.settings:get_bool("music_enable") then
|
|||||||
meta:set_string("infotext", S("Music Player (on)"))
|
meta:set_string("infotext", S("Music Player (on)"))
|
||||||
meta:set_int("music_player_enabled", 1)
|
meta:set_int("music_player_enabled", 1)
|
||||||
|
|
||||||
|
-- Get track or set random track if not set
|
||||||
|
local track = meta:get_int("music_player_track")
|
||||||
|
if track == nil or not music.tracks[track] then
|
||||||
|
track = math.random(1, #music.tracks)
|
||||||
|
meta:set_int("music_player_track", track)
|
||||||
|
end
|
||||||
|
|
||||||
if music.players[dp] == nil then
|
if music.players[dp] == nil then
|
||||||
music.players[dp] = {
|
music.players[dp] = {
|
||||||
["handle"] = minetest.sound_play(
|
["handle"] = minetest.sound_play(
|
||||||
music.default_track,
|
music.tracks[track].name,
|
||||||
{
|
{
|
||||||
pos = pos,
|
pos = pos,
|
||||||
gain = music.volume,
|
gain = music.volume,
|
||||||
@ -51,7 +61,7 @@ if minetest.settings:get_bool("music_enable") then
|
|||||||
music.players[dp]["timer"] = 0
|
music.players[dp]["timer"] = 0
|
||||||
minetest.sound_stop(music.players[dp]["handle"])
|
minetest.sound_stop(music.players[dp]["handle"])
|
||||||
music.players[dp]["handle"] = minetest.sound_play(
|
music.players[dp]["handle"] = minetest.sound_play(
|
||||||
music.default_track,
|
music.tracks[track].name,
|
||||||
{
|
{
|
||||||
pos = pos,
|
pos = pos,
|
||||||
gain = music.volume,
|
gain = music.volume,
|
||||||
@ -71,11 +81,16 @@ if minetest.settings:get_bool("music_enable") then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if music.players[dp]["timer"] > music.track_length then
|
local meta = minetest.get_meta(pos)
|
||||||
|
local track = meta:get_int("music_player_track")
|
||||||
|
|
||||||
|
if music.tracks[track] then
|
||||||
|
if music.players[dp]["timer"] > music.tracks[track].length then
|
||||||
music.start(pos)
|
music.start(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function music.toggle(pos)
|
function music.toggle(pos)
|
||||||
local dp = minetest.hash_node_position(pos)
|
local dp = minetest.hash_node_position(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user