1
0
Fork 0
mirror of https://gitlab.com/niansa/storybuilder.git synced 2025-03-06 20:48:28 +01:00

Add background music support

This commit is contained in:
Nils 2019-10-03 13:24:31 +02:00
parent 6838a11af8
commit 8a9cdb8f5b
5 changed files with 32 additions and 3 deletions

18
mods/bgmusic/init.lua Normal file
View file

@ -0,0 +1,18 @@
-- This is just an API
bgmusic = {}
local pmusic = {}
function bgmusic.play(name, sound)
if sound ~= nil then
pmusic[name] = minetest.sound_play(sound, {to_player=name, gain=0.75, loop=true})
return true
end
return false
end
function bgmusic.stop(name)
if pmusic[name] then
minetest.sound_stop(pmusic[name])
return true
end
return false
end

View file

@ -0,0 +1,4 @@
minetest.register_globalstep(function(dtime)
local objects = minetest.object_refs
for id, object in pairs(objects) do
local relpos = object:get_pos()

View file

@ -5,6 +5,7 @@ local modpath = minetest.get_modpath("story")
dofile(modpath.."/schem.lua")
dofile(modpath.."/checkpoint_api.lua")
dofile(modpath.."/stage_api.lua")
dofile(modpath.."/globalsteps.lua")
dofile(modpath.."/nodes.lua")
dofile(modpath.."/borders.lua")

View file

@ -1,7 +1,5 @@
local modpath = minetest.get_modpath("story")
local worldpath = minetest.get_worldpath()
spos = {}
lspos = {}
-- round
function story.get_random_pos()
@ -31,8 +29,11 @@ function story.reload_stage(name, continuation)
minetest.chat_send_player(name, "Not reloading stage as reload is disabled")
return false
end
spos = {}
local stage = storybase.get_stage(name)
local object = minetest.get_player_by_name(name)
-- Stop playing music
bgmusic.stop(name)
-- Get stage positions
storybase.debugmsg(name, "Loading stage " .. stage .. "...")
if not story.get_stage(stage) then
@ -59,5 +60,10 @@ function story.reload_stage(name, continuation)
story.stagepos[name] = { x = spos.x, y = spos.y, z = spos.z }
-- Remove loading screen
player.texhud_remove(object, loadinghud, true)
-- Start playing music
bgmusic.play(name, music)
-- Clean up variables
-- spos = nil (TODO: find out why this is causing weeird bugs)
music = nil
return true
end

View file

@ -1,7 +1,7 @@
buildmode = false
noreload = false
allow_cheating = minetest.is_singleplayer()
debugmsgs = true
debugmsgs = false
defaultprivs = {
interact = true,
shout = true,