Skip to content

Commit

Permalink
save files now track audio
Browse files Browse the repository at this point in the history
  • Loading branch information
ajusa committed Jan 3, 2021
1 parent c6340ac commit 0f594d3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/audio.moon
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
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
if exists(@path) and @n != 0
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

0 comments on commit 0f594d3

Please sign in to comment.