ReModel: remove the CharacterInstanceId: client
This commit is contained in:
parent
a5adc61e90
commit
9cc6414648
67 changed files with 891 additions and 953 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package com.pixelized.server.lwa.model.character
|
||||
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheetJson
|
||||
import com.pixelized.shared.lwa.model.characterSheet.factory.CharacterSheetJsonFactory
|
||||
import com.pixelized.shared.lwa.protocol.rest.CharacterPreviewJson
|
||||
|
|
@ -24,11 +25,15 @@ class CharacterSheetService(
|
|||
initialValue = emptyMap()
|
||||
)
|
||||
|
||||
fun characters(): List<CharacterPreviewJson> {
|
||||
fun character(characterSheetId: String): CharacterSheet? {
|
||||
return sheets[characterSheetId]
|
||||
}
|
||||
|
||||
fun charactersJson(): List<CharacterPreviewJson> {
|
||||
return sheets.map { factory.convertToPreviewJson(sheet = it.value) }
|
||||
}
|
||||
|
||||
fun characterSheet(characterSheetId: String): CharacterSheetJson? {
|
||||
fun characterSheetJson(characterSheetId: String): CharacterSheetJson? {
|
||||
return sheets[characterSheetId]?.let(factory::convertToJson)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ fun Engine.removeCampaignNpc(): suspend io.ktor.server.routing.RoutingContext.()
|
|||
status = HttpStatusCode.OK,
|
||||
)
|
||||
webSocket.emit(
|
||||
value = CampaignEvent.UpdateScene(
|
||||
value = CampaignEvent.NpcRemoved(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
characterSheetId = characterSheetId,
|
||||
)
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ fun Engine.putCampaignScene(): suspend io.ktor.server.routing.RoutingContext.()
|
|||
webSocket.emit(
|
||||
value = CampaignEvent.UpdateScene(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
name = scene.name,
|
||||
)
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fun Engine.getCharacter(): suspend io.ktor.server.routing.RoutingContext.() -> U
|
|||
val characterSheetId = call.queryParameters.characterSheetId
|
||||
// get the character sheet of the given id.
|
||||
val characterSheet = characterService
|
||||
.characterSheet(characterSheetId = characterSheetId)
|
||||
.characterSheetJson(characterSheetId = characterSheetId)
|
||||
?: error("CharacterSheet with id:$characterSheetId not found.")
|
||||
// send it back to the user.
|
||||
call.respond(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import io.ktor.server.response.respond
|
|||
fun Engine.getCharacters(): suspend io.ktor.server.routing.RoutingContext.() -> Unit {
|
||||
return {
|
||||
call.respond(
|
||||
message = characterService.characters(),
|
||||
message = characterService.charactersJson(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,9 @@ fun Engine.putCharacterDamage(): suspend io.ktor.server.routing.RoutingContext.(
|
|||
val characterSheetId = call.queryParameters.characterSheetId
|
||||
val damage = call.queryParameters["damage"]?.toIntOrNull()
|
||||
?: error("Missing damage parameter.")
|
||||
// fetch the character sheet
|
||||
val characterSheet = characterService.character(characterSheetId)
|
||||
?: error("Character sheet not found for characterSheetId: $characterSheetId")
|
||||
// Update the character damage
|
||||
characterService.updateDamage(
|
||||
characterSheetId = characterSheetId,
|
||||
|
|
@ -27,6 +30,7 @@ fun Engine.putCharacterDamage(): suspend io.ktor.server.routing.RoutingContext.(
|
|||
value = CharacterSheetEvent.UpdateDamage(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
characterSheetId = characterSheetId,
|
||||
oldValue = characterSheet.damage,
|
||||
damage = damage,
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ fun Engine.putCharacterFatigue(): suspend io.ktor.server.routing.RoutingContext.
|
|||
val characterSheetId = call.queryParameters.characterSheetId
|
||||
val fatigue = call.queryParameters["fatigue"]?.toIntOrNull()
|
||||
?: error("Missing fatigue parameter.")
|
||||
// fetch the character sheet
|
||||
val characterSheet = characterService.character(characterSheetId)
|
||||
?: error("Character sheet not found for characterSheetId: $characterSheetId")
|
||||
// Update the character damage
|
||||
characterService.updateFatigue(
|
||||
characterSheetId = characterSheetId,
|
||||
|
|
@ -27,6 +30,7 @@ fun Engine.putCharacterFatigue(): suspend io.ktor.server.routing.RoutingContext.
|
|||
value = CharacterSheetEvent.UpdateFatigue(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
characterSheetId = characterSheetId,
|
||||
oldValue = characterSheet.fatigue,
|
||||
fatigue = fatigue,
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue