Skip to content

Commit

Permalink
import statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
ManApart committed Dec 15, 2023
1 parent 2f872ae commit 17c6dbd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
28 changes: 20 additions & 8 deletions src/jsMain/kotlin/Persistance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,31 @@ private fun exportData(data: String, fileName: String) {
document.body?.removeChild(download)
}

fun importPlayerInfo() {
fun importPlayerInfo(status: HTMLElement) {
importData { data ->
jsonMapper.decodeFromString<InMemoryStorage>(data).also { inMemoryStorage = it }
println("Imported ${inMemoryStorage.planetUserInfo.size} user info pieces")
persistMemory()
try {
jsonMapper.decodeFromString<InMemoryStorage>(data).also { inMemoryStorage = it }
println("Imported ${inMemoryStorage.planetUserInfo.size} user info pieces")
persistMemory()
status.innerText = "Player Info Imported"
} catch (e: Exception) {
println("Import failed")
status.innerText = "Import failed"
}
}
}

fun importPictures() {
fun importPictures(status: HTMLElement) {
importData { data ->
jsonMapper.decodeFromString<Map<String, String>>(data).also { pictureStorage = it.toMutableMap() }
println("Imported ${pictureStorage.keys.size} pictures")
persistPictures()
try {
jsonMapper.decodeFromString<Map<String, String>>(data).also { pictureStorage = it.toMutableMap() }
println("Imported ${pictureStorage.keys.size} pictures")
persistPictures()
status.innerText = "Pictures Imported"
} catch (e: Exception) {
println("Import failed")
status.innerText = "Import failed"
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/jsMain/kotlin/views/DockView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private fun TagConsumer<HTMLElement>.manageData() {
id = "import-button"
+"Import Data"
title = "Import saved user data"
onClickFunction = { importPlayerInfo() }
onClickFunction = { importPlayerInfo(el("load-status")) }
}
button {
id = "export-button"
Expand All @@ -146,7 +146,7 @@ private fun TagConsumer<HTMLElement>.manageData() {
id = "import-images-button"
+"Import Images"
title = "Import saved user images"
onClickFunction = { importPictures() }
onClickFunction = { importPictures(el("load-status")) }
}
button {
id = "export-images-button"
Expand All @@ -155,6 +155,9 @@ private fun TagConsumer<HTMLElement>.manageData() {
onClickFunction = { exportPictures() }
}
}
p{
id = "load-status"
}
}
}

Expand Down

0 comments on commit 17c6dbd

Please sign in to comment.