diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 0b2b38be..784e8077 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -27,6 +27,7 @@ import ru.dbotthepony.kstarbound.defs.item.ItemPrototype import ru.dbotthepony.kstarbound.defs.item.ItemRarity import ru.dbotthepony.kstarbound.defs.item.ItemTooltipKind import ru.dbotthepony.kstarbound.defs.item.LeveledStatusEffect +import ru.dbotthepony.kstarbound.defs.item.LiquidItemPrototype import ru.dbotthepony.kstarbound.defs.item.MaterialItemPrototype import ru.dbotthepony.kstarbound.defs.liquid.LiquidDefinition import ru.dbotthepony.kstarbound.defs.projectile.* @@ -169,11 +170,13 @@ object Starbound { .also(AtlasConfiguration::registerGson) .registerTypeAdapter(LeveledStatusEffect.ADAPTER) + .registerTypeAdapter(MaterialReference.Companion) .registerTypeAdapter(ItemPrototype.ADAPTER) .registerTypeAdapter(CurrencyItemPrototype.ADAPTER) .registerTypeAdapter(ArmorItemPrototype.ADAPTER) .registerTypeAdapter(MaterialItemPrototype.ADAPTER) + .registerTypeAdapter(LiquidItemPrototype.ADAPTER) .registerTypeAdapter(IItemDefinition.InventoryIcon.ADAPTER) .registerTypeAdapter(IFossilItemDefinition.FossilSetDescription.ADAPTER) @@ -516,7 +519,7 @@ object Starbound { } private fun loadItemDefinitions(callback: (String) -> Unit) { - val files = listOf(".item", ".currency", ".head", ".chest", ".legs", ".back", ".activeitem", ".matitem") + val files = listOf(".item", ".currency", ".head", ".chest", ".legs", ".back", ".activeitem", ".matitem", ".liqitem") for (fs in fileSystems) { for (listedFile in fs.explore().filter { it.isFile }.filter { f -> files.any { f.name.endsWith(it) } }) { @@ -531,6 +534,9 @@ object Starbound { } else if (listedFile.name.endsWith(".matitem")) { val def = GSON.fromJson(listedFile.reader(), MaterialItemPrototype::class.java) check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } + } else if (listedFile.name.endsWith(".liqitem")) { + val def = GSON.fromJson(listedFile.reader(), LiquidItemPrototype::class.java) + check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } } else if (listedFile.name.endsWith(".currency")) { val def = GSON.fromJson(listedFile.reader(), CurrencyItemPrototype::class.java) check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ILiquidItem.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ILiquidItem.kt new file mode 100644 index 00000000..2c37422b --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ILiquidItem.kt @@ -0,0 +1,10 @@ +package ru.dbotthepony.kstarbound.defs.item + +import ru.dbotthepony.kstarbound.defs.MaterialReference + +interface ILiquidItem : IItemDefinition { + /** + * То, какую жидкость из себя представляет данный предмет + */ + val liquid: MaterialReference +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemTooltipKind.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemTooltipKind.kt index a2df17fa..1504abbc 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemTooltipKind.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemTooltipKind.kt @@ -6,6 +6,11 @@ enum class ItemTooltipKind { */ NORMAL, + /** + * Инструмент (кирка, музыкальный инструмент, мотыга, т.п.) + */ + TOOL, + /** * Улучшение для рюкзака */ diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/LiquidItemDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/LiquidItemDefinition.kt new file mode 100644 index 00000000..fc301940 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/LiquidItemDefinition.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.kstarbound.defs.item + +import ru.dbotthepony.kstarbound.defs.MaterialReference + +data class LiquidItemDefinition( + override val shortdescription: String, + override val description: String, + override val itemName: String, + override val price: Long, + override val rarity: ItemRarity, + override val category: String?, + override val inventoryIcon: List?, + override val itemTags: List, + override val learnBlueprintsOnPickup: List, + override val maxStack: Long, + override val eventCategory: String?, + override val consumeOnPickup: Boolean, + override val pickupQuestTemplates: List, + override val scripts: List, + override val tooltipKind: ItemTooltipKind, + override val twoHanded: Boolean, + override val radioMessagesOnPickup: List, + override val fuelAmount: Long?, + + override val liquid: MaterialReference, + + val json: Map +) : ILiquidItem diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/LiquidItemPrototype.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/LiquidItemPrototype.kt new file mode 100644 index 00000000..04b5d111 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/LiquidItemPrototype.kt @@ -0,0 +1,56 @@ +package ru.dbotthepony.kstarbound.defs.item + +import ru.dbotthepony.kstarbound.defs.MaterialReference +import ru.dbotthepony.kstarbound.defs.enrollMap +import ru.dbotthepony.kstarbound.io.json.BuilderAdapter + +class LiquidItemPrototype : ItemPrototype() { + var liquid: MaterialReference? = null + + var liquidId: Int? + get() = liquid?.id + set(value) { + if (liquid == null) + liquid = MaterialReference(id = value, name = null) + } + + var liquidName: String? + get() = liquid?.name + set(value) { liquid = MaterialReference(name = value, id = null) } + + override fun assemble(): IItemDefinition { + return LiquidItemDefinition( + shortdescription = shortdescription, + description = description, + itemName = itemName, + price = price, + rarity = rarity, + category = category, + inventoryIcon = inventoryIcon, + itemTags = itemTags, + learnBlueprintsOnPickup = learnBlueprintsOnPickup, + maxStack = maxStack, + eventCategory = eventCategory, + consumeOnPickup = consumeOnPickup, + pickupQuestTemplates = pickupQuestTemplates, + scripts = scripts, + tooltipKind = tooltipKind, + twoHanded = twoHanded, + radioMessagesOnPickup = radioMessagesOnPickup, + fuelAmount = fuelAmount, + + liquid = checkNotNull(liquid) { "Liquid is null (either 'liquidId' or 'liquidName' should be present, or 'liquid' itself)" }, + + json = enrollMap(json), + ) + } + + companion object { + val ADAPTER = BuilderAdapter.Builder(::LiquidItemPrototype) + .also { addFields(it as BuilderAdapter.Builder) } // безопасность: свойства родительского класса объявлены как final + .auto(LiquidItemPrototype::liquid) + .auto(LiquidItemPrototype::liquidId) + .auto(LiquidItemPrototype::liquidName) + .build() + } +}