Rename mod: mpd → tutorial_music
This commit is contained in:
parent
288ec1a5da
commit
cb1cee225c
@ -1 +0,0 @@
|
||||
name = mpd
|
@ -28,7 +28,7 @@ function default.get_hotbar_bg(x,y)
|
||||
end
|
||||
|
||||
local music = ""
|
||||
if minetest.get_modpath("mpd") then
|
||||
if minetest.get_modpath("tutorial_music") then
|
||||
music = "button[-0.1,0.7;3,1;togglemusic;"..minetest.formspec_escape(S("Toggle music")).."]"
|
||||
end
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
name = tutorial_default
|
||||
optional_depends = intllib
|
||||
optional_depends = intllib, tutorial_music
|
||||
|
@ -1,46 +1,46 @@
|
||||
|
||||
mpd={}
|
||||
tutorial_music={}
|
||||
|
||||
--config
|
||||
mpd.pause_between_songs=7
|
||||
tutorial_music.pause_between_songs=7
|
||||
|
||||
--end config
|
||||
|
||||
mpd.modpath=minetest.get_modpath("mpd")
|
||||
if not mpd.modpath then
|
||||
error("mpd mod folder has to be named 'mpd'!")
|
||||
tutorial_music.modpath=minetest.get_modpath("tutorial_music")
|
||||
if not tutorial_music.modpath then
|
||||
error("mod folder has to be named 'tutorial_music'!")
|
||||
end
|
||||
--{name, length, gain~1}
|
||||
mpd.songs = {}
|
||||
local sfile, sfileerr=io.open(mpd.modpath.."/songs.txt")
|
||||
tutorial_music.songs = {}
|
||||
local sfile, sfileerr=io.open(tutorial_music.modpath.."/songs.txt")
|
||||
if not sfile then error("Error opening songs.txt: "..sfileerr) end
|
||||
for line in sfile:lines() do
|
||||
if line~="" and line[1]~="#" then
|
||||
local name, timeMinsStr, timeSecsStr, gainStr = string.match(line, "^(%S+)%s+(%d+):([%d%.]+)%s+([%d%.]+)$")
|
||||
local timeMins, timeSecs, gain = tonumber(timeMinsStr), tonumber(timeSecsStr), tonumber(gainStr)
|
||||
if name and timeMins and timeSecs and gain then
|
||||
mpd.songs[#mpd.songs+1]={name=name, length=timeMins*60+timeSecs, lengthhr=timeMinsStr..":"..timeSecsStr, gain=gain}
|
||||
tutorial_music.songs[#tutorial_music.songs+1]={name=name, length=timeMins*60+timeSecs, lengthhr=timeMinsStr..":"..timeSecsStr, gain=gain}
|
||||
else
|
||||
minetest.log("warning", "[mpd] Misformatted song entry in songs.txt: "..line)
|
||||
minetest.log("warning", "[tutorial_music] Misformatted song entry in songs.txt: "..line)
|
||||
end
|
||||
end
|
||||
end
|
||||
sfile:close()
|
||||
|
||||
if #mpd.songs==0 then
|
||||
print("[mpd]no songs registered, not doing anything")
|
||||
if #tutorial_music.songs==0 then
|
||||
minetest.log("error", "[tutorial_music] no songs registered, not doing anything")
|
||||
return
|
||||
end
|
||||
|
||||
mpd.storage = minetest.get_mod_storage()
|
||||
tutorial_music.storage = minetest.get_mod_storage()
|
||||
|
||||
mpd.handles={}
|
||||
tutorial_music.handles={}
|
||||
|
||||
mpd.playing=false
|
||||
mpd.id_playing=nil
|
||||
mpd.song_time_left=nil
|
||||
mpd.time_next=10 --sekunden
|
||||
mpd.id_last_played=nil
|
||||
tutorial_music.playing=false
|
||||
tutorial_music.id_playing=nil
|
||||
tutorial_music.song_time_left=nil
|
||||
tutorial_music.time_next=10 --sekunden
|
||||
tutorial_music.id_last_played=nil
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local meta = player:get_meta()
|
||||
@ -52,131 +52,131 @@ minetest.register_on_joinplayer(function(player)
|
||||
play = false
|
||||
end
|
||||
if play then
|
||||
mpd.next_song()
|
||||
tutorial_music.next_song()
|
||||
else
|
||||
mpd.stop_song()
|
||||
tutorial_music.stop_song()
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if mpd.playing then
|
||||
if mpd.song_time_left<=0 then
|
||||
mpd.stop_song()
|
||||
mpd.time_next=mpd.pause_between_songs
|
||||
if tutorial_music.playing then
|
||||
if tutorial_music.song_time_left<=0 then
|
||||
tutorial_music.stop_song()
|
||||
tutorial_music.time_next=tutorial_music.pause_between_songs
|
||||
else
|
||||
mpd.song_time_left=mpd.song_time_left-dtime
|
||||
tutorial_music.song_time_left=tutorial_music.song_time_left-dtime
|
||||
end
|
||||
elseif mpd.time_next then
|
||||
if mpd.time_next<=0 then
|
||||
mpd.next_song()
|
||||
elseif tutorial_music.time_next then
|
||||
if tutorial_music.time_next<=0 then
|
||||
tutorial_music.next_song()
|
||||
else
|
||||
mpd.time_next=mpd.time_next-dtime
|
||||
tutorial_music.time_next=tutorial_music.time_next-dtime
|
||||
end
|
||||
end
|
||||
end)
|
||||
mpd.play_song=function(id)
|
||||
if mpd.playing then
|
||||
mpd.stop_song()
|
||||
tutorial_music.play_song=function(id)
|
||||
if tutorial_music.playing then
|
||||
tutorial_music.stop_song()
|
||||
end
|
||||
local song=mpd.songs[id]
|
||||
local song=tutorial_music.songs[id]
|
||||
if not song then return end
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local pname=player:get_player_name()
|
||||
local pvolume=tonumber(mpd.storage:get_string("vol_"..pname))
|
||||
local pvolume=tonumber(tutorial_music.storage:get_string("vol_"..pname))
|
||||
if not pvolume then pvolume=1 end
|
||||
if pvolume>0 then
|
||||
local handle = minetest.sound_play(song.name, {to_player=pname, gain=song.gain*pvolume})
|
||||
if handle then
|
||||
mpd.handles[pname]=handle
|
||||
tutorial_music.handles[pname]=handle
|
||||
end
|
||||
end
|
||||
end
|
||||
mpd.playing=id
|
||||
tutorial_music.playing=id
|
||||
--adding 2 seconds as security
|
||||
mpd.song_time_left = song.length + 2
|
||||
tutorial_music.song_time_left = song.length + 2
|
||||
end
|
||||
mpd.stop_song=function()
|
||||
for pname, handle in pairs(mpd.handles) do
|
||||
tutorial_music.stop_song=function()
|
||||
for pname, handle in pairs(tutorial_music.handles) do
|
||||
minetest.sound_stop(handle)
|
||||
end
|
||||
mpd.id_last_played=mpd.playing
|
||||
mpd.playing=nil
|
||||
mpd.handles={}
|
||||
mpd.time_next=nil
|
||||
tutorial_music.id_last_played=tutorial_music.playing
|
||||
tutorial_music.playing=nil
|
||||
tutorial_music.handles={}
|
||||
tutorial_music.time_next=nil
|
||||
end
|
||||
|
||||
mpd.next_song=function()
|
||||
tutorial_music.next_song=function()
|
||||
local next
|
||||
repeat
|
||||
next=math.random(1,#mpd.songs)
|
||||
until #mpd.songs==1 or next~=mpd.id_last_played
|
||||
mpd.play_song(next)
|
||||
next=math.random(1,#tutorial_music.songs)
|
||||
until #tutorial_music.songs==1 or next~=tutorial_music.id_last_played
|
||||
tutorial_music.play_song(next)
|
||||
end
|
||||
|
||||
mpd.song_human_readable=function(id)
|
||||
local song=mpd.songs[id]
|
||||
tutorial_music.song_human_readable=function(id)
|
||||
local song=tutorial_music.songs[id]
|
||||
return id..": "..song.name.." ["..song.lengthhr.."]"
|
||||
end
|
||||
|
||||
minetest.register_privilege("mpd", "may control the music player daemon (mpd) mod")
|
||||
minetest.register_privilege("mpd", "May control the music")
|
||||
|
||||
minetest.register_chatcommand("mpd_stop", {
|
||||
minetest.register_chatcommand("music_stop", {
|
||||
params = "",
|
||||
description = "Stop the song currently playing",
|
||||
privs = {mpd=true},
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
player:get_meta():set_string("play_music", "0")
|
||||
mpd.stop_song()
|
||||
tutorial_music.stop_song()
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("mpd_list", {
|
||||
minetest.register_chatcommand("music_list", {
|
||||
params = "",
|
||||
description = "List all available songs and their IDs",
|
||||
privs = {mpd=true},
|
||||
func = function(name, param)
|
||||
for k,v in ipairs(mpd.songs) do
|
||||
minetest.chat_send_player(name, mpd.song_human_readable(k))
|
||||
for k,v in ipairs(tutorial_music.songs) do
|
||||
minetest.chat_send_player(name, tutorial_music.song_human_readable(k))
|
||||
end
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("mpd_play", {
|
||||
minetest.register_chatcommand("music_play", {
|
||||
params = "<id>",
|
||||
description = "Play the songs with the given ID (see ids with /mpd_list)",
|
||||
description = "Play the songs with the given ID (see IDs with /music_list)",
|
||||
privs = {mpd=true},
|
||||
func = function(name, param)
|
||||
id=tonumber(param)
|
||||
if id and id>0 and id<=#mpd.songs then
|
||||
if id and id>0 and id<=#tutorial_music.songs then
|
||||
local player = minetest.get_player_by_name(name)
|
||||
player:get_meta():set_string("play_music", "1")
|
||||
mpd.play_song(id)
|
||||
return true,"Playing: "..mpd.song_human_readable(id)
|
||||
tutorial_music.play_song(id)
|
||||
return true,"Playing: "..tutorial_music.song_human_readable(id)
|
||||
end
|
||||
return false, "Invalid song ID!"
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("mpd_what", {
|
||||
minetest.register_chatcommand("music_what", {
|
||||
params = "",
|
||||
description = "Display the currently played song.",
|
||||
privs = {mpd=true},
|
||||
func = function(name, param)
|
||||
if not mpd.playing then return true,"Nothing playing, "..math.floor(mpd.time_next or 0).." sec. left until next song." end
|
||||
return true,"Playing: "..mpd.song_human_readable(mpd.playing).."\nTime Left: "..math.floor(mpd.song_time_left or 0).." sec."
|
||||
if not tutorial_music.playing then return true,"Nothing playing, "..math.floor(tutorial_music.time_next or 0).." sec. left until next song." end
|
||||
return true,"Playing: "..tutorial_music.song_human_readable(tutorial_music.playing).."\nTime left: "..math.floor(tutorial_music.song_time_left or 0).." sec."
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("mpd_next", {
|
||||
minetest.register_chatcommand("music_next", {
|
||||
params = "[seconds]",
|
||||
description = "Start the next song, either immediately (no parameters) or after n seconds.",
|
||||
privs = {mpd=true},
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
player:get_meta():set_string("play_music", "1")
|
||||
mpd.stop_song()
|
||||
tutorial_music.stop_song()
|
||||
if param and tonumber(param) then
|
||||
mpd.time_next=tonumber(param)
|
||||
tutorial_music.time_next=tonumber(param)
|
||||
return true,"Next song in "..param.." seconds!"
|
||||
else
|
||||
mpd.next_song()
|
||||
tutorial_music.next_song()
|
||||
return true,"Next song started!"
|
||||
end
|
||||
end,
|
||||
@ -187,13 +187,13 @@ minetest.register_chatcommand("mvolume", {
|
||||
privs = {},
|
||||
func = function(pname, param)
|
||||
if not param or param=="" then
|
||||
local pvolume=tonumber(mpd.storage:get_string("vol_"..pname))
|
||||
local pvolume=tonumber(tutorial_music.storage:get_string("vol_"..pname))
|
||||
if not pvolume then pvolume=1 end
|
||||
if pvolume>0 then
|
||||
return true, "Your music volume is set to "..pvolume.."."
|
||||
else
|
||||
if mpd.handles[pname] then
|
||||
minetest.sound_stop(mpd.handles[pname])
|
||||
if tutorial_music.handles[pname] then
|
||||
minetest.sound_stop(tutorial_music.handles[pname])
|
||||
end
|
||||
return true, "Background music is disabled for you. Use '/mvolume 1' to enable it again."
|
||||
end
|
||||
@ -204,12 +204,12 @@ minetest.register_chatcommand("mvolume", {
|
||||
end
|
||||
pvolume = math.min(pvolume, 1)
|
||||
pvolume = math.max(pvolume, 0)
|
||||
mpd.storage:set_string("vol_"..pname, pvolume)
|
||||
tutorial_music.storage:set_string("vol_"..pname, pvolume)
|
||||
if pvolume>0 then
|
||||
return true, "Music volume set to "..pvolume..". Change will take effect when the next song starts."
|
||||
else
|
||||
if mpd.handles[pname] then
|
||||
minetest.sound_stop(mpd.handles[pname])
|
||||
if tutorial_music.handles[pname] then
|
||||
minetest.sound_stop(tutorial_music.handles[pname])
|
||||
end
|
||||
return true, "Disabled background music for you. Use /mvol to enable it again."
|
||||
end
|
||||
@ -218,11 +218,11 @@ minetest.register_chatcommand("mvolume", {
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if(fields.togglemusic) then
|
||||
if mpd.playing then
|
||||
mpd.stop_song()
|
||||
if tutorial_music.playing then
|
||||
tutorial_music.stop_song()
|
||||
player:get_meta():set_string("play_music", "0")
|
||||
else
|
||||
mpd.next_song()
|
||||
tutorial_music.next_song()
|
||||
player:get_meta():set_string("play_music", "1")
|
||||
end
|
||||
end
|
1
mods/tutorial_music/mod.conf
Normal file
1
mods/tutorial_music/mod.conf
Normal file
@ -0,0 +1 @@
|
||||
name = tutorial_music
|
@ -1,7 +1,9 @@
|
||||
|
||||
### mpd Mod for Minetest
|
||||
(c) 2017 orwell96
|
||||
Slightly modified for the Tutorial.
|
||||
### Tutorial music mod
|
||||
|
||||
Based on the MPD mod ((c) 2017 orwell96)
|
||||
|
||||
Modified for the Tutorial.
|
||||
|
||||
This mod is licensed under the MIT License.
|
||||
|
@ -103,11 +103,11 @@ minetest.register_node("tutorial_supplemental:loudspeaker", {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = set_loudspeaker_infotext,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if mpd.playing then
|
||||
mpd.stop_song()
|
||||
if tutorial_music.playing then
|
||||
tutorial_music.stop_song()
|
||||
clicker:get_meta():set_string("play_music", "0")
|
||||
else
|
||||
mpd.next_song()
|
||||
tutorial_music.next_song()
|
||||
clicker:get_meta():set_string("play_music", "1")
|
||||
end
|
||||
end,
|
||||
|
@ -1,3 +1,3 @@
|
||||
name = tutorial_supplemental
|
||||
depends = tutorial_default, mpd
|
||||
depends = tutorial_default, tutorial_music
|
||||
optional_depends = intllib
|
||||
|
Loading…
x
Reference in New Issue
Block a user