Add a basic version of the GM screen.
This commit is contained in:
parent
35396b6069
commit
6b86a6c075
42 changed files with 969 additions and 784 deletions
|
|
@ -33,7 +33,11 @@ class CampaignService(
|
|||
initialValue = factory.convertToJson(campaignFlow.value),
|
||||
)
|
||||
|
||||
fun campaign(): CampaignJson {
|
||||
fun campaign(): Campaign {
|
||||
return campaignFlow.value
|
||||
}
|
||||
|
||||
fun campaignJson(): CampaignJson {
|
||||
return campaignJsonFlow.value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ import io.ktor.server.response.respond
|
|||
|
||||
fun Engine.getCampaign(): suspend io.ktor.server.routing.RoutingContext.() -> Unit {
|
||||
return {
|
||||
call.respond(campaignService.campaign())
|
||||
call.respond(campaignService.campaignJson())
|
||||
}
|
||||
}
|
||||
|
|
@ -9,30 +9,43 @@ import io.ktor.server.response.respondText
|
|||
|
||||
fun Engine.putCampaignCharacter(): suspend io.ktor.server.routing.RoutingContext.() -> Unit {
|
||||
return {
|
||||
val characterSheetId = call.queryParameters["characterSheetId"]
|
||||
val instanceId = call.queryParameters["instanceId"]?.toIntOrNull()
|
||||
val id = if (characterSheetId != null && instanceId != null) {
|
||||
Campaign.CharacterInstance.Id(
|
||||
try {
|
||||
val characterSheetId = call.queryParameters["characterSheetId"]
|
||||
?: error("missing character sheet id")
|
||||
|
||||
val instanceId = campaignService.campaign().characters.keys
|
||||
.firstOrNull { key -> key.characterSheetId == characterSheetId }
|
||||
|
||||
if (instanceId != null) {
|
||||
error("Character Already in party")
|
||||
}
|
||||
|
||||
val id = Campaign.CharacterInstance.Id(
|
||||
characterSheetId = characterSheetId,
|
||||
instanceId = instanceId
|
||||
instanceId = 0,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val updated = id?.let { campaignService.addCharacter(it) } ?: false
|
||||
val code = when (updated) {
|
||||
true -> HttpStatusCode.Accepted
|
||||
else -> HttpStatusCode.UnprocessableEntity
|
||||
}
|
||||
call.respondText(
|
||||
text = "$code",
|
||||
status = code,
|
||||
)
|
||||
webSocket.emit(
|
||||
Message(
|
||||
from = "Server",
|
||||
value = RestSynchronisation.Campaign,
|
||||
|
||||
if (campaignService.addCharacter(id).not()) {
|
||||
error("Unexpected error occurred when the character instance was added to the party")
|
||||
}
|
||||
|
||||
call.respondText(
|
||||
text = "Character $characterSheetId successfully added to the party",
|
||||
status = HttpStatusCode.Accepted,
|
||||
)
|
||||
)
|
||||
webSocket.emit(
|
||||
Message(
|
||||
from = "Server",
|
||||
value = RestSynchronisation.Campaign,
|
||||
)
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
call.run {
|
||||
respondText(
|
||||
text = "${exception.message}",
|
||||
status = HttpStatusCode.UnprocessableEntity,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,35 +9,46 @@ import io.ktor.server.response.respondText
|
|||
|
||||
fun Engine.putCampaignNpc(): suspend io.ktor.server.routing.RoutingContext.() -> Unit {
|
||||
return {
|
||||
val characterSheetId = call.queryParameters["characterSheetId"]
|
||||
val instanceId = call.queryParameters["instanceId"]?.toIntOrNull()
|
||||
try {
|
||||
val characterSheetId = call.queryParameters["characterSheetId"]
|
||||
?: error("missing character sheet id")
|
||||
|
||||
val id = if (characterSheetId != null && instanceId != null) {
|
||||
Campaign.CharacterInstance.Id(
|
||||
val instanceId = campaignService.campaign().npcs.keys
|
||||
.filter { it.characterSheetId == characterSheetId }
|
||||
.reduceOrNull { acc, id ->
|
||||
if (acc.instanceId < id.instanceId) {
|
||||
id
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
}
|
||||
|
||||
val id = Campaign.CharacterInstance.Id(
|
||||
characterSheetId = characterSheetId,
|
||||
instanceId = instanceId
|
||||
instanceId = instanceId?.let { it.instanceId + 1 } ?: 0,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val updated = id?.let { campaignService.addNpc(it) } ?: false
|
||||
if (campaignService.addNpc(id).not()) {
|
||||
error("Unexpected error occurred when the character instance was added to the npcs")
|
||||
}
|
||||
|
||||
val code = when (updated) {
|
||||
true -> HttpStatusCode.Accepted
|
||||
else -> HttpStatusCode.UnprocessableEntity
|
||||
}
|
||||
|
||||
call.respondText(
|
||||
text = "$code",
|
||||
status = code,
|
||||
)
|
||||
|
||||
webSocket.emit(
|
||||
Message(
|
||||
from = "Server",
|
||||
value = RestSynchronisation.Campaign,
|
||||
call.respondText(
|
||||
text = "Character $characterSheetId successfully added to the npcs",
|
||||
status = HttpStatusCode.Accepted,
|
||||
)
|
||||
)
|
||||
webSocket.emit(
|
||||
Message(
|
||||
from = "Server",
|
||||
value = RestSynchronisation.Campaign,
|
||||
)
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
call.run {
|
||||
respondText(
|
||||
text = "${exception.message}",
|
||||
status = HttpStatusCode.UnprocessableEntity,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue