From 21dbb194fd24b9e621c4f196cea8120f58f75084 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Mon, 5 Dec 2022 22:16:06 +0800 Subject: [PATCH] change data/meta definition. - change the id and seq and name def of SongUnit - change and added fields to Song - change and added fields to Difficulty - add subproj sekai-database for db connection and action(empty currently) - add sekai-cli command database to execute database manager action(no implementation currently) --- gradle.properties | 2 +- sekai-cli/gradle.properties | 2 +- .../java/cc/sukazyo/sekai_cli/ClientMain.java | 20 +++++--- .../java/cc/sukazyo/sekai_cli/Config.java | 8 ++++ .../cc/sukazyo/sekai_cli/client/Database.java | 46 +++++++++++++++++++ .../sukazyo/sekai_cli/db/PostgresConfig.java | 6 ++- sekai-database/build.gradle | 19 ++++++++ .../project_sekai_colorful_stage/LeoNeed.java | 2 +- .../Nightcord25ji.java | 10 ++-- .../SekaiSpecial.java | 6 +-- .../project_sekai_colorful_stage/VSinger.java | 2 +- .../WonderlandsShowtime.java | 2 +- settings.gradle | 1 + .../cc/sukazyo/sekai_scores/Difficulty.java | 22 ++++++++- .../java/cc/sukazyo/sekai_scores/Song.java | 27 ++++++++++- .../cc/sukazyo/sekai_scores/SongUnit.java | 46 ++++++++++++------- 16 files changed, 182 insertions(+), 39 deletions(-) create mode 100644 sekai-cli/src/main/java/cc/sukazyo/sekai_cli/client/Database.java create mode 100644 sekai-database/build.gradle diff --git a/gradle.properties b/gradle.properties index 8a6ec46..0fe9489 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ ## Project Configurations # Proj Metadata -projVersion = 0.5 +projVersion = 0.6 # Dependencies diff --git a/sekai-cli/gradle.properties b/sekai-cli/gradle.properties index 9247e62..ba52310 100644 --- a/sekai-cli/gradle.properties +++ b/sekai-cli/gradle.properties @@ -1,7 +1,7 @@ ## Project Configurations # Proj Metadata -moduleVersion = 0.5.1 +moduleVersion = 0.5.2 # dependencies lib_postgres_driver = 42.5.1 diff --git a/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/ClientMain.java b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/ClientMain.java index 2ced1ab..57edeee 100644 --- a/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/ClientMain.java +++ b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/ClientMain.java @@ -2,6 +2,7 @@ package cc.sukazyo.sekai_cli; import cc.sukazyo.sekai_cli.client.AddScore; import cc.sukazyo.sekai_cli.client.Configs; +import cc.sukazyo.sekai_cli.client.Database; import java.util.List; @@ -28,12 +29,19 @@ public class ClientMain { if ($args.size() > 0) { final String i0 = $args.remove(0); - if (i0.equals("add")) { - AddScore.main($args.toArray(String[]::new)); - $done(); - } else if (i0.equals("config")) { - Configs.main($args.toArray(String[]::new)); - $done(); + switch (i0) { + case "add" -> { + AddScore.main($args.toArray(String[]::new)); + $done(); + } + case "config" -> { + Configs.main($args.toArray(String[]::new)); + $done(); + } + case "database" -> { + Database.main($args.toArray(String[]::new)); + $done(); + } } } diff --git a/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/Config.java b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/Config.java index 729e3cb..b22b7cb 100644 --- a/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/Config.java +++ b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/Config.java @@ -1,5 +1,7 @@ package cc.sukazyo.sekai_cli; +import cc.sukazyo.sekai_cli.db.PostgresConfig; + import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.File; @@ -25,6 +27,12 @@ public class Config { @Nonnull public final String db_auth_pwd; @Nullable public final String db_schema; + private PostgresConfig db = null; + public PostgresConfig db () { + if (db == null) db = new PostgresConfig(this); + return db; + } + private Config (Properties props) { // user config field this.sekai_id = Long.parseLong(props.getProperty("user.sekai-id")); diff --git a/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/client/Database.java b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/client/Database.java new file mode 100644 index 0000000..3ff6700 --- /dev/null +++ b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/client/Database.java @@ -0,0 +1,46 @@ +package cc.sukazyo.sekai_cli.client; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +import static cc.sukazyo.sekai_cli.Log._debug; +import static cc.sukazyo.sekai_cli.Log._user; + +public class Database { + + public static void main (String[] args) { + + final List $args = Arrays.asList(args); + + final String subcommand = $args.remove(0); + if (subcommand.equals("import")) { + if ($args.isEmpty()) { + System.out.println(""" + database import: + currently available types: + song + song-difficulty + """); + } else { + final Path file; + try { file = Paths.get($args.remove(1)); } + catch (IndexOutOfBoundsException e) { + _user("database import: need a file path."); + _debug(e); + } + switch ($args.remove(0)) { + case "song" -> + _user("type song: WIP"); + case "song-difficulty" -> + _user("type song-difficulty: WIP"); + default -> + _user("unavailable type.\ncurrently available types:\n song\n song-difficulty"); + } + } + } + + } + +} diff --git a/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/db/PostgresConfig.java b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/db/PostgresConfig.java index 2b169b3..8307a01 100644 --- a/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/db/PostgresConfig.java +++ b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/db/PostgresConfig.java @@ -37,7 +37,11 @@ public class PostgresConfig { } public String struct() { - return struct == null ? "default" : struct; + return struct; + } + + public String table (String table) { + return (struct == null ? "" : '"' + struct() + '"' + ".") + '"' + table + '"'; } public Connection connect () throws SQLException { diff --git a/sekai-database/build.gradle b/sekai-database/build.gradle new file mode 100644 index 0000000..7c395d7 --- /dev/null +++ b/sekai-database/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group 'cc.sukazyo' +version projVersion + +repositories { + mavenCentral() +} + +dependencies { + testImplementation "org.junit.jupiter:junit-jupiter-api:${lib_junit_v}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${lib_junit_v}" +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/LeoNeed.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/LeoNeed.java index 56db504..6bee5d8 100644 --- a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/LeoNeed.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/LeoNeed.java @@ -11,7 +11,7 @@ public class LeoNeed extends SongDefinition { /** ... */ public static final Song Calc = new Song( - 243, "Calc.", SongUnit.LEO_NEED, + 243, "Calc.", SongUnit.LIGHT_SOUND, new DifficultiesSekai( new Difficulty( EASY_NAME, 7, 325), new Difficulty(NORMAL_NAME,13, 464), diff --git a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Nightcord25ji.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Nightcord25ji.java index 27a7a97..fb98ca0 100644 --- a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Nightcord25ji.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Nightcord25ji.java @@ -11,7 +11,7 @@ public class Nightcord25ji extends SongDefinition { /** ... */ public static final Song Kuyamu_to_Kaite_Mirai = new Song( - 60, "悔やむと書いてミライ", SongUnit.NIGHTCORD_25JI, + 60, "悔やむと書いてミライ", SongUnit.SCHOOL_REFUSAL, new DifficultiesSekai( new Difficulty( EASY_NAME, 8, 190), new Difficulty(NORMAL_NAME,13, 440), @@ -22,7 +22,7 @@ public class Nightcord25ji extends SongDefinition { ); /** ... */ public static final Song Keitai_Renwa = new Song( - 61, "携帯恋話", SongUnit.NIGHTCORD_25JI, + 61, "携帯恋話", SongUnit.SCHOOL_REFUSAL, new DifficultiesSekai( new Difficulty( EASY_NAME, 8, 204), new Difficulty(NORMAL_NAME, 12, 361), @@ -33,7 +33,7 @@ public class Nightcord25ji extends SongDefinition { ); /** ... */ public static final Song ID_Smile = new Song( - 116, "アイディスマイル", SongUnit.NIGHTCORD_25JI, + 116, "アイディスマイル", SongUnit.SCHOOL_REFUSAL, new DifficultiesSekai( new Difficulty( EASY_NAME, 7, 263), new Difficulty(NORMAL_NAME,12, 439), @@ -44,7 +44,7 @@ public class Nightcord25ji extends SongDefinition { ); /** ... */ public static final Song Saisei = new Song( - 142, "再生", SongUnit.NIGHTCORD_25JI, + 142, "再生", SongUnit.SCHOOL_REFUSAL, new DifficultiesSekai( new Difficulty( EASY_NAME, 5, 124), new Difficulty(NORMAL_NAME,11, 221), @@ -55,7 +55,7 @@ public class Nightcord25ji extends SongDefinition { ); /** ... */ public static final Song Kanade_Tomosu_Sora = new Song( - 149, "カナデトモスソラ", SongUnit.NIGHTCORD_25JI, + 149, "カナデトモスソラ", SongUnit.SCHOOL_REFUSAL, new DifficultiesSekai( new Difficulty( EASY_NAME, 6, 213), new Difficulty(NORMAL_NAME,11, 312), diff --git a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SekaiSpecial.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SekaiSpecial.java index 12b04bc..911f0cb 100644 --- a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SekaiSpecial.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SekaiSpecial.java @@ -11,7 +11,7 @@ public class SekaiSpecial extends SongDefinition { /** ... */ public static final Song Yoru_ni_Kakeru = new Song( - 139, "夜に駆ける", SongUnit.SP, + 139, "夜に駆ける", SongUnit._X, new DifficultiesSekai( new Difficulty( EASY_NAME, 6, 182), new Difficulty(NORMAL_NAME,11, 357), @@ -22,7 +22,7 @@ public class SekaiSpecial extends SongDefinition { ); /** ... */ public static final Song Gunjou_Sanka = new Song( - 141, "群青讃歌", SongUnit.SP, + 141, "群青讃歌", SongUnit._X, new DifficultiesSekai( new Difficulty( EASY_NAME, 7, 199), new Difficulty(NORMAL_NAME,13, 344), @@ -33,7 +33,7 @@ public class SekaiSpecial extends SongDefinition { ); /** ... */ public static final Song Journey = new Song( - 235, "Journey", SongUnit.SP, + 235, "Journey", SongUnit._X, new DifficultiesSekai( new Difficulty( EASY_NAME, 6, 199), new Difficulty(NORMAL_NAME,12, 512), diff --git a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/VSinger.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/VSinger.java index 170c77d..05d97fd 100644 --- a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/VSinger.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/VSinger.java @@ -11,7 +11,7 @@ public class VSinger extends SongDefinition { /** ... */ public static final Song Luka_Luka_Night_Fever = new Song( - 216, "ルカルカ★ナイトフィーバー", SongUnit.VSINGER, + 216, "ルカルカ★ナイトフィーバー", SongUnit.PIAPRO, new DifficultiesSekai( new Difficulty( EASY_NAME, 7, 218), new Difficulty(NORMAL_NAME,13, 457), diff --git a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/WonderlandsShowtime.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/WonderlandsShowtime.java index afee0f3..042918a 100644 --- a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/WonderlandsShowtime.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/WonderlandsShowtime.java @@ -11,7 +11,7 @@ public class WonderlandsShowtime extends SongDefinition { /** ... */ public static final Song Donna_Ketsumatsu_ga_Onozomi_Dai = new Song( - 290, "どんな結末がお望みだい?", SongUnit.WONDERLANDS_SHOWTIME, + 290, "どんな結末がお望みだい?", SongUnit.THEME_PARK, new DifficultiesSekai( new Difficulty( EASY_NAME, 8, 215), new Difficulty(NORMAL_NAME,12, 325), diff --git a/settings.gradle b/settings.gradle index 27d1ba2..f55964a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ rootProject.name = 'sekai-scores' include 'sekai-cli' include 'sekai-meta' +include 'sekai-database' diff --git a/src/main/java/cc/sukazyo/sekai_scores/Difficulty.java b/src/main/java/cc/sukazyo/sekai_scores/Difficulty.java index 292d65a..54b7001 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/Difficulty.java +++ b/src/main/java/cc/sukazyo/sekai_scores/Difficulty.java @@ -6,11 +6,26 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; public record Difficulty( - @Nonnegative String id, + @Nonnull String id, @Nonnegative int level, - @Nonnegative int noteCount + @Nonnegative int noteCount, + int levelPlus, + int levelPlus_f, + int levelPlus_p ) { + public static final int NULL = -1; + + /** + * capability constructor for v0.5 + */ + public Difficulty (@Nonnull String id, @Nonnegative int level, @Nonnegative int noteCount) { + this( + id, level, noteCount, + NULL, NULL, NULL + ); + } + /** * @since 0.4 */ @@ -42,6 +57,9 @@ public record Difficulty( return String.format("{%s}", toStringSimple()); } + /** + * outdated since v0.6: data type update + */ @Nonnull public String toStringSimple () { return String.format( diff --git a/src/main/java/cc/sukazyo/sekai_scores/Song.java b/src/main/java/cc/sukazyo/sekai_scores/Song.java index 791f6a1..2841cc3 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/Song.java +++ b/src/main/java/cc/sukazyo/sekai_scores/Song.java @@ -3,14 +3,39 @@ package cc.sukazyo.sekai_scores; import cc.sukazyo.sekai_scores.util.Converter; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.time.Duration; +import java.time.ZonedDateTime; public record Song( int id, @Nonnull String name, @Nonnull SongUnit unit, - @Nonnull Difficulties difficulties + @Nonnull Difficulties difficulties, + @Nullable String producer, + @Nullable String arranger, + @Nullable String composer, + @Nullable String lyricist, + @Nullable int[] bpm, + @Nullable Duration duration, + @Nullable ZonedDateTime releaseDate, + @Nullable String[] nameAlias ) { + /** + * capability constructor for v0.5 + */ + public Song (int id, @Nonnull String name, @Nonnull SongUnit unit, @Nonnull Difficulties difficulties) { + this( + id, name, unit, difficulties, + null, null, null, null, + null, null, null, null + ); + } + + /** + * !! outdated since v0.6: data type update + */ @Override @Nonnull public String toString () { diff --git a/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java b/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java index 6e588da..90a99bf 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java +++ b/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java @@ -6,17 +6,17 @@ import javax.annotation.Nonnull; public enum SongUnit { - VSINGER(0, "VIRTUAL SINGER"), - LEO_NEED(1, "Leo/need"), - MORE_MORE_JUMP(2, "MORE MORE JUMP!"), - VIVID_BAD_SQUAD(3, "Vivid BAD SQUAD"), - WONDERLANDS_SHOWTIME(4, "ワンダーランズ×ショウタイム"), - NIGHTCORD_25JI(5, "25時、ナイトコードで。"), + PIAPRO(1, "VIRTUAL SINGER"), + LIGHT_SOUND(2, "Leo/need"), + IDOL(3, "MORE MORE JUMP!"), + STREET(4, "Vivid BAD SQUAD"), + THEME_PARK(5, "ワンダーランズ×ショウタイム"), + SCHOOL_REFUSAL(6, "25時、ナイトコードで。"), /** * Just the "other" unit in game. * @since 0.2 */ - OTHER(-1, "other"), + OTHER(7, "other"), /** * It collects that songs belongs to multiple units. *

@@ -27,27 +27,41 @@ public enum SongUnit { * This unit/group doesn't exist in the game. * @since 0.2 */ - SP(-2, "セカイ") + _X(-1, "セカイ") ; + public SongUnit getBySeq(int seq) { + return switch (seq) { + case 1 -> PIAPRO; + case 2 -> LIGHT_SOUND; + case 3 -> IDOL; + case 4 -> STREET; + case 5 -> THEME_PARK; + case 6 -> SCHOOL_REFUSAL; + case 7 -> OTHER; + case -1 -> _X; + default -> null; + }; + } + /** * An id of this group/unit. *

- * The value start at 0 for {@link #VSINGER} + * The value start at 1 for {@link #PIAPRO} which is VIRTUAL SINGER * and increment according to the order of the groups/units in the game. *

* for some special group/unit, it has a special id: *

    - *
  • {@link #OTHER}: {@link -1}, as a special group that even exists in game
  • - *
  • {@link #SP}: {@link -2}, as a group that doesn't exist in game
  • + *
  • {@link #OTHER}: {@link 7}, as a special group that even exists in game
  • + *
  • {@link #_X}: {@link -1}, as a group that doesn't exist in game
  • *
* @since 0.3 */ - public final int id; + public final int seq; @Nonnull public final String name; - SongUnit (int id, @Nonnull String name) { - this.id = id; + SongUnit (int seq, @Nonnull String name) { + this.seq = seq; this.name = name; } @@ -55,8 +69,8 @@ public enum SongUnit { @Nonnull public String toString() { return String.format( - "{\"id\":%d,\"fullname\":%s}", - id, + "{\"seq\":%d,\"fullname\":%s}", + seq, Converter.parseJSONString(name) ); }