Add music manager

This commit is contained in:
Pyrex 2024-02-11 20:18:01 -08:00
parent da41929613
commit 3b9c61329b
5 changed files with 26 additions and 3 deletions

View File

@ -33,6 +33,15 @@ end
function completion_tracker:advance_completion_level(clevel)
dset(0,max(dget(0), clevel))
end
function completion_tracker:get_music_preference()
return dget(59)==0
end
function completion_tracker:set_music_preference()
if (dget(59)==0) dset(59,1) return
dset(59,0)
end
-- TODO: Bitfield instead
function completion_tracker:mark_seen(text_id)
local ix,bit=self:_unpack_text_id(text_id)

View File

@ -2,7 +2,6 @@ main={}
add(modules,main)
function main:init()
music(0)
extcmd("rec")
self.state_manager=state_manager:new() -- instantiate one global
self.state_manager:push(state_menu:new())

View File

@ -14,6 +14,7 @@ __lua__
#include layout.lua
#include layout_hint.lua
#include liturgy.lua
#include music_manager.lua
#include ruleset.lua
#include palette.lua
#include progression.lua

10
music_manager.lua Normal file
View File

@ -0,0 +1,10 @@
music_manager={}
add(modules,music_manager)
function music_manager:init()
end
function music_manager:update()
local is_playing = stat(54) != -1
local should_be_playing = completion_tracker:get_music_preference()
if (is_playing and not should_be_playing) music(-1,500)
if (not is_playing and should_be_playing) music(0)
end

View File

@ -10,8 +10,12 @@ function state_menu:init()
main.state_manager:push(state_archaeology:new())
end),
menu_option:new(),
menu_option:new(function() return "music" end,function()
-- todo: music manager
menu_option:new(function()
local pref=completion_tracker:get_music_preference()
if (pref) return "stop music"
return "start music"
end,function()
completion_tracker:set_music_preference(not completion_tracker:get_music_preference())
end),
menu_option:new(function() return "reset data" end,function()
main.state_manager:push(state_reset_menu:new(self))