Add visibility toggle for player & npc + refactor WebSocketMessage.

This commit is contained in:
Andres Gomez, Thomas (ITDV RL) 2025-03-19 15:19:31 +01:00
parent 2d164b265e
commit 4c37d8b937
47 changed files with 475 additions and 304 deletions

View file

@ -4,6 +4,7 @@ data class Campaign(
val characters: Map<CharacterInstance.Id, CharacterInstance>,
val npcs: Map<CharacterInstance.Id, CharacterInstance>,
val scene: Scene,
val options: Options,
) {
data class CharacterInstance(
val characteristic: Map<Characteristic, Int>,
@ -53,11 +54,24 @@ data class Campaign(
}
}
data class Options(
val showParty: Boolean,
val showNpcs: Boolean,
) {
companion object {
fun empty() = Options(
showParty = true,
showNpcs = false,
)
}
}
companion object {
val EMPTY = Campaign(
characters = emptyMap(),
npcs = emptyMap(),
scene = Scene.empty(),
options = Options.empty(),
)
}
}

View file

@ -14,4 +14,7 @@ sealed interface CampaignJson {
@Serializable
sealed interface SceneJson
@Serializable
sealed interface OptionJson
}

View file

@ -7,6 +7,7 @@ data class CampaignJsonV1(
val characters: Map<String, CharacterInstanceJsonV1>,
val npcs: Map<String, CharacterInstanceJsonV1>,
val scene: SceneJsonV1?,
val options: OptionsJsonV1?,
) : CampaignJson {
@Serializable
@ -24,4 +25,10 @@ data class CampaignJsonV1(
data class SceneJsonV1(
val name: String,
) : CampaignJson.SceneJson
@Serializable
data class OptionsJsonV1(
val showPlayer: Boolean,
val showNpcs: Boolean,
) : CampaignJson.OptionJson
}

View file

@ -58,6 +58,10 @@ class CampaignJsonFactory(
.toMap(),
scene = CampaignJsonV1.SceneJsonV1(
name = data.scene.name
),
options = CampaignJsonV1.OptionsJsonV1(
showPlayer = data.options.showParty,
showNpcs = data.options.showNpcs,
)
)
}

View file

@ -26,6 +26,9 @@ class CampaignJsonV1Factory {
scene = campaignJson.scene
?.let { convertFromV1(it) }
?: Campaign.Scene.empty(),
options = campaignJson.options
?.let { convertFromV1(it) }
?:Campaign.Options.empty()
)
}
@ -66,4 +69,13 @@ class CampaignJsonV1Factory {
name = sceneJson.name
)
}
fun convertFromV1(
optionsJson: CampaignJsonV1.OptionsJsonV1,
): Campaign.Options {
return Campaign.Options(
showParty = optionsJson.showPlayer,
showNpcs = optionsJson.showNpcs
)
}
}

View file

@ -1,16 +1,17 @@
package com.pixelized.shared.lwa.protocol.websocket.payload
package com.pixelized.shared.lwa.protocol.websocket
import com.pixelized.shared.lwa.model.campaign.CampaignJsonV1
import kotlinx.serialization.Serializable
@Serializable
sealed interface CampaignMessage : MessagePayload {
val prefix: Char
val characterSheetId: String
val instanceId: Int
sealed interface CampaignMessage : SocketMessage, CharacterInstanceIdMessage {
override val prefix: Char
override val characterSheetId: String
override val instanceId: Int
@Serializable
data class UpdateCharacteristic(
override val timestamp: Long,
override val prefix: Char,
override val characterSheetId: String,
override val instanceId: Int,
@ -20,6 +21,7 @@ sealed interface CampaignMessage : MessagePayload {
@Serializable
data class UpdateDiminished(
override val timestamp: Long,
override val prefix: Char,
override val characterSheetId: String,
override val instanceId: Int,

View file

@ -0,0 +1,15 @@
package com.pixelized.shared.lwa.protocol.websocket
import kotlinx.serialization.Serializable
@Serializable
sealed interface CharacterSheetIdMessage {
val characterSheetId: String
}
@Serializable
sealed interface CharacterInstanceIdMessage : CharacterSheetIdMessage {
override val characterSheetId: String
val prefix: Char
val instanceId: Int
}

View file

@ -0,0 +1,17 @@
package com.pixelized.shared.lwa.protocol.websocket
import kotlinx.serialization.Serializable
@Serializable
sealed interface GameMasterEvent : SocketMessage {
@Serializable
class ToggleNpc(
override val timestamp: Long,
) : GameMasterEvent
@Serializable
class TogglePlayer(
override val timestamp: Long,
) : GameMasterEvent
}

View file

@ -1,10 +0,0 @@
package com.pixelized.shared.lwa.protocol.websocket
import com.pixelized.shared.lwa.protocol.websocket.payload.MessagePayload
import kotlinx.serialization.Serializable
@Serializable
data class Message(
val from: String,
val value: MessagePayload,
)

View file

@ -0,0 +1,24 @@
package com.pixelized.shared.lwa.protocol.websocket
import kotlinx.serialization.Serializable
@Serializable
sealed class RestSynchronisation : SocketMessage {
@Serializable
data class CharacterSheetUpdate(
override val timestamp: Long,
override val characterSheetId: String,
) : RestSynchronisation(), CharacterSheetIdMessage
@Serializable
data class CharacterSheetDelete(
override val timestamp: Long,
override val characterSheetId: String,
) : RestSynchronisation(), CharacterSheetIdMessage
@Serializable
data class Campaign(
override val timestamp: Long,
) : RestSynchronisation()
}

View file

@ -0,0 +1,26 @@
package com.pixelized.shared.lwa.protocol.websocket
import kotlinx.serialization.Serializable
@Serializable
data class RollMessage(
override val timestamp: Long,
val uuid: String,
val prefix: Char,
val characterSheetId: String,
val instanceId: Int?,
val skillLabel: String,
val rollValue: Int,
val resultLabel: String? = null,
val rollDifficulty: String? = null,
val rollSuccessLimit: Int? = null,
val critical: Critical? = null,
) : SocketMessage {
enum class Critical {
CRITICAL_SUCCESS,
SPECIAL_SUCCESS,
SUCCESS,
FAILURE,
CRITICAL_FAILURE
}
}

View file

@ -0,0 +1,8 @@
package com.pixelized.shared.lwa.protocol.websocket
import kotlinx.serialization.Serializable
@Serializable
sealed interface SocketMessage {
val timestamp: Long
}

View file

@ -0,0 +1,13 @@
package com.pixelized.shared.lwa.protocol.websocket
import kotlinx.serialization.Serializable
@Serializable
data class ToggleActiveAlteration(
override val timestamp: Long,
override val characterSheetId: String,
override val prefix: Char,
override val instanceId: Int,
val alterationId: String,
val active: Boolean,
) : SocketMessage, CharacterInstanceIdMessage

View file

@ -0,0 +1,11 @@
package com.pixelized.shared.lwa.protocol.websocket
import kotlinx.serialization.Serializable
@Serializable
data class UpdateSkillUsageMessage(
override val timestamp: Long,
override val characterSheetId: String,
val skillId: String,
val used: Boolean,
) : SocketMessage, CharacterSheetIdMessage

View file

@ -1,6 +0,0 @@
package com.pixelized.shared.lwa.protocol.websocket.payload
import kotlinx.serialization.Serializable
@Serializable
sealed interface MessagePayload

View file

@ -1,27 +0,0 @@
package com.pixelized.shared.lwa.protocol.websocket.payload
import kotlinx.serialization.Serializable
@Serializable
sealed class RestSynchronisation : MessagePayload {
@Serializable
data class CharacterUpdate(
val id: String,
) : RestSynchronisation()
@Serializable
data class CharacterDelete(
val characterId: String,
) : RestSynchronisation()
@Serializable
data class ToggleActiveAlteration(
val characterId: String,
val alterationId: String,
val active: Boolean,
) : RestSynchronisation()
@Serializable
data object Campaign : RestSynchronisation()
}

View file

@ -1,43 +0,0 @@
package com.pixelized.shared.lwa.protocol.websocket.payload
import kotlinx.serialization.Serializable
import java.util.UUID
@Serializable
data class RollMessage(
val id: RollId,
val prefix: Char,
val characterSheetId: String,
val instanceId: Int?,
val skillLabel: String,
val rollValue: Int,
val resultLabel: String? = null,
val rollDifficulty: String? = null,
val rollSuccessLimit: Int? = null,
val critical: Critical? = null,
) : MessagePayload {
@Serializable
data class RollId(
val rollId: String,
val timestamp: Long,
) {
companion object {
fun create(
rollId: String = UUID.randomUUID().toString(),
timestamp: Long = System.currentTimeMillis(),
) = RollId(
rollId = rollId,
timestamp = timestamp,
)
}
}
enum class Critical {
CRITICAL_SUCCESS,
SPECIAL_SUCCESS,
SUCCESS,
FAILURE,
CRITICAL_FAILURE
}
}

View file

@ -1,10 +0,0 @@
package com.pixelized.shared.lwa.protocol.websocket.payload
import kotlinx.serialization.Serializable
@Serializable
data class UpdateSkillUsageMessage(
val characterSheetId: String,
val skillId: String,
val used: Boolean,
) : MessagePayload