Skip to content

Commit

Permalink
load sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
ManApart committed Dec 15, 2023
1 parent 17c6dbd commit 549601e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/jsMain/kotlin/Persistance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fun loadPictures(): Promise<*> {

fun exportPlayerInfo() = exportData(jsonMapper.encodeToString(inMemoryStorage), "StarfieldEye.json")

fun exportPictures() = exportData(jsonMapper.encodeToString(pictureStorage), "starfield-pictures.json")
fun exportPictures() = exportData(jsonMapper.encodeToString(pictureStorage), "StarfieldPictures.json")

private fun exportData(data: String, fileName: String) {
val download = document.createElement("a") as HTMLElement
Expand Down Expand Up @@ -226,4 +226,26 @@ fun savePicture(key: String, data: String) {
fun deletePicture(key: String) {
pictureStorage.remove(key)
persistPictures()
}

fun loadSampleData(status: HTMLElement) {
try {
status.innerText = "Loading Player Info"
loadJson("sample/StarfieldEye.json").then { playerJson ->
jsonMapper.decodeFromString<InMemoryStorage>(playerJson).also { inMemoryStorage = it }
println("Imported ${inMemoryStorage.planetUserInfo.size} user info pieces")
status.innerText = "Loading Pictures"
loadJson("sample/StarfieldPictures.json").then { pictureJson ->
jsonMapper.decodeFromString<Map<String, String>>(pictureJson)
.also { pictureStorage = it.toMutableMap() }
println("Imported ${pictureStorage.keys.size} pictures")
persistMemory()
persistPictures()
status.innerText = "Loaded sample data!"
}
}
} catch (e: Exception) {
status.innerText = "Loading sample data failed"
}

}
14 changes: 14 additions & 0 deletions src/jsMain/kotlin/views/AboutView.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package views

import components.linkableH2
import el
import kotlinx.html.*
import kotlinx.html.js.onClickFunction
import loadSampleData
import org.w3c.dom.HTMLElement
import replaceElement
import updateUrl
Expand All @@ -23,6 +26,17 @@ fun aboutView(section: String? = null) {

p { +"Open it on a second monitor while playing, or on your phone to plan your next adventure." }

p {
span {
id = "load-sample-data-text"
+"If you'd like to explore with sample data, click this button: "
}
button {
+"Load Sample Data"
onClickFunction = { loadSampleData(el("load-sample-data-text")) }
}
}

p { +"The Crew page also links to similar sites made by others, so you can pick the one that works best for you." }

p {
Expand Down
7 changes: 7 additions & 0 deletions src/jsMain/kotlin/views/DockView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.html.*
import kotlinx.html.js.onClickFunction
import loadSampleData
import missionReference
import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement
Expand Down Expand Up @@ -121,6 +122,12 @@ private fun TagConsumer<HTMLElement>.manageData() {
p { +"I recommend using the thumbnail image when uploading screenshots from photo mode. While you can upload any size you want, the backup will be much smaller if you use the thumbnails, and they're generally still as large as the displayed image on the site." }
p { +"If you're having issues with the site, it's possible that deleting your user data may fix them. Make sure to export your data first so you have a backup." }

div {
button {
+"Load Sample Data"
onClickFunction = { loadSampleData(el("load-status")) }
}
}
div {
button {
id = "import-button"
Expand Down
1 change: 1 addition & 0 deletions src/jsMain/resources/sample/StarfieldEye.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/jsMain/resources/sample/StarfieldPictures.json

Large diffs are not rendered by default.

0 comments on commit 549601e

Please sign in to comment.