From 7e41c98cd3b5f0d4ac0a79610f9e47a6f5ec6168 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sun, 13 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Implemented a background transition for selecting songs. --- .bin/songs/list.json | 2 +- src/sj/SelectScene.d | 33 ++++++++++++++++++++++++--------- src/sj/Song.d | 24 +++++++++++++++++++----- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/.bin/songs/list.json b/.bin/songs/list.json index 22be6a8..851c9ad 100644 --- a/.bin/songs/list.json +++ b/.bin/songs/list.json @@ -9,7 +9,7 @@ "play-offset": 1000, "play-loop": 2000, "bg-inner-color": [0.8, 0.8, 0.8, 1], - "bg-outer-color": [0.8, 0.8, 0.8, 1] + "bg-outer-color": [0.1, 0.1, 0.1, 1] } } ] diff --git a/src/sj/SelectScene.d b/src/sj/SelectScene.d index 0471ebd..caed85e 100644 --- a/src/sj/SelectScene.d +++ b/src/sj/SelectScene.d @@ -120,14 +120,14 @@ private class FirstSetupState : AbstractSceneState { public: this(SelectScene owner) { super(owner); - stage_appear_state_ = new StageAppearState(owner); + stage_appear_state_ = new SongAppearState(owner); } enum AnimeFrames = 30; - enum BgInnerColor = vec4(0.8, 0.6, 0.6, 1); + enum BgInnerColor = vec4(0.4, 0.2, 0.2, 1); enum BgOuterColor = vec4(-0.4, -0.4, -0.4, 1); - enum CubeRotationSpeed = vec3(0, PI/10, 0); + enum CubeRotationSpeed = vec3(0, PI/5, 0); enum CubeInterval = 0.06; void Initialize() { @@ -154,7 +154,7 @@ private class FirstSetupState : AbstractSceneState { } private: - StageAppearState stage_appear_state_; + SongAppearState stage_appear_state_; Animation anime_; @@ -163,7 +163,7 @@ private class FirstSetupState : AbstractSceneState { Easing!float cube_interval_ease_; } -private class StageAppearState : AbstractSceneState { +private class SongAppearState : AbstractSceneState { public: this(SelectScene owner) { super(owner); @@ -177,7 +177,16 @@ private class StageAppearState : AbstractSceneState { anime_ = Animation(AnimeFrames); - cube_interval_ease_ = Easing!float(owner.lobby_.cube_interval, 0.005); + auto lobby = owner.lobby_; + + cube_rota_speed_ease_ = Easing!vec3( + FirstSetupState.CubeRotationSpeed, CubeRotationSpeed); + cube_interval_ease_ = Easing!float(lobby.cube_interval, 0.005); + + with (owner.songs_[song_index_].preview) { + bg_inner_ease_ = Easing!vec4(lobby.background.inner_color, bg_inner_color); + bg_outer_ease_ = Easing!vec4(lobby.background.outer_color, bg_outer_color); + } sfSound_setBuffer(owner.sound_, owner.soundres_.spotlight); sfSound_play(owner.sound_); @@ -185,9 +194,11 @@ private class StageAppearState : AbstractSceneState { override UpdateResult Update(KeyInput input) { const ratio = anime_.Update(); - owner.lobby_.cube_matrix.rotation += CubeRotationSpeed + - (FirstSetupState.CubeRotationSpeed - CubeRotationSpeed) * (1-ratio); - owner.lobby_.cube_interval = cube_interval_ease_.Calculate(ratio); + owner.lobby_.cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio); + owner.lobby_.cube_interval = cube_interval_ease_.Calculate(ratio); + + owner.lobby_.background.inner_color = bg_inner_ease_.Calculate(ratio); + owner.lobby_.background.outer_color = bg_outer_ease_.Calculate(ratio); return CreateResult(this); } @@ -196,5 +207,9 @@ private class StageAppearState : AbstractSceneState { Animation anime_; + Easing!vec3 cube_rota_speed_ease_; Easing!float cube_interval_ease_; + + Easing!vec4 bg_inner_ease_; + Easing!vec4 bg_outer_ease_; } diff --git a/src/sj/Song.d b/src/sj/Song.d index bdbd8f7..1701147 100644 --- a/src/sj/Song.d +++ b/src/sj/Song.d @@ -6,8 +6,7 @@ import std.array, std.exception, std.json, std.path, - std.string, - std.typecons; + std.string; import derelict.sfml2.audio, derelict.sfml2.system; @@ -26,9 +25,9 @@ class Song { size_t play_offset; /// - Nullable!vec4 bg_inner_color; + vec4 bg_inner_color = vec4(0, 0, 0, 0); /// - Nullable!vec4 bg_outer_color; + vec4 bg_outer_color = vec4(0, 0, 0, 0); } /// @@ -51,7 +50,13 @@ class Song { music_ = sfMusic_createFromFile(music_path.toStringz).enforce; script_path_ = buildPath(basepath, json["script"].str); - // TODO: update preview config + with (preview_) { + const preview_json = json["preview"]; + + play_offset = preview_json["play-offset"].integer; + bg_inner_color = GetVectorFromJson!4(preview_json["bg-inner-color"]); + bg_outer_color = GetVectorFromJson!4(preview_json["bg-outer-color"]); + } } ~this() { sfMusic_destroy(music_); @@ -83,6 +88,15 @@ class Song { static float GetNumericAsFloatFromJson(in JSONValue json) { return json.type == JSONType.float_? json.floating: json.integer; } + static Vector!(float, dim) GetVectorFromJson(size_t dim)(in JSONValue json) { + (json.array.length == dim).enforce; + + Vector!(float, dim) v; + static foreach (i; 0..dim) { + v.vector[i] = GetNumericAsFloatFromJson(json.array[i]); + } + return v; + } string name_;