1
0
mirror of https://github.com/Eyre-S/sekai-scores.git synced 2024-11-22 19:24:55 +08:00

implement toString to serialize to JSON format, add "id" field for SongUnit

This commit is contained in:
A.C.Sukazyo Eyre 2022-11-21 16:26:17 +08:00
parent 28ff69ceb8
commit 3032af55e5
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
10 changed files with 190 additions and 19 deletions

View File

@ -19,6 +19,8 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${lib_junit_v}" testImplementation "org.junit.jupiter:junit-jupiter-api:${lib_junit_v}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${lib_junit_v}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${lib_junit_v}"
testImplementation project(":sekai-scores-db")
} }
final JavaVersion proj_java = JavaVersion.VERSION_17 final JavaVersion proj_java = JavaVersion.VERSION_17

View File

@ -1,7 +1,7 @@
## Project Configurations ## Project Configurations
# Proj Metadata # Proj Metadata
projVersion = 0.2 projVersion = 0.3
# Dependencies # Dependencies

View File

@ -1,11 +1,11 @@
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
plugins { plugins {
id 'java' id 'java'
id 'java-library' id 'java-library'
} }
group 'cc.sukazyo'
version moduleVersion
repositories { repositories {
mavenCentral() mavenCentral()
} }
@ -19,6 +19,31 @@ dependencies {
} }
final JavaVersion proj_java = JavaVersion.VERSION_17
final Charset proj_source_encoding = StandardCharsets.UTF_8
group 'cc.sukazyo'
version moduleVersion
test { test {
useJUnitPlatform() useJUnitPlatform()
} }
java {
sourceCompatibility proj_java
targetCompatibility proj_java
withSourcesJar()
}
tasks.withType(JavaCompile) {
options.encoding = proj_source_encoding.name()
}
tasks.withType(Javadoc) {
options.encoding = proj_source_encoding.name()
options.docEncoding = proj_source_encoding.name()
options.charSet = proj_source_encoding.name()
}

View File

@ -26,4 +26,17 @@ public record DifficultiesSekai(
action.accept(MASTER_NAME, master); action.accept(MASTER_NAME, master);
} }
@Override
@Nonnull
public String toString() {
return String.format(
"[{\"id\":\"%s\",%s},{\"id\":\"%s\",%s},{\"id\":\"%s\",%s},{\"id\":\"%s\",%s},{\"id\":\"%s\",%s}]",
EASY_NAME, easy.toStringSimple(),
NORMAL_NAME, normal.toStringSimple(),
HARD_NAME, hard.toStringSimple(),
EXPERT_NAME, expert.toStringSimple(),
MASTER_NAME, master.toStringSimple()
);
}
} }

View File

@ -1,8 +1,45 @@
package cc.sukazyo.sekai_scores; package cc.sukazyo.sekai_scores;
import javax.annotation.Nonnegative; import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
public record Difficulty( public record Difficulty(
@Nonnegative int level, @Nonnegative int level,
@Nonnegative int noteCount @Nonnegative int noteCount
) {} ) {
/**
* The difficulty number of this difficulty map.
* <p>
* it is a number in range 1-36 in official prsk game.
* @since 0.2
*/
@Nonnegative public int level () { return level; }
/**
* an alias of {@link #level} field.
* @since 0.3
* @see #level()
*/
@Nonnegative public int difficulty () { return level(); }
/**
* The total note count in this difficulty map.
* @since 0.2
*/
@Nonnegative public int noteCount () { return noteCount; }
@Override
@Nonnull
public String toString() {
return String.format("{%s}", toStringSimple());
}
@Nonnull
public String toStringSimple () {
return String.format(
"\"difficulty\":%d,\"notes\":%d",
level, noteCount
);
}
}

View File

@ -2,6 +2,7 @@ package cc.sukazyo.sekai_scores;
import javax.annotation.CheckForSigned; import javax.annotation.CheckForSigned;
import javax.annotation.Nonnegative; import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
/** /**
* @see ScoreBase * @see ScoreBase
@ -182,4 +183,17 @@ public class ScoreBaseData {
return combo; return combo;
} }
@Override
@Nonnull
public String toString() {
return String.format(
"{\"perfect\":%d,\"great\":%d,\"good\":%d,\"bad\":%d,\"miss\":%d,\"judge\":{\"fast\":%s,\"slow\":%s,\"flick\":%s},\"combo\":%s}",
notePerfect, noteGreat, noteGood, noteBad, noteMiss,
judgeFast==NULL ? "null" : judgeFast,
judgeSlow==NULL ? "null" : judgeFast,
judgeFlick==NULL ? "null" : judgeFast,
combo==NULL ? "null" : combo
);
}
} }

View File

@ -1,9 +1,24 @@
package cc.sukazyo.sekai_scores; package cc.sukazyo.sekai_scores;
import cc.sukazyo.sekai_scores.util.Converter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public record Song( public record Song(
@Nonnull String name, @Nonnull String name,
@Nonnull SongUnit unit, @Nonnull SongUnit unit,
@Nonnull Difficulties difficulties @Nonnull Difficulties difficulties
) {} ) {
@Override
@Nonnull
public String toString () {
return String.format(
"{\"name\":\"%s\",\"unit\":%s,\"difficulties\":%s}",
Converter.parseJSONString(name),
unit,
difficulties
);
}
}

View File

@ -1,23 +1,64 @@
package cc.sukazyo.sekai_scores; package cc.sukazyo.sekai_scores;
import cc.sukazyo.sekai_scores.util.Converter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public enum SongUnit { public enum SongUnit {
VSINGER("VIRTUAL SINGER"), VSINGER(0, "VIRTUAL SINGER"),
LEO_NEED("Leo/need"), LEO_NEED(1, "Leo/need"),
MORE_MORE_JUMP("MORE MORE JUMP!"), MORE_MORE_JUMP(2, "MORE MORE JUMP!"),
VIVID_BAD_SQUAD("Vivid BAD SQUAD"), VIVID_BAD_SQUAD(3, "Vivid BAD SQUAD"),
WONDERLANDS_SHOWTIME("ワンダーランズ×ショウタイム"), WONDERLANDS_SHOWTIME(4, "ワンダーランズ×ショウタイム"),
NIGHTCORD_25JI("25時、ナイトコードで。"), NIGHTCORD_25JI(5, "25時、ナイトコードで。"),
OTHER("other"), /**
SP("セカイ") * Just the "other" unit in game.
* @since 0.2
*/
OTHER(-1, "other"),
/**
* It collects that songs belongs to multiple units.
* <p>
* Like "Journey", "群青讃歌", it belongs to all of those units exists in game,
* and hard to assign those songs to those units exists. So this group was created,
* means the song belongs to "the whole セカイ".
* <p>
* This unit/group doesn't exist in the game.
* @since 0.2
*/
SP(-2, "セカイ")
; ;
/**
* An id of this group/unit.
* <p>
* The value start at 0 for {@link #VSINGER}
* and increment according to the order of the groups/units in the game.
* <p>
* for some special group/unit, it has a special id:
* <ul>
* <li>{@link #OTHER}: {@link -1}, as a special group that even exists in game</li>
* <li>{@link #SP}: {@link -2}, as a group that doesn't exist in game</li>
* </ul>
* @since 0.3
*/
public final int id;
@Nonnull public final String name; @Nonnull public final String name;
SongUnit (@Nonnull String name) { SongUnit (int id, @Nonnull String name) {
this.id = id;
this.name = name; this.name = name;
} }
@Override
@Nonnull
public String toString() {
return String.format(
"{\"id\":%d,\"fullname\":\"%s\"}",
id,
Converter.parseJSONString(name)
);
}
} }

View File

@ -1,11 +1,23 @@
package cc.sukazyo.sekai_scores; package cc.sukazyo.sekai_scores;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.time.LocalDateTime; import java.time.ZonedDateTime;
public record UserScore ( public record UserScore (
@Nonnull Song song, @Nonnull Song song,
@Nonnull Difficulty difficulty, @Nonnull Difficulty difficulty,
@Nonnull ScoreBase score, @Nonnull ScoreBase score,
@Nonnull LocalDateTime playtime @Nonnull ZonedDateTime playtime
) {} ) {
@Override
@Nonnull
public String toString () {
return String.format(
"{\"song\":%s,\"difficulty\":%s,\"score\":%s,\"playtime\":%d}",
song, difficulty, score,
playtime.toInstant().toEpochMilli()
);
}
}

View File

@ -0,0 +1,12 @@
package cc.sukazyo.sekai_scores.util;
import javax.annotation.Nonnull;
public class Converter {
@Nonnull
public static String parseJSONString (@Nonnull String input) {
return input.replaceAll("'", "\\'").replaceAll("\"", "\\\"");
}
}