Server : Add item service.
This commit is contained in:
parent
b09a6d5184
commit
0aaa56a4aa
24 changed files with 607 additions and 28 deletions
|
|
@ -7,6 +7,8 @@ import com.pixelized.shared.lwa.model.campaign.factory.CampaignJsonV1Factory
|
|||
import com.pixelized.shared.lwa.model.campaign.factory.CampaignJsonV2Factory
|
||||
import com.pixelized.shared.lwa.model.characterSheet.factory.CharacterSheetJsonFactory
|
||||
import com.pixelized.shared.lwa.model.characterSheet.factory.CharacterSheetJsonV1Factory
|
||||
import com.pixelized.shared.lwa.model.item.factory.ItemJsonFactory
|
||||
import com.pixelized.shared.lwa.model.item.factory.ItemJsonFactoryV1
|
||||
import com.pixelized.shared.lwa.model.tag.TagJsonFactory
|
||||
import com.pixelized.shared.lwa.parser.dice.DiceParser
|
||||
import com.pixelized.shared.lwa.parser.expression.ExpressionParser
|
||||
|
|
@ -48,6 +50,8 @@ val factoryDependencies
|
|||
factoryOf(::AlteredCharacterSheetFactory)
|
||||
factoryOf(::AlterationJsonFactory)
|
||||
factoryOf(::TagJsonFactory)
|
||||
factoryOf(::ItemJsonFactory)
|
||||
factoryOf(::ItemJsonFactoryV1)
|
||||
}
|
||||
|
||||
val parserDependencies
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.pixelized.shared.lwa.model.item
|
||||
|
||||
data class Item(
|
||||
val id: String,
|
||||
val metadata: MetaData,
|
||||
val options: Options,
|
||||
val tags: List<String>,
|
||||
val alterations: List<String>,
|
||||
) {
|
||||
data class MetaData(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val thumbnail: String?,
|
||||
val image: String?,
|
||||
)
|
||||
|
||||
data class Options(
|
||||
val stackable: Boolean,
|
||||
val equipable: Boolean,
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.pixelized.shared.lwa.model.item
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
sealed interface ItemJson {
|
||||
val id: String
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.pixelized.shared.lwa.model.item
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ItemJsonV1(
|
||||
override val id: String,
|
||||
val metadata: ItemMetadataJsonV1,
|
||||
val options: ItemOptionJsonV1,
|
||||
val tags: List<String>,
|
||||
val alterations: List<String>,
|
||||
) : ItemJson {
|
||||
|
||||
@Serializable
|
||||
data class ItemMetadataJsonV1(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val thumbnail: String?,
|
||||
val image: String?,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ItemOptionJsonV1(
|
||||
val stackable: Boolean,
|
||||
val equipable: Boolean,
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.pixelized.shared.lwa.model.item.factory
|
||||
|
||||
import com.pixelized.shared.lwa.model.item.Item
|
||||
import com.pixelized.shared.lwa.model.item.ItemJson
|
||||
import com.pixelized.shared.lwa.model.item.ItemJsonV1
|
||||
|
||||
class ItemJsonFactory(
|
||||
private val v1: ItemJsonFactoryV1,
|
||||
) {
|
||||
fun convertFromJson(json: ItemJson): Item {
|
||||
return when (json) {
|
||||
is ItemJsonV1 -> v1.convertFromJson(json = json)
|
||||
}
|
||||
}
|
||||
|
||||
fun convertToJson(item: Item): ItemJson {
|
||||
return v1.convertToJson(item = item)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.pixelized.shared.lwa.model.item.factory
|
||||
|
||||
import com.pixelized.shared.lwa.model.item.Item
|
||||
import com.pixelized.shared.lwa.model.item.ItemJsonV1
|
||||
|
||||
class ItemJsonFactoryV1 {
|
||||
|
||||
fun convertFromJson(json: ItemJsonV1): Item {
|
||||
return Item(
|
||||
id = json.id,
|
||||
metadata = Item.MetaData(
|
||||
name = json.metadata.name,
|
||||
description = json.metadata.description,
|
||||
image = json.metadata.image,
|
||||
thumbnail = json.metadata.thumbnail,
|
||||
),
|
||||
options = Item.Options(
|
||||
stackable = json.options.stackable,
|
||||
equipable = json.options.equipable,
|
||||
),
|
||||
tags = json.tags,
|
||||
alterations = json.alterations,
|
||||
)
|
||||
}
|
||||
|
||||
fun convertToJson(item: Item): ItemJsonV1 {
|
||||
return ItemJsonV1(
|
||||
id = item.id,
|
||||
metadata = ItemJsonV1.ItemMetadataJsonV1(
|
||||
name = item.metadata.name,
|
||||
description = item.metadata.description,
|
||||
image = item.metadata.image,
|
||||
thumbnail = item.metadata.thumbnail,
|
||||
),
|
||||
options = ItemJsonV1.ItemOptionJsonV1(
|
||||
stackable = item.options.stackable,
|
||||
equipable = item.options.equipable,
|
||||
),
|
||||
tags = item.tags,
|
||||
alterations = item.alterations,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,8 @@ data class APIResponse<T>(
|
|||
enum class ErrorCode {
|
||||
AlterationId,
|
||||
AlterationName,
|
||||
ItemId,
|
||||
ItemName,
|
||||
CharacterSheetId,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,27 +5,48 @@ import kotlinx.serialization.Serializable
|
|||
@Serializable
|
||||
sealed interface ApiSynchronisation : SocketMessage {
|
||||
|
||||
@Serializable
|
||||
sealed interface CharacterSheetApiSynchronisation : ApiSynchronisation, CharacterSheetIdMessage
|
||||
|
||||
@Serializable
|
||||
data class CharacterSheetDelete(
|
||||
override val timestamp: Long,
|
||||
override val characterSheetId: String,
|
||||
) : ApiSynchronisation, CharacterSheetIdMessage
|
||||
) : CharacterSheetApiSynchronisation
|
||||
|
||||
@Serializable
|
||||
data class CharacterSheetUpdate(
|
||||
override val timestamp: Long,
|
||||
override val characterSheetId: String,
|
||||
) : ApiSynchronisation, CharacterSheetIdMessage
|
||||
) : CharacterSheetApiSynchronisation
|
||||
|
||||
@Serializable
|
||||
sealed interface AlterationApiSynchronisation : ApiSynchronisation
|
||||
|
||||
@Serializable
|
||||
data class AlterationUpdate(
|
||||
override val timestamp: Long,
|
||||
val alterationId: String,
|
||||
) : ApiSynchronisation
|
||||
) : AlterationApiSynchronisation
|
||||
|
||||
@Serializable
|
||||
data class AlterationDelete(
|
||||
override val timestamp: Long,
|
||||
val alterationId: String,
|
||||
) : ApiSynchronisation
|
||||
) : AlterationApiSynchronisation
|
||||
|
||||
@Serializable
|
||||
sealed interface ItemApiSynchronisation : ApiSynchronisation
|
||||
|
||||
@Serializable
|
||||
data class ItemUpdate(
|
||||
override val timestamp: Long,
|
||||
val itemId: String,
|
||||
) : ItemApiSynchronisation
|
||||
|
||||
@Serializable
|
||||
data class ItemDelete(
|
||||
override val timestamp: Long,
|
||||
val itemId: String,
|
||||
) : ItemApiSynchronisation
|
||||
}
|
||||
|
|
@ -54,6 +54,16 @@ class PathProvider(
|
|||
}
|
||||
}
|
||||
|
||||
fun itemsPath(
|
||||
os: OperatingSystem = this.operatingSystem,
|
||||
app: String = this.appName,
|
||||
): String {
|
||||
return when (os) {
|
||||
OperatingSystem.Windows -> "${storePath(os = os, app = app)}items\\"
|
||||
OperatingSystem.Macintosh -> "${storePath(os = os, app = app)}items/"
|
||||
}
|
||||
}
|
||||
|
||||
fun tagsPath(
|
||||
os: OperatingSystem = this.operatingSystem,
|
||||
app: String = this.appName,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue