-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d26c5a7
commit 0b6fc90
Showing
32 changed files
with
574 additions
and
159 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions
86
app/src/main/java/io/github/skydynamic/maiproberplus/core/data/chuni/ChuniData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package io.github.skydynamic.maiproberplus.core.data.chuni | ||
|
||
import android.content.Context | ||
import io.github.skydynamic.maiproberplus.Application | ||
import io.github.skydynamic.maiproberplus.core.prober.client | ||
import io.ktor.client.request.get | ||
import io.ktor.client.statement.bodyAsText | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.Json | ||
import java.io.File | ||
|
||
val JSON = Json { | ||
ignoreUnknownKeys = true | ||
encodeDefaults = true | ||
} | ||
|
||
class ChuniData { | ||
@Serializable | ||
data class SongDifficulty( | ||
val difficulty: Int, | ||
val level: String, | ||
@SerialName("level_value") val levelValue: Float, | ||
@SerialName("note_designer") val noteDesigner: String, | ||
val version: Int, | ||
val kanji: String = "", | ||
val star: Int = 0, | ||
) | ||
|
||
@Serializable | ||
data class SongInfo( | ||
val id: Int, val title: String, val artist: String, val genre: String, | ||
val bpm: Int, val version: Int, val difficulties: List<SongDifficulty> | ||
) | ||
|
||
@Serializable | ||
data class MusicDetail( | ||
val name: String, val level: Float, | ||
val score: Int, val rating: Float, | ||
val version: Int, val rankType: ChuniEnums.RankType, | ||
val diff: ChuniEnums.Difficulty, val fullComboType: ChuniEnums.FullComboType, | ||
val clearType: ChuniEnums.ClearType, val fullChainType: ChuniEnums.FullChainType | ||
) | ||
|
||
@Serializable | ||
data class LxnsSongListResponse(val songs: List<SongInfo>) | ||
|
||
companion object { | ||
var CHUNI_SONG_LIST = readChuniSongList() | ||
|
||
@OptIn(DelicateCoroutinesApi::class) | ||
fun syncMaimaiSongList() { | ||
val context = Application.application | ||
var listFile = File(context.filesDir, "chuni_song_list.json") | ||
|
||
GlobalScope.launch(Dispatchers.IO) { | ||
val result = | ||
client.get("https://maimai.lxns.net/api/v0/chunithm/song/list?notes=true") | ||
listFile.deleteOnExit() | ||
listFile.createNewFile() | ||
val bufferedWriter = | ||
context.openFileOutput("chuni_song_list.json", Context.MODE_PRIVATE) | ||
.bufferedWriter() | ||
bufferedWriter.write(result.bodyAsText()) | ||
bufferedWriter.close() | ||
} | ||
|
||
CHUNI_SONG_LIST = readChuniSongList() | ||
} | ||
|
||
private fun readChuniSongList(): List<SongInfo> { | ||
return JSON.decodeFromString<LxnsSongListResponse>( | ||
Application.application.getFilesDirInputStream("chuni_song_list.json") | ||
.bufferedReader().use { it.readText() } | ||
).songs | ||
} | ||
|
||
fun getSongIdFromTitle(title: String): Int { | ||
return CHUNI_SONG_LIST.find { it.title == title }?.id ?: -1 | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
app/src/main/java/io/github/skydynamic/maiproberplus/core/data/chuni/ChuniEnums.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package io.github.skydynamic.maiproberplus.core.data.chuni | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
class ChuniEnums { | ||
@Serializable | ||
enum class Difficulty(val diffName: String, val diffIndex: Int) { | ||
BASIC("Basic", 0), | ||
ADVANCED("Advanced", 1), | ||
EXPERT("Expert", 2), | ||
MASTER("Master", 3), | ||
ULTIMA("Ultima", 4), | ||
WORLDSEND("World's End", 5), | ||
RECENT("Recent", 6); | ||
|
||
companion object { | ||
@JvmStatic | ||
fun getDifficultyWithName(diffName: String): Difficulty { | ||
for (difficulty in entries) { | ||
if (difficulty.diffName.lowercase() == diffName.lowercase()) { | ||
return difficulty | ||
} | ||
} | ||
throw IllegalArgumentException("No such difficulty") | ||
} | ||
} | ||
} | ||
|
||
@Serializable | ||
enum class ClearType(val type: String) { | ||
CATASTROPHY("catastrophy"), | ||
ABSOLUTEP("absolutep"), | ||
ABSOLUTE("absolute"), | ||
HARD("hard"), | ||
CLEAR("clear"), | ||
FAILED("failed"); | ||
} | ||
|
||
@Serializable | ||
enum class FullComboType(val type: String) { | ||
NULL(""), | ||
AJC("alljusticecritical"), | ||
AJ("alljustice"), | ||
FC("fullcombo"); | ||
} | ||
|
||
@Serializable | ||
enum class FullChainType(val type: String) { | ||
NULL(""), | ||
FC("fullchain"), | ||
GFC("fullchain2") | ||
} | ||
|
||
@Serializable | ||
enum class RankType( | ||
val rank: String, | ||
private val intRange: IntRange, | ||
) { | ||
D("d", 0..499999), | ||
C("c", 500000..599999), | ||
B("b", 600000..699999), | ||
BB("bb", 700000..799999), | ||
BBB("bbb", 800000..899999), | ||
A("a", 900000..924999), | ||
AA("aa", 925000..949999), | ||
AAA("aaa", 950000..974999), | ||
S("s", 975000..989999), | ||
SP("sp", 990000..999999), | ||
SS("ss", 1000000..1004999), | ||
SSP("ssp", 1005000..1007499), | ||
SSS("sss", 1007500..1008999), | ||
SSSP("sssp", 1009000..1010000); | ||
|
||
companion object { | ||
@JvmStatic | ||
fun getRankTypeByScore(score: Int): RankType { | ||
var returnValue = D | ||
for (rank in entries) { | ||
if (score in rank.intRange) { | ||
returnValue = rank | ||
} | ||
} | ||
return returnValue | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.