ILiquidItem

This commit is contained in:
DBotThePony 2023-01-04 16:04:09 +07:00
parent f76530e5b6
commit 6fa7b2193e
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 106 additions and 1 deletions

View File

@ -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!" }

View File

@ -0,0 +1,10 @@
package ru.dbotthepony.kstarbound.defs.item
import ru.dbotthepony.kstarbound.defs.MaterialReference
interface ILiquidItem : IItemDefinition {
/**
* То, какую жидкость из себя представляет данный предмет
*/
val liquid: MaterialReference
}

View File

@ -6,6 +6,11 @@ enum class ItemTooltipKind {
*/
NORMAL,
/**
* Инструмент (кирка, музыкальный инструмент, мотыга, т.п.)
*/
TOOL,
/**
* Улучшение для рюкзака
*/

View File

@ -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<IItemDefinition.IInventoryIcon>?,
override val itemTags: List<String>,
override val learnBlueprintsOnPickup: List<String>,
override val maxStack: Long,
override val eventCategory: String?,
override val consumeOnPickup: Boolean,
override val pickupQuestTemplates: List<String>,
override val scripts: List<String>,
override val tooltipKind: ItemTooltipKind,
override val twoHanded: Boolean,
override val radioMessagesOnPickup: List<String>,
override val fuelAmount: Long?,
override val liquid: MaterialReference,
val json: Map<String, Any>
) : ILiquidItem

View File

@ -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<ItemPrototype>) } // безопасность: свойства родительского класса объявлены как final
.auto(LiquidItemPrototype::liquid)
.auto(LiquidItemPrototype::liquidId)
.auto(LiquidItemPrototype::liquidName)
.build()
}
}