Refactor the character sheet edit.
This commit is contained in:
parent
edf58fd215
commit
eb7b653bd7
71 changed files with 3155 additions and 489 deletions
|
|
@ -31,6 +31,10 @@ class CharacterSheetService(
|
|||
return sheets[characterSheetId]
|
||||
}
|
||||
|
||||
fun charactersJson(characterSheetId: String): CharacterPreviewJson? {
|
||||
return sheets[characterSheetId]?.let { factory.convertToPreviewJson(sheet = it) }
|
||||
}
|
||||
|
||||
fun charactersJson(): List<CharacterPreviewJson> {
|
||||
return sheets.map { factory.convertToPreviewJson(sheet = it.value) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ class Engine(
|
|||
characterSheetId = message.characterSheetId,
|
||||
)
|
||||
|
||||
is CampaignEvent.UpdateScene -> Unit // TODO
|
||||
is CampaignEvent.UpdateScene -> Unit
|
||||
}
|
||||
|
||||
is ApiSynchronisation -> Unit // Nothing to do there.
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ import com.pixelized.server.lwa.server.rest.campaign.removeCampaignCharacter
|
|||
import com.pixelized.server.lwa.server.rest.campaign.removeCampaignNpc
|
||||
import com.pixelized.server.lwa.server.rest.character.deleteCharacter
|
||||
import com.pixelized.server.lwa.server.rest.character.getCharacter
|
||||
import com.pixelized.server.lwa.server.rest.character.getCharacters
|
||||
import com.pixelized.server.lwa.server.rest.character.getPreviewCharacter
|
||||
import com.pixelized.server.lwa.server.rest.character.getPreviewCharacters
|
||||
import com.pixelized.server.lwa.server.rest.character.putCharacter
|
||||
import com.pixelized.server.lwa.server.rest.character.putCharacterAlteration
|
||||
import com.pixelized.server.lwa.server.rest.character.putCharacterDamage
|
||||
|
|
@ -107,7 +108,7 @@ class LocalServer {
|
|||
try {
|
||||
send(frame)
|
||||
} catch (exception: Exception) {
|
||||
// TODO
|
||||
// TODO proper exception handling
|
||||
println("WebSocket exception: ${exception.localizedMessage}")
|
||||
}
|
||||
}
|
||||
|
|
@ -125,7 +126,7 @@ class LocalServer {
|
|||
}
|
||||
}
|
||||
}.onFailure { exception ->
|
||||
// TODO
|
||||
// TODO proper exception handling
|
||||
println("WebSocket exception: ${exception.message}")
|
||||
}.also {
|
||||
job.cancel()
|
||||
|
|
@ -165,10 +166,6 @@ class LocalServer {
|
|||
route(
|
||||
path = "/character",
|
||||
) {
|
||||
get(
|
||||
path = "/all",
|
||||
body = engine.getCharacters(),
|
||||
)
|
||||
get(
|
||||
path = "/detail",
|
||||
body = engine.getCharacter(),
|
||||
|
|
@ -201,6 +198,18 @@ class LocalServer {
|
|||
body = engine.putCharacterAlteration(),
|
||||
)
|
||||
}
|
||||
route(
|
||||
path = "/preview"
|
||||
) {
|
||||
get(
|
||||
path = "/all",
|
||||
body = engine.getPreviewCharacters(),
|
||||
)
|
||||
get(
|
||||
path = "/detail",
|
||||
body = engine.getPreviewCharacter(),
|
||||
)
|
||||
}
|
||||
}
|
||||
route(
|
||||
path = "/alteration",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.pixelized.server.lwa.server.rest.character
|
||||
|
||||
import com.pixelized.server.lwa.server.Engine
|
||||
import com.pixelized.server.lwa.utils.extentions.characterSheetId
|
||||
import com.pixelized.server.lwa.utils.extentions.exception
|
||||
import com.pixelized.shared.lwa.protocol.rest.APIResponse
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.RoutingContext
|
||||
|
||||
fun Engine.getPreviewCharacter(): suspend RoutingContext.() -> Unit {
|
||||
return {
|
||||
try {
|
||||
// get the query parameter
|
||||
val characterSheetId = call.queryParameters.characterSheetId
|
||||
// fetch the character preview
|
||||
val json = characterService.charactersJson(characterSheetId = characterSheetId)
|
||||
?: error("CharacterSheet preview with id:$characterSheetId not found.")
|
||||
// send it back to the user.
|
||||
call.respond(
|
||||
message = APIResponse.success(
|
||||
data = json,
|
||||
),
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
call.exception(
|
||||
exception = exception
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import com.pixelized.shared.lwa.protocol.rest.APIResponse
|
|||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.RoutingContext
|
||||
|
||||
fun Engine.getCharacters(): suspend RoutingContext.() -> Unit {
|
||||
fun Engine.getPreviewCharacters(): suspend RoutingContext.() -> Unit {
|
||||
return {
|
||||
try {
|
||||
call.respond(
|
||||
Loading…
Add table
Add a link
Reference in a new issue