[update] Renamed Song to Music.

This commit is contained in:
falsycat 2019-10-14 00:00:00 +00:00
parent e1745f1c2b
commit 0a18f7feae
10 changed files with 53 additions and 53 deletions

2
.bin/.gitignore vendored
View File

@ -1,5 +1,5 @@
* *
!/*/ !/*/
!/songs/* !/music/*
!/.gitignore !/.gitignore

Binary file not shown.

View File

@ -9,9 +9,9 @@ import std.algorithm,
import sj.AbstractGame, import sj.AbstractGame,
sj.FontSet, sj.FontSet,
sj.LobbyWorld, sj.LobbyWorld,
sj.Music,
sj.ProgramSet, sj.ProgramSet,
sj.SelectScene, sj.SelectScene,
sj.Song,
sj.TitleScene; sj.TitleScene;
/// ///
@ -21,9 +21,9 @@ class Game : AbstractGame {
this() { this() {
const path = thisExePath.dirName; const path = thisExePath.dirName;
const songs_dir = buildPath(path, "songs"); const music_dir = buildPath(path, "music");
const songs_list = buildPath(songs_dir, "list.json").readText; const music_list = buildPath(music_dir, "list.json").readText;
songs_ = Song.CreateFromJson(songs_list.parseJSON, songs_dir); music_list_ = Music.CreateFromJson(music_list.parseJSON, music_dir);
fonts_ = new FontSet; fonts_ = new FontSet;
programs_ = new ProgramSet; programs_ = new ProgramSet;
@ -31,7 +31,7 @@ class Game : AbstractGame {
lobby_ = new LobbyWorld(programs_); lobby_ = new LobbyWorld(programs_);
title_ = new TitleScene(lobby_, programs_); title_ = new TitleScene(lobby_, programs_);
select_ = new SelectScene(lobby_, programs_, fonts_, songs_); select_ = new SelectScene(lobby_, programs_, fonts_, music_list_);
title_.SetupSceneDependency(select_); title_.SetupSceneDependency(select_);
select_.SetupSceneDependency(title_); select_.SetupSceneDependency(title_);
@ -49,11 +49,11 @@ class Game : AbstractGame {
fonts_.destroy(); fonts_.destroy();
programs_.destroy(); programs_.destroy();
songs_.each!destroy(); music_list_.each!destroy();
} }
private: private:
Song[] songs_; Music[] music_list_;
FontSet fonts_; FontSet fonts_;
ProgramSet programs_; ProgramSet programs_;

View File

@ -1,5 +1,5 @@
/// License: MIT /// License: MIT
module sj.Song; module sj.Music;
import std.array, import std.array,
std.conv, std.conv,
@ -16,7 +16,7 @@ import gl4d;
static import sjplayer; static import sjplayer;
/// ///
class Song { class Music {
public: public:
/// ///
static struct PreviewConfig { static struct PreviewConfig {
@ -31,12 +31,12 @@ class Song {
} }
/// ///
static Song[] CreateFromJson(in JSONValue json, string basepath) { static Music[] CreateFromJson(in JSONValue json, string basepath) {
auto result = appender!(Song[]); auto result = appender!(Music[]);
result.reserve(json.array.length); result.reserve(json.array.length);
foreach (item; json.array) { foreach (item; json.array) {
result ~= new Song(item, basepath); result ~= new Music(item, basepath);
} }
return result[]; return result[];
} }

View File

@ -13,9 +13,9 @@ import gl4d;
import sj.FontSet, import sj.FontSet,
sj.KeyInput, sj.KeyInput,
sj.LobbyWorld, sj.LobbyWorld,
sj.Music,
sj.ProgramSet, sj.ProgramSet,
sj.SceneInterface, sj.SceneInterface,
sj.Song,
sj.Text, sj.Text,
sj.TextProgram, sj.TextProgram,
sj.TitleScene, sj.TitleScene,
@ -27,9 +27,9 @@ import sj.FontSet,
class SelectScene : SceneInterface { class SelectScene : SceneInterface {
public: public:
/// ///
this(LobbyWorld lobby, ProgramSet program, FontSet fonts, Song[] songs) { this(LobbyWorld lobby, ProgramSet program, FontSet fonts, Music[] music_list) {
lobby_ = lobby; lobby_ = lobby;
songs_ = songs.dup; music_list_ = music_list.dup;
text_ = new Text(program.Get!TextProgram); text_ = new Text(program.Get!TextProgram);
fonts_ = fonts; fonts_ = fonts;
@ -95,7 +95,7 @@ class SelectScene : SceneInterface {
Text text_; Text text_;
FontSet fonts_; FontSet fonts_;
Song[] songs_; Music[] music_list_;
sfSound* sound_; sfSound* sound_;
SoundResources soundres_; SoundResources soundres_;
@ -146,7 +146,7 @@ private class FirstSetupState : AbstractSceneState {
public: public:
this(SelectScene owner) { this(SelectScene owner) {
super(owner); super(owner);
stage_appear_state_ = new SongAppearState(owner); music_appear_state_ = new MusicAppearState(owner);
} }
enum AnimeFrames = 30; enum AnimeFrames = 30;
@ -175,14 +175,14 @@ private class FirstSetupState : AbstractSceneState {
} }
if (anime_.isFinished) { if (anime_.isFinished) {
stage_appear_state_.Initialize(0); music_appear_state_.Initialize(0);
return CreateResult(stage_appear_state_); return CreateResult(music_appear_state_);
} }
return CreateResult(this); return CreateResult(this);
} }
private: private:
SongAppearState stage_appear_state_; MusicAppearState music_appear_state_;
Animation anime_; Animation anime_;
@ -191,17 +191,17 @@ private class FirstSetupState : AbstractSceneState {
Easing!float cube_interval_ease_; Easing!float cube_interval_ease_;
} }
private class SongAppearState : AbstractSceneState { private class MusicAppearState : AbstractSceneState {
public: public:
this(SelectScene owner) { this(SelectScene owner) {
super(owner); super(owner);
song_wait_state_ = new SongWaitState(owner, this); music_wait_state_ = new MusicWaitState(owner, this);
} }
enum AnimeFrames = 30; enum AnimeFrames = 30;
void Initialize(size_t song_index) { void Initialize(size_t music_index) {
song_index_ = song_index; music_index_ = music_index;
anime_ = Animation(AnimeFrames); anime_ = Animation(AnimeFrames);
@ -210,7 +210,7 @@ private class SongAppearState : AbstractSceneState {
LoadingCubeRotationSpeed, CubeRotationSpeed); LoadingCubeRotationSpeed, CubeRotationSpeed);
cube_interval_ease_ = Easing!float(LoadingCubeInterval, 0.005); cube_interval_ease_ = Easing!float(LoadingCubeInterval, 0.005);
with (owner.songs_[song_index_].preview) { with (owner.music_list_[music_index_].preview) {
bg_inner_ease_ = Easing!vec4(background.inner_color, bg_inner_color); bg_inner_ease_ = Easing!vec4(background.inner_color, bg_inner_color);
bg_outer_ease_ = Easing!vec4(background.outer_color, bg_outer_color); bg_outer_ease_ = Easing!vec4(background.outer_color, bg_outer_color);
} }
@ -219,10 +219,10 @@ private class SongAppearState : AbstractSceneState {
sfSound_setBuffer(owner.sound_, owner.soundres_.spotlight); sfSound_setBuffer(owner.sound_, owner.soundres_.spotlight);
sfSound_play(owner.sound_); sfSound_play(owner.sound_);
const song = owner.songs_[song_index_]; const music = owner.music_list_[music_index_];
with (owner.text_) { with (owner.text_) {
const w = LoadGlyphs(vec2i(1024, 64), const w = LoadGlyphs(vec2i(1024, 64),
song.name.to!dstring, vec2i(TitleTextSize, 0), owner.fonts_.gothic); music.name.to!dstring, vec2i(TitleTextSize, 0), owner.fonts_.gothic);
matrix.scale = TitleTextScale; matrix.scale = TitleTextScale;
matrix.translation = TitleTextTranslation + vec3(-w/2*matrix.scale.x, 0, 0); matrix.translation = TitleTextTranslation + vec3(-w/2*matrix.scale.x, 0, 0);
} }
@ -239,16 +239,16 @@ private class SongAppearState : AbstractSceneState {
} }
if (anime_.isFinished) { if (anime_.isFinished) {
song_wait_state_.Initialize(song_index_); music_wait_state_.Initialize(music_index_);
return CreateResult(song_wait_state_); return CreateResult(music_wait_state_);
} }
return CreateResult(this); return CreateResult(this);
} }
private: private:
SongWaitState song_wait_state_; MusicWaitState music_wait_state_;
size_t song_index_; size_t music_index_;
Animation anime_; Animation anime_;
@ -258,18 +258,18 @@ private class SongAppearState : AbstractSceneState {
Easing!vec4 bg_inner_ease_; Easing!vec4 bg_inner_ease_;
Easing!vec4 bg_outer_ease_; Easing!vec4 bg_outer_ease_;
} }
private class SongWaitState : AbstractSceneState { private class MusicWaitState : AbstractSceneState {
public: public:
this(SelectScene owner, SongAppearState song_appear_state) { this(SelectScene owner, MusicAppearState music_appear_state) {
super(owner); super(owner);
song_appear_state_ = song_appear_state; music_appear_state_ = music_appear_state;
} }
void Initialize(size_t song_index) { void Initialize(size_t music_index) {
song_index_ = song_index; music_index_ = music_index;
auto song = owner.songs_[song_index_]; auto music = owner.music_list_[music_index_];
song.PlayForPreview(); music.PlayForPreview();
with (owner.text_) { with (owner.text_) {
matrix.scale = TitleTextScale; matrix.scale = TitleTextScale;
@ -281,30 +281,30 @@ private class SongWaitState : AbstractSceneState {
owner.lobby_.cube_matrix.rotation += CubeRotationSpeed; owner.lobby_.cube_matrix.rotation += CubeRotationSpeed;
if (input.up) { if (input.up) {
song.StopPlaying(); music.StopPlaying();
owner.title_scene_.Initialize(); owner.title_scene_.Initialize();
return CreateResult(owner.title_scene_); return CreateResult(owner.title_scene_);
} }
if (input.left && song_index_ != 0) { if (input.left && music_index_ != 0) {
song.StopPlaying(); music.StopPlaying();
song_appear_state_.Initialize(song_index_-1); music_appear_state_.Initialize(music_index_-1);
return CreateResult(song_appear_state_); return CreateResult(music_appear_state_);
} }
if (input.right && song_index_+1 < owner.songs_.length) { if (input.right && music_index_+1 < owner.music_list_.length) {
song.StopPlaying(); music.StopPlaying();
song_appear_state_.Initialize(song_index_+1); music_appear_state_.Initialize(music_index_+1);
return CreateResult(song_appear_state_); return CreateResult(music_appear_state_);
} }
return CreateResult(this); return CreateResult(this);
} }
private: private:
@property Song song() { @property Music music() {
return owner.songs_[song_index_]; return owner.music_list_[music_index_];
} }
SongAppearState song_appear_state_; MusicAppearState music_appear_state_;
size_t song_index_; size_t music_index_;
} }