From 2065a6b4d6acb4457c77011359627ca5f8eadb17 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Mon, 27 Mar 2023 14:13:39 +1100 Subject: [PATCH] Removed some logging and commented out code Also added a couple of comments related to the scene logic --- app/scenes/settings.rb | 2 -- app/tick.rb | 1 - app/util/music.rb | 4 ---- app/util/scene.rb | 18 ++++++++++++------ app/util/sound.rb | 38 +------------------------------------- 5 files changed, 13 insertions(+), 50 deletions(-) diff --git a/app/scenes/settings.rb b/app/scenes/settings.rb index 75be6b5..8a522d0 100644 --- a/app/scenes/settings.rb +++ b/app/scenes/settings.rb @@ -8,10 +8,8 @@ class SettingsMenu < MenuScene key: :sfx, kind: :toggle, on_select: ->(args) do - puts 'toggle sfx' GameSetting.save_after(args) do |args| args.state.setting.sfx = !args.state.setting.sfx - puts "sfx = #{args.state.setting.sfx}" end end }, diff --git a/app/tick.rb b/app/tick.rb index 56b8deb..de92bfa 100644 --- a/app/tick.rb +++ b/app/tick.rb @@ -18,7 +18,6 @@ def tick(args) Input.track_swipe(args) if mobile? - # Scene.send("tick_#{args.state.scene}", args) args.state.scene_stack.each do |scene| scene.tick(args) if scene.tick_in_background || scene == args.state.scene_stack.last end diff --git a/app/util/music.rb b/app/util/music.rb index c52d09b..9dbea91 100644 --- a/app/util/music.rb +++ b/app/util/music.rb @@ -49,15 +49,11 @@ module Music queue.each do |channel, value| unless value.empty? if args.audio["MUSIC_CHANNEL_#{channel}"] - puts "THERE'S MUSIC CURRENTLY PLAYING #{args.audio["MUSIC_CHANNEL_#{channel}"]}" if args.audio["MUSIC_CHANNEL_#{channel}"].looping - puts "CANCEL THE LOOP ON CURRENT MUSIC" args.audio["MUSIC_CHANNEL_#{channel}"].looping = false end else - puts "PLAY THAT FUNKY MUSIC! #{value}" value.shift.play_music(args, { channel: channel, gain: args.state.setting.music ? 0.8 : 0.0 }) - puts "Now, the queue is #{value}" end end end diff --git a/app/util/scene.rb b/app/util/scene.rb index 48baf45..c9967ae 100644 --- a/app/util/scene.rb +++ b/app/util/scene.rb @@ -7,8 +7,8 @@ # SceneInstance # # The main `#tick` of the game handles delegating to the current scene based on -# the `args.state.scene` value, which is a symbol of the current scene, ex: -# `:gameplay` +# the `args.state.scene_stack` value, which contains the current scene, as well +# as scenes that can be "popped" back to. module Scene class << self # Change the current scene, and optionally reset the scene that's begin @@ -19,15 +19,21 @@ module Scene args.state.scene_stack ||= [] # if we're here /not/ from push or pop, clear the scene stack args.state.scene_stack.clear unless push_or_pop - args.state.scene_stack.push(scene) if args.state.scene_stack.empty? + + # if `scene` is not a `SceneInstance`, it's probably a symbol representing + # the scene we're switching to, so go get it. + the_scene = scene.is_a?(SceneInstance) ? scene : SCENES[scene].new(args) - scene.reset(args) if reset + # if the stack is empty (e.g. we just cleared it), then push this scene + args.state.scene_stack.push(the_scene) if args.state.scene_stack.empty? + + # if we asked to reset the scene, then do so. + the_scene.reset(args) if reset - args.state.scene = scene raise FinishTick, 'finish tick early' end - # Change the current scene and push the previous scene onto the stack + # Change the current scene by pushing it onto the scene stack def push(args, scene, reset: false) args.state.scene_stack ||= [] the_scene = scene.is_a?(SceneInstance) ? scene : SCENES[scene].new(args) diff --git a/app/util/sound.rb b/app/util/sound.rb index 11dbc8d..ffa8daa 100644 --- a/app/util/sound.rb +++ b/app/util/sound.rb @@ -23,40 +23,4 @@ module Sound SOUNDS.fetch(key).resume(args) end end -end - -# # play a sound effect. the file in sounds/ must match the key name. ex: -# # play_sfx(args, :select) -# def play_sfx(args, key) -# if args.state.setting.sfx -# args.outputs.sounds << "sounds/#{key}.wav" -# end -# end - -# # play the specified music track, the key must correspond to the -# # `sounds/#{key}.ogg` file naming scheme. -# def play_music(args, key) -# args.audio[:music] = { input: "sounds/#{key}.ogg", looping: true, } -# set_music_vol(args) -# end - -# # sets the music vol based on whether or not music is enabled or disabled -# def set_music_vol(args) -# vol = args.state.setting.music ? 0.8 : 0.0 -# args.audio[:music]&.gain = vol -# end - -# # pause the currently playing music track -# def pause_music(args) -# args.audio[:music].paused = true -# end - -# # pause the current music track -# def resume_music(args) -# args.audio[:music].paused = false -# end - -# # stop the currently playing music track -# def stop_music(args) -# args.audio.delete(:music) -# end +end \ No newline at end of file