diff --git a/src/sj/Game.d b/src/sj/Game.d index 622e141..ef2a498 100644 --- a/src/sj/Game.d +++ b/src/sj/Game.d @@ -8,6 +8,7 @@ import std.algorithm, import sj.AbstractGame, sj.FontSet, + sj.LoadingScene, sj.LobbyWorld, sj.Music, sj.ProgramSet, @@ -25,6 +26,8 @@ class Game : AbstractGame { const music_list = buildPath(music_dir, "list.json").readText; music_list_ = Music.CreateFromJson(music_list.parseJSON, music_dir); + // To prevent working GC, all objects should be created at here. + fonts_ = new FontSet; programs_ = new ProgramSet; @@ -32,9 +35,11 @@ class Game : AbstractGame { title_ = new TitleScene(lobby_, programs_); select_ = new SelectScene(lobby_, programs_, fonts_, music_list_); + load_ = new LoadingScene(lobby_, programs_, fonts_); - title_.SetupSceneDependency(select_); - select_.SetupSceneDependency(title_); + title_ .SetupSceneDependency(select_); + select_.SetupSceneDependency(title_, load_); + load_ .SetupSceneDependency(); // TODO: pass play scene title_.Initialize(); super(title_); @@ -43,6 +48,7 @@ class Game : AbstractGame { ~this() { title_.destroy(); select_.destroy(); + load_.destroy(); lobby_.destroy(); @@ -60,6 +66,7 @@ class Game : AbstractGame { LobbyWorld lobby_; - TitleScene title_; - SelectScene select_; + TitleScene title_; + SelectScene select_; + LoadingScene load_; } diff --git a/src/sj/LoadingScene.d b/src/sj/LoadingScene.d new file mode 100644 index 0000000..e105049 --- /dev/null +++ b/src/sj/LoadingScene.d @@ -0,0 +1,43 @@ +/// License: MIT +module sj.LoadingScene; + +import sj.FontSet, + sj.KeyInput, + sj.LobbyWorld, + sj.Music, + sj.ProgramSet, + sj.SceneInterface; + +/// +class LoadingScene : SceneInterface { + public: + /// + this(LobbyWorld lobby, ProgramSet programs, FontSet fonts) { + lobby_ = lobby; + programs_ = programs; + fonts_ = fonts; + } + ~this() { + } + + /// + void SetupSceneDependency() { // TODO: add play scene + } + + /// + void Initialize(Music music) { + } + override SceneInterface Update(KeyInput input) { + return this; + } + override void Draw() { + lobby_.Draw(); + } + + private: + LobbyWorld lobby_; + + ProgramSet programs_; + + FontSet fonts_; +} diff --git a/src/sj/SelectScene.d b/src/sj/SelectScene.d index a80601c..fcf2f67 100644 --- a/src/sj/SelectScene.d +++ b/src/sj/SelectScene.d @@ -12,6 +12,7 @@ import gl4d; import sj.FontSet, sj.KeyInput, + sj.LoadingScene, sj.LobbyWorld, sj.Music, sj.ProgramSet, @@ -48,8 +49,9 @@ class SelectScene : SceneInterface { } /// - void SetupSceneDependency(TitleScene title_scene) { + void SetupSceneDependency(TitleScene title_scene, LoadingScene load_scene) { title_scene_ = title_scene; + load_scene_ = load_scene; } /// @@ -88,7 +90,8 @@ class SelectScene : SceneInterface { } } - TitleScene title_scene_; + TitleScene title_scene_; + LoadingScene load_scene_; LobbyWorld lobby_; @@ -267,8 +270,6 @@ private class MusicWaitState : AbstractSceneState { void Initialize(size_t music_index) { music_index_ = music_index; - - auto music = owner.music_list_[music_index_]; music.PlayForPreview(); with (owner.text_) { @@ -285,6 +286,12 @@ private class MusicWaitState : AbstractSceneState { owner.title_scene_.Initialize(); return CreateResult(owner.title_scene_); } + if (input.down) { + music.StopPlaying(); + owner.load_scene_.Initialize(music); + return CreateResult(owner.load_scene_); + } + if (input.left && music_index_ != 0) { music.StopPlaying(); music_appear_state_.Initialize(music_index_-1);