-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
achievements: Implement save achievements marked status
- Loading branch information
Showing
18 changed files
with
209 additions
and
9 deletions.
There are no files selected for viewing
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
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
6 changes: 6 additions & 0 deletions
6
wwm/core/data/src/commonMain/kotlin/dev/omico/wwm/data/WwmMarkedAchievementIds.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,6 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.data | ||
|
||
typealias WwmMarkedAchievementIds = Set<Int> |
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
19 changes: 19 additions & 0 deletions
19
wwm/core/data/src/commonMain/kotlin/dev/omico/wwm/data/internal/Json.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,19 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.data.internal | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
internal val json: Json = | ||
Json { | ||
prettyPrint = true | ||
prettyPrintIndent = " " | ||
} | ||
|
||
internal inline fun <reified T> T.toJson(): String = json.encodeToString(this) | ||
|
||
internal inline fun <reified T> String.fromJson(): T = json.decodeFromString(this) |
12 changes: 12 additions & 0 deletions
12
...ore/data/src/commonMain/kotlin/dev/omico/wwm/data/internal/MarkedAchievementsDataStore.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,12 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.data.internal | ||
|
||
import dev.omico.wwm.data.WwmMarkedAchievementIds | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") // TODO KT-61573 | ||
internal expect class MarkedAchievementsDataStore() { | ||
suspend fun load(): WwmMarkedAchievementIds | ||
suspend fun save(ids: WwmMarkedAchievementIds) | ||
} |
21 changes: 21 additions & 0 deletions
21
...src/desktopMain/kotlin/dev/omico/wwm/data/internal/MarkedAchievementsDataStore.desktop.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,21 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.data.internal | ||
|
||
import dev.omico.wwm.data.WwmMarkedAchievementIds | ||
import dev.omico.wwm.foundation.wwmMarkedAchievementsFile | ||
import java.nio.file.Path | ||
import kotlin.io.path.exists | ||
import kotlin.io.path.readText | ||
import kotlin.io.path.writeText | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") // TODO KT-61573 | ||
internal actual class MarkedAchievementsDataStore { | ||
actual suspend fun load(): WwmMarkedAchievementIds = | ||
wwmMarkedAchievementsFile.takeIf(Path::exists)?.readText()?.fromJson<WwmMarkedAchievementIds>() ?: emptySet() | ||
|
||
actual suspend fun save(ids: WwmMarkedAchievementIds) { | ||
wwmMarkedAchievementsFile.writeText(ids.toJson()) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...a/src/wasmJsMain/kotlin/dev/omico/wwm/data/internal/MarkedAchievementsDataStore.wasmJs.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,20 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.data.internal | ||
|
||
import dev.omico.wwm.data.WwmMarkedAchievementIds | ||
import kotlinx.browser.localStorage | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") // TODO KT-61573 | ||
internal actual class MarkedAchievementsDataStore { | ||
actual suspend fun load(): WwmMarkedAchievementIds { | ||
val achievements = localStorage.getItem(ACHIEVEMENTS_KEY) ?: return emptySet() | ||
return achievements.split(",").map(String::toInt).toSet() | ||
} | ||
|
||
actual suspend fun save(ids: WwmMarkedAchievementIds): Unit = | ||
localStorage.setItem(ACHIEVEMENTS_KEY, ids.joinToString(",")) | ||
} | ||
|
||
private const val ACHIEVEMENTS_KEY = "achievements" |
20 changes: 20 additions & 0 deletions
20
...re/data/src/webMain/kotlin/dev/omico/wwm/data/internal/MarkedAchievementsDataStore.web.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,20 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.data.internal | ||
|
||
import dev.omico.wwm.data.WwmMarkedAchievementIds | ||
import kotlinx.browser.localStorage | ||
|
||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") // TODO KT-61573 | ||
internal actual class MarkedAchievementsDataStore { | ||
actual suspend fun load(): WwmMarkedAchievementIds { | ||
val achievements = localStorage.getItem(ACHIEVEMENTS_KEY) ?: return emptySet() | ||
return achievements.split(",").map(String::toInt).toSet() | ||
} | ||
|
||
actual suspend fun save(ids: WwmMarkedAchievementIds): Unit = | ||
localStorage.setItem(ACHIEVEMENTS_KEY, ids.joinToString(",")) | ||
} | ||
|
||
private const val ACHIEVEMENTS_KEY = "achievements" |
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
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
10 changes: 10 additions & 0 deletions
10
...ndation/src/desktopMain/kotlin/dev/omico/wwm/foundation/DesktopApplicationEnvironments.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,10 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.foundation | ||
|
||
object DesktopApplicationEnvironments { | ||
private val environments: Map<String, String> = System.getenv() | ||
|
||
val WWM_LOCAL_DIRECTORY: String? = environments["WWM_LOCAL_DIRECTORY"] | ||
} |
16 changes: 16 additions & 0 deletions
16
...ore/foundation/src/desktopMain/kotlin/dev/omico/wwm/foundation/DesktopApplicationPaths.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,16 @@ | ||
/* | ||
* Copyright 2024 Omico. All Rights Reserved. | ||
*/ | ||
package dev.omico.wwm.foundation | ||
|
||
import java.nio.file.Path | ||
import kotlin.io.path.Path | ||
import kotlin.io.path.createParentDirectories | ||
|
||
private val userHomeDirectory: Path = Path(System.getProperty("user.home")) | ||
|
||
private val wwmLocalDirectory: Path = | ||
DesktopApplicationEnvironments.WWM_LOCAL_DIRECTORY?.let(::Path) | ||
?: userHomeDirectory.resolve(".wwm") | ||
|
||
val wwmMarkedAchievementsFile: Path = wwmLocalDirectory.resolve("MarkedAchievements.json").createParentDirectories() |