diff --git a/.gitignore b/.gitignore index 1d26366..27347d9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build src/test/java/test/ +*/src/test/java/test/ diff --git a/build.gradle b/build.gradle index b45dabf..286263a 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-api:${lib_junit_v}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${lib_junit_v}" - testImplementation project(":sekai-scores-db") + testImplementation project(":sekai-meta") } diff --git a/gradle.properties b/gradle.properties index d92c3b1..8a6ec46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ ## Project Configurations # Proj Metadata -projVersion = 0.4 +projVersion = 0.5 # Dependencies diff --git a/sekai-cli/build.gradle b/sekai-cli/build.gradle index d4f343d..0260bd2 100644 --- a/sekai-cli/build.gradle +++ b/sekai-cli/build.gradle @@ -15,6 +15,9 @@ dependencies { compileOnly "com.github.spotbugs:spotbugs-annotations:${lib_spotbugs_v}" implementation rootProject + implementation project(":sekai-meta") + + implementation "org.postgresql:postgresql:${lib_postgres_driver}" testImplementation "org.junit.jupiter:junit-jupiter-api:${lib_junit_v}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${lib_junit_v}" diff --git a/sekai-cli/gradle.properties b/sekai-cli/gradle.properties index 911432c..9247e62 100644 --- a/sekai-cli/gradle.properties +++ b/sekai-cli/gradle.properties @@ -2,3 +2,6 @@ # Proj Metadata moduleVersion = 0.5.1 + +# dependencies +lib_postgres_driver = 42.5.1 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 df1205e..729e3cb 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 @@ -23,7 +23,7 @@ public class Config { @Nonnull public final String db_name; @Nonnull public final String db_auth_user; @Nonnull public final String db_auth_pwd; - @Nullable public final String db_prefix; + @Nullable public final String db_schema; private Config (Properties props) { // user config field @@ -37,8 +37,8 @@ public class Config { _debug("config field db.auth.user set: " + this.db_auth_user); this.db_auth_pwd = getNonnull(props, "db.auth.password"); _debug("config field db.auth.password set."); - this.db_prefix = props.getProperty("db.table-prefix"); - _debug(this.db_prefix == null ? "config field db.prefix unset." : "config field db.table-prefix set: " + this.db_prefix); + this.db_schema = props.getProperty("db.schema"); + _debug(this.db_schema == null ? "config field db.schema unset." : "config field db.schema set: " + this.db_schema); } @Nonnull @@ -54,7 +54,7 @@ public class Config { echo("db.database", db_name); echo("db.auth.user", db_auth_user); echo("db.auth.password", db_auth_pwd); - echo("db.table-prefix", db_prefix); + echo("db.schema", db_schema); } private void echo (String k, String v) { 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 new file mode 100644 index 0000000..2b169b3 --- /dev/null +++ b/sekai-cli/src/main/java/cc/sukazyo/sekai_cli/db/PostgresConfig.java @@ -0,0 +1,47 @@ +package cc.sukazyo.sekai_cli.db; + +import cc.sukazyo.sekai_cli.Config; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class PostgresConfig { + + @Nonnull public final String host; + @Nonnull public final String database; + @Nullable public final String struct; + @Nonnull public final String user; + @Nonnull public final String token; + + public PostgresConfig ( + @Nonnull String host, @Nonnull String database, @Nullable String struct, + @Nonnull String user, @Nonnull String token + ) { + this.host = host; + this.database = database; + this.struct = struct; + this.user = user; + this.token = token; + } + + public PostgresConfig (Config global) { + this(global.db_host, global.db_name, global.db_schema, global.db_auth_user, global.db_auth_pwd); + } + + @Override + public String toString () { + return String.format("jdbc:postgresql://%s/%s", host, database); + } + + public String struct() { + return struct == null ? "default" : struct; + } + + public Connection connect () throws SQLException { + return DriverManager.getConnection(this.toString(), user, token); + } + +} diff --git a/sekai-scores-db/build.gradle b/sekai-meta/build.gradle similarity index 100% rename from sekai-scores-db/build.gradle rename to sekai-meta/build.gradle diff --git a/sekai-scores-db/gradle.properties b/sekai-meta/gradle.properties similarity index 66% rename from sekai-scores-db/gradle.properties rename to sekai-meta/gradle.properties index a3fabf6..c0e1d0e 100644 --- a/sekai-scores-db/gradle.properties +++ b/sekai-meta/gradle.properties @@ -1,4 +1,4 @@ ## Project Configurations # Proj Metadata -moduleVersion = 0.2.1 +moduleVersion = 0.3 diff --git a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/LeoNeed.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/LeoNeed.java similarity index 84% rename from sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/LeoNeed.java rename to sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/LeoNeed.java index 384c1f7..56db504 100644 --- a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/LeoNeed.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/LeoNeed.java @@ -1,4 +1,4 @@ -package cc.sukazyo.sekai_scores.db.project_sekai_colorful_stage; +package cc.sukazyo.sekai_scores.meta.project_sekai_colorful_stage; import cc.sukazyo.sekai_scores.Difficulty; import cc.sukazyo.sekai_scores.DifficultiesSekai; @@ -7,7 +7,7 @@ import cc.sukazyo.sekai_scores.SongUnit; import static cc.sukazyo.sekai_scores.DifficultiesSekai.*; -public class LeoNeed { +public class LeoNeed extends SongDefinition { /** ... */ public static final Song Calc = new Song( diff --git a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/Nightcord25ji.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Nightcord25ji.java similarity index 93% rename from sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/Nightcord25ji.java rename to sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Nightcord25ji.java index 738ad3a..27a7a97 100644 --- a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/Nightcord25ji.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Nightcord25ji.java @@ -1,4 +1,4 @@ -package cc.sukazyo.sekai_scores.db.project_sekai_colorful_stage; +package cc.sukazyo.sekai_scores.meta.project_sekai_colorful_stage; import cc.sukazyo.sekai_scores.Difficulty; import cc.sukazyo.sekai_scores.DifficultiesSekai; @@ -7,7 +7,7 @@ import cc.sukazyo.sekai_scores.SongUnit; import static cc.sukazyo.sekai_scores.DifficultiesSekai.*; -public class Nightcord25ji { +public class Nightcord25ji extends SongDefinition { /** ... */ public static final Song Kuyamu_to_Kaite_Mirai = new Song( @@ -32,7 +32,7 @@ public class Nightcord25ji { ) ); /** ... */ - public static final Song ID_SMILE = new Song( + public static final Song ID_Smile = new Song( 116, "アイディスマイル", SongUnit.NIGHTCORD_25JI, new DifficultiesSekai( new Difficulty( EASY_NAME, 7, 263), diff --git a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/Other.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Other.java similarity index 91% rename from sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/Other.java rename to sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Other.java index af5caa0..3eb3f57 100644 --- a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/Other.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/Other.java @@ -1,4 +1,4 @@ -package cc.sukazyo.sekai_scores.db.project_sekai_colorful_stage; +package cc.sukazyo.sekai_scores.meta.project_sekai_colorful_stage; import cc.sukazyo.sekai_scores.Difficulty; import cc.sukazyo.sekai_scores.DifficultiesSekai; @@ -7,7 +7,7 @@ import cc.sukazyo.sekai_scores.SongUnit; import static cc.sukazyo.sekai_scores.DifficultiesSekai.*; -public class Other { +public class Other extends SongDefinition { /** ... */ diff --git a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/SekaiSpecial.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SekaiSpecial.java similarity index 92% rename from sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/SekaiSpecial.java rename to sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SekaiSpecial.java index 9527482..12b04bc 100644 --- a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/SekaiSpecial.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SekaiSpecial.java @@ -1,4 +1,4 @@ -package cc.sukazyo.sekai_scores.db.project_sekai_colorful_stage; +package cc.sukazyo.sekai_scores.meta.project_sekai_colorful_stage; import cc.sukazyo.sekai_scores.Difficulty; import cc.sukazyo.sekai_scores.DifficultiesSekai; @@ -7,7 +7,7 @@ import cc.sukazyo.sekai_scores.SongUnit; import static cc.sukazyo.sekai_scores.DifficultiesSekai.*; -public class SekaiSpecial { +public class SekaiSpecial extends SongDefinition { /** ... */ public static final Song Yoru_ni_Kakeru = new Song( diff --git a/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SongDefinition.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SongDefinition.java new file mode 100644 index 0000000..6efb625 --- /dev/null +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/SongDefinition.java @@ -0,0 +1,25 @@ +package cc.sukazyo.sekai_scores.meta.project_sekai_colorful_stage; + +import cc.sukazyo.sekai_scores.Song; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +public abstract class SongDefinition { + + public Song[] songs() { + final List songs = new ArrayList<>(); + for (Field field : this.getClass().getFields()) { + if (field.getType() == Song.class) { + try { + songs.add((Song)field.get(new Object())); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + return songs.toArray(Song[]::new); + } + +} diff --git a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/VSinger.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/VSinger.java similarity index 86% rename from sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/VSinger.java rename to sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/VSinger.java index 2eb1972..170c77d 100644 --- a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/VSinger.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/VSinger.java @@ -1,4 +1,4 @@ -package cc.sukazyo.sekai_scores.db.project_sekai_colorful_stage; +package cc.sukazyo.sekai_scores.meta.project_sekai_colorful_stage; import cc.sukazyo.sekai_scores.Difficulty; import cc.sukazyo.sekai_scores.DifficultiesSekai; @@ -7,7 +7,7 @@ import cc.sukazyo.sekai_scores.SongUnit; import static cc.sukazyo.sekai_scores.DifficultiesSekai.*; -public class VSinger { +public class VSinger extends SongDefinition { /** ... */ public static final Song Luka_Luka_Night_Fever = new Song( diff --git a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/WonderlandsShowtime.java b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/WonderlandsShowtime.java similarity index 85% rename from sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/WonderlandsShowtime.java rename to sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/WonderlandsShowtime.java index 696bdbe..afee0f3 100644 --- a/sekai-scores-db/src/main/java/cc/sukazyo/sekai_scores/db/project_sekai_colorful_stage/WonderlandsShowtime.java +++ b/sekai-meta/src/main/java/cc/sukazyo/sekai_scores/meta/project_sekai_colorful_stage/WonderlandsShowtime.java @@ -1,4 +1,4 @@ -package cc.sukazyo.sekai_scores.db.project_sekai_colorful_stage; +package cc.sukazyo.sekai_scores.meta.project_sekai_colorful_stage; import cc.sukazyo.sekai_scores.Difficulty; import cc.sukazyo.sekai_scores.DifficultiesSekai; @@ -7,7 +7,7 @@ import cc.sukazyo.sekai_scores.SongUnit; import static cc.sukazyo.sekai_scores.DifficultiesSekai.*; -public class WonderlandsShowtime { +public class WonderlandsShowtime extends SongDefinition { /** ... */ public static final Song Donna_Ketsumatsu_ga_Onozomi_Dai = new Song( diff --git a/sekai-meta/src/main/resources/sekai-meta/VSinger.list b/sekai-meta/src/main/resources/sekai-meta/VSinger.list new file mode 100644 index 0000000..0913f48 --- /dev/null +++ b/sekai-meta/src/main/resources/sekai-meta/VSinger.list @@ -0,0 +1,17 @@ + +[Tell_Your_World] +id=1 +title=Tell Your World +producer=kz +arranger=kz +composer=kz +lyricist=kz +commissioned=false +bpm=150 +duration=2:03.3 +released_date=2019-06-10 +difficulty.easy=5;220 +difficulty.normal=10;492 +difficulty.hard=16;719 +difficulty.expert=22;961 +difficulty.master=26;1147 diff --git a/settings.gradle b/settings.gradle index cb5982e..27d1ba2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ rootProject.name = 'sekai-scores' include 'sekai-cli' -include 'sekai-scores-db' +include 'sekai-meta' diff --git a/src/main/java/cc/sukazyo/sekai_scores/Difficulties.java b/src/main/java/cc/sukazyo/sekai_scores/Difficulties.java index 2e6c380..2c1c41f 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/Difficulties.java +++ b/src/main/java/cc/sukazyo/sekai_scores/Difficulties.java @@ -5,6 +5,8 @@ import java.util.function.Consumer; public interface Difficulties { + Difficulty[] getAll (); + void forEach(@Nonnull Consumer action); } diff --git a/src/main/java/cc/sukazyo/sekai_scores/DifficultiesSekai.java b/src/main/java/cc/sukazyo/sekai_scores/DifficultiesSekai.java index 416038c..e1c3d85 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/DifficultiesSekai.java +++ b/src/main/java/cc/sukazyo/sekai_scores/DifficultiesSekai.java @@ -17,6 +17,11 @@ public record DifficultiesSekai( public static final String EXPERT_NAME = "EXPERT"; public static final String MASTER_NAME = "MASTER"; + @Override + public Difficulty[] getAll () { + return new Difficulty[]{easy, normal, hard, expert, master}; + } + @Override public void forEach (@Nonnull Consumer action) { action.accept(easy);