From 0f594d3f0c6aa9c19a7ce3adc6435a590bd8135a Mon Sep 17 00:00:00 2001 From: Arham Jain Date: Sun, 3 Jan 2021 11:36:20 -0500 Subject: [PATCH] save files now track audio --- src/audio.moon | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/audio.moon b/src/audio.moon index 2459956..4b33de8 100644 --- a/src/audio.moon +++ b/src/audio.moon @@ -1,9 +1,17 @@ -sound = nil -music = nil +sound = {} +music = {} +on "save", => + @music = {path: music.path} + @sound = {path: sound.path, n: sound.n} + +on "restore", => + if @music and @sound + if @music.path then dispatch "music", @music + if @sound.path then dispatch "sound", @sound clear = => - if @ != nil + if next(@) @file\stop! - @ = nil + @ = {} exists = => @\sub(-1) != "~" on "sound", => clear sound @@ -11,15 +19,15 @@ on "sound", => file = with love.audio.newSource(@path, "stream") \setLooping(@n == -1) \play! - sound = {:file, n: @n or 0} + sound = {path: @path, :file, n: @n or 0} on "music", => clear music if exists @path file = with love.audio.newSource(@path, "stream") \setLooping(true) \play! - music = {:file} + music = {path: @path, :file} on "update", -> - if sound != nil and not sound.file\isPlaying! and sound.n > 1 + if next(sound) and not sound.file\isPlaying! and sound.n > 1 sound.file\play! sound.n -= 1