mirror of
https://github.com/Eyre-S/sekai-scores.git
synced 2024-11-22 03:04:55 +08:00
implement toString to serialize to JSON format, add "id" field for SongUnit
This commit is contained in:
parent
28ff69ceb8
commit
3032af55e5
@ -19,6 +19,8 @@ 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")
|
||||
|
||||
}
|
||||
|
||||
final JavaVersion proj_java = JavaVersion.VERSION_17
|
||||
|
@ -1,7 +1,7 @@
|
||||
## Project Configurations
|
||||
|
||||
# Proj Metadata
|
||||
projVersion = 0.2
|
||||
projVersion = 0.3
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
@ -1,11 +1,11 @@
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group 'cc.sukazyo'
|
||||
version moduleVersion
|
||||
|
||||
repositories {
|
||||
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 {
|
||||
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()
|
||||
}
|
||||
|
@ -26,4 +26,17 @@ public record DifficultiesSekai(
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,45 @@
|
||||
package cc.sukazyo.sekai_scores;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public record Difficulty(
|
||||
@Nonnegative int level,
|
||||
@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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cc.sukazyo.sekai_scores;
|
||||
|
||||
import javax.annotation.CheckForSigned;
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* @see ScoreBase
|
||||
@ -182,4 +183,17 @@ public class ScoreBaseData {
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,24 @@
|
||||
package cc.sukazyo.sekai_scores;
|
||||
|
||||
import cc.sukazyo.sekai_scores.util.Converter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public record Song(
|
||||
@Nonnull String name,
|
||||
@Nonnull SongUnit unit,
|
||||
@Nonnull Difficulties difficulties
|
||||
) {}
|
||||
) {
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String toString () {
|
||||
return String.format(
|
||||
"{\"name\":\"%s\",\"unit\":%s,\"difficulties\":%s}",
|
||||
Converter.parseJSONString(name),
|
||||
unit,
|
||||
difficulties
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,64 @@
|
||||
package cc.sukazyo.sekai_scores;
|
||||
|
||||
import cc.sukazyo.sekai_scores.util.Converter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public enum SongUnit {
|
||||
|
||||
VSINGER("VIRTUAL SINGER"),
|
||||
LEO_NEED("Leo/need"),
|
||||
MORE_MORE_JUMP("MORE MORE JUMP!"),
|
||||
VIVID_BAD_SQUAD("Vivid BAD SQUAD"),
|
||||
WONDERLANDS_SHOWTIME("ワンダーランズ×ショウタイム"),
|
||||
NIGHTCORD_25JI("25時、ナイトコードで。"),
|
||||
OTHER("other"),
|
||||
SP("セカイ")
|
||||
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時、ナイトコードで。"),
|
||||
/**
|
||||
* 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;
|
||||
|
||||
SongUnit (@Nonnull String name) {
|
||||
SongUnit (int id, @Nonnull String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"{\"id\":%d,\"fullname\":\"%s\"}",
|
||||
id,
|
||||
Converter.parseJSONString(name)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,23 @@
|
||||
package cc.sukazyo.sekai_scores;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public record UserScore (
|
||||
@Nonnull Song song,
|
||||
@Nonnull Difficulty difficulty,
|
||||
@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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
12
src/main/java/cc/sukazyo/sekai_scores/util/Converter.java
Normal file
12
src/main/java/cc/sukazyo/sekai_scores/util/Converter.java
Normal 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("\"", "\\\"");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user