From ae8f8ad65882c7caf035e03c1d0964968d97e7c4 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 1 Feb 2023 12:22:26 +0700 Subject: [PATCH] Flashlight definition --- .../ru/dbotthepony/kstarbound/Starbound.kt | 54 +++++++------------ .../defs/item/ArmorItemPrototype.kt | 30 ++++++++++- .../defs/item/FlashlightDefinition.kt | 35 ++++++++++++ .../defs/item/FlashlightPrototype.kt | 49 +++++++++++++++++ .../defs/item/IFlashlightDefinition.kt | 17 ++++++ .../defs/item/IHarvestingToolDefinition.kt | 8 +-- .../defs/item/IItemInHandDefinition.kt | 10 ++++ 7 files changed, 161 insertions(+), 42 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightDefinition.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightPrototype.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IFlashlightDefinition.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IItemInHandDefinition.kt diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 65c92ebc..04dbf8aa 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -19,8 +19,12 @@ import ru.dbotthepony.kstarbound.defs.image.AtlasConfiguration import ru.dbotthepony.kstarbound.defs.image.SpriteReference import ru.dbotthepony.kstarbound.defs.item.ArmorItemPrototype import ru.dbotthepony.kstarbound.defs.item.ArmorPieceType +import ru.dbotthepony.kstarbound.defs.item.BackArmorItemPrototype +import ru.dbotthepony.kstarbound.defs.item.ChestArmorItemPrototype import ru.dbotthepony.kstarbound.defs.item.CurrencyItemPrototype +import ru.dbotthepony.kstarbound.defs.item.FlashlightPrototype import ru.dbotthepony.kstarbound.defs.item.HarvestingToolPrototype +import ru.dbotthepony.kstarbound.defs.item.HeadArmorItemPrototype import ru.dbotthepony.kstarbound.defs.item.IArmorItemDefinition import ru.dbotthepony.kstarbound.defs.item.IFossilItemDefinition import ru.dbotthepony.kstarbound.defs.item.IItemDefinition @@ -28,6 +32,7 @@ import ru.dbotthepony.kstarbound.defs.item.ItemDefinition 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.LegsArmorItemPrototype import ru.dbotthepony.kstarbound.defs.item.LeveledStatusEffect import ru.dbotthepony.kstarbound.defs.item.LiquidItemPrototype import ru.dbotthepony.kstarbound.defs.item.MaterialItemPrototype @@ -508,47 +513,28 @@ object Starbound { } private fun loadItemDefinitions(callback: (String) -> Unit) { - val files = listOf(".item", ".currency", ".head", ".chest", ".legs", ".back", ".activeitem", ".matitem", ".liqitem", ".harvestingtool") + val files = linkedMapOf( + ".item" to ItemPrototype::class.java, + ".currency" to CurrencyItemPrototype::class.java, + ".liqitem" to LiquidItemPrototype::class.java, + ".matitem" to MaterialItemPrototype::class.java, + ".flashlight" to FlashlightPrototype::class.java, + ".harvestingtool" to HarvestingToolPrototype::class.java, + ".head" to HeadArmorItemPrototype::class.java, + ".chest" to ChestArmorItemPrototype::class.java, + ".legs" to LegsArmorItemPrototype::class.java, + ".back" to BackArmorItemPrototype::class.java, + ) for (fs in fileSystems) { - for (listedFile in fs.explore().filter { it.isFile }.filter { f -> files.any { f.name.endsWith(it) } }) { + for (listedFile in fs.explore().filter { it.isFile }.filter { f -> files.keys.any { f.name.endsWith(it) } }) { try { callback("Loading $listedFile") assetFolder = listedFile.computeDirectory() - if (listedFile.name.endsWith(".item")) { - val def = GSON.fromJson(listedFile.reader(), ItemPrototype::class.java) - check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } - } else if (listedFile.name.endsWith(".harvestingtool")) { - val def = GSON.fromJson(listedFile.reader(), HarvestingToolPrototype::class.java) - check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } - } 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!" } - } else if (listedFile.name.endsWith(".head")) { - val def = GSON.fromJson(listedFile.reader(), ArmorItemPrototype::class.java) - def.armorType = ArmorPieceType.HEAD - check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } - } else if (listedFile.name.endsWith(".chest")) { - val def = GSON.fromJson(listedFile.reader(), ArmorItemPrototype::class.java) - def.armorType = ArmorPieceType.CHEST - check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } - } else if (listedFile.name.endsWith(".legs")) { - val def = GSON.fromJson(listedFile.reader(), ArmorItemPrototype::class.java) - def.armorType = ArmorPieceType.LEGS - check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } - } else if (listedFile.name.endsWith(".back")) { - val def = GSON.fromJson(listedFile.reader(), ArmorItemPrototype::class.java) - def.armorType = ArmorPieceType.BACK - check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } - } + val def: ItemPrototype = GSON.fromJson(listedFile.reader(), files.entries.first { listedFile.name.endsWith(it.key) }.value) + check(items.put(def.itemName, def.assemble()) == null) { "Already has item with name ${def.itemName} loaded!" } } catch (err: Throwable) { LOGGER.error("Loading item definition file $listedFile", err) } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ArmorItemPrototype.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ArmorItemPrototype.kt index 0c5215a5..65d7a896 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ArmorItemPrototype.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ArmorItemPrototype.kt @@ -12,7 +12,7 @@ import ru.dbotthepony.kstarbound.io.json.neverNull import ru.dbotthepony.kstarbound.util.NotNullVar @JsonBuilder -class ArmorItemPrototype : ItemPrototype(), IArmorItemDefinition { +open class ArmorItemPrototype : ItemPrototype(), IArmorItemDefinition { override var colorOptions: ImmutableList> = ImmutableList.of() override var maleFrames: IArmorItemDefinition.ArmorFrames by NotNullVar() override var femaleFrames: IArmorItemDefinition.ArmorFrames by NotNullVar() @@ -62,3 +62,31 @@ class ArmorItemPrototype : ItemPrototype(), IArmorItemDefinition { ) } } + +@JsonBuilder +class HeadArmorItemPrototype : ArmorItemPrototype() { + init { + armorType = ArmorPieceType.HEAD + } +} + +@JsonBuilder +class ChestArmorItemPrototype : ArmorItemPrototype() { + init { + armorType = ArmorPieceType.CHEST + } +} + +@JsonBuilder +class LegsArmorItemPrototype : ArmorItemPrototype() { + init { + armorType = ArmorPieceType.LEGS + } +} + +@JsonBuilder +class BackArmorItemPrototype : ArmorItemPrototype() { + init { + armorType = ArmorPieceType.BACK + } +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightDefinition.kt new file mode 100644 index 00000000..11a91a01 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightDefinition.kt @@ -0,0 +1,35 @@ +package ru.dbotthepony.kstarbound.defs.item + +import com.google.common.collect.ImmutableList +import ru.dbotthepony.kstarbound.defs.IThingWithDescription +import ru.dbotthepony.kstarbound.defs.ThingDescription +import ru.dbotthepony.kvector.vector.Color +import ru.dbotthepony.kvector.vector.ndouble.Vector2d + +data class FlashlightDefinition( + override val itemName: String, + override val price: Long, + override val rarity: ItemRarity, + override val category: String?, + override val inventoryIcon: ImmutableList?, + override val itemTags: ImmutableList, + override val learnBlueprintsOnPickup: ImmutableList, + override val maxStack: Long, + override val eventCategory: String?, + override val consumeOnPickup: Boolean, + override val pickupQuestTemplates: ImmutableList, + override val tooltipKind: ItemTooltipKind, + override val twoHanded: Boolean, + override val radioMessagesOnPickup: ImmutableList, + override val fuelAmount: Long?, + + override val lightPosition: Vector2d, + override val lightColor: Color, + override val beamLevel: Int, + override val beamAmbience: Double, + override val handPosition: Vector2d, + + val descriptionData: ThingDescription, + + val json: Map +) : IFlashlightDefinition, IThingWithDescription by descriptionData diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightPrototype.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightPrototype.kt new file mode 100644 index 00000000..af001dbf --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/FlashlightPrototype.kt @@ -0,0 +1,49 @@ +package ru.dbotthepony.kstarbound.defs.item + +import ru.dbotthepony.kstarbound.defs.util.enrollMap +import ru.dbotthepony.kstarbound.io.json.builder.JsonBuilder +import ru.dbotthepony.kstarbound.util.NotNullVar +import ru.dbotthepony.kvector.vector.Color +import ru.dbotthepony.kvector.vector.ndouble.Vector2d + +@JsonBuilder +class FlashlightPrototype : ItemPrototype(), IFlashlightDefinition { + override var lightPosition: Vector2d by NotNullVar() + override var lightColor: Color by NotNullVar() + override var beamLevel: Int by NotNullVar() + override var beamAmbience: Double by NotNullVar() + override var handPosition: Vector2d by NotNullVar() + + init { + maxStack = 1L + } + + override fun assemble(): IItemDefinition { + return FlashlightDefinition( + descriptionData = descriptionData, + itemName = itemName, + price = price, + rarity = rarity, + category = category, + inventoryIcon = inventoryIcon, + itemTags = itemTags, + learnBlueprintsOnPickup = learnBlueprintsOnPickup, + maxStack = maxStack, + eventCategory = eventCategory, + consumeOnPickup = consumeOnPickup, + pickupQuestTemplates = pickupQuestTemplates, + tooltipKind = tooltipKind, + twoHanded = twoHanded, + radioMessagesOnPickup = radioMessagesOnPickup, + fuelAmount = fuelAmount, + + json = enrollMap(json), + + lightPosition = lightPosition, + lightColor = lightColor, + beamLevel = beamLevel, + beamAmbience = beamAmbience, + handPosition = handPosition, + ) + } +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IFlashlightDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IFlashlightDefinition.kt new file mode 100644 index 00000000..5f16fa41 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IFlashlightDefinition.kt @@ -0,0 +1,17 @@ +package ru.dbotthepony.kstarbound.defs.item + +import ru.dbotthepony.kvector.vector.Color +import ru.dbotthepony.kvector.vector.ndouble.Vector2d + +interface IFlashlightDefinition : IItemDefinition, IItemInHandDefinition { + /** + * Смещение в пикселях + */ + val lightPosition: Vector2d + + val lightColor: Color + + val beamLevel: Int + + val beamAmbience: Double +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt index 01c199e1..2d37a573 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt @@ -1,9 +1,8 @@ package ru.dbotthepony.kstarbound.defs.item import ru.dbotthepony.kstarbound.defs.animation.IAnimated -import ru.dbotthepony.kvector.vector.ndouble.Vector2d -interface IHarvestingToolDefinition : IItemDefinition, IAnimated { +interface IHarvestingToolDefinition : IItemDefinition, IAnimated, IItemInHandDefinition { /** * Радиус в тайлах, на какое расстояние действует данный инструмент для сбора */ @@ -24,11 +23,6 @@ interface IHarvestingToolDefinition : IItemDefinition, IAnimated { */ val strikeSounds: List - /** - * Позиция инструмента в руке (смещение в пикселях) - */ - val handPosition: Vector2d - /** * Время атаки */ diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IItemInHandDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IItemInHandDefinition.kt new file mode 100644 index 00000000..a6131bee --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IItemInHandDefinition.kt @@ -0,0 +1,10 @@ +package ru.dbotthepony.kstarbound.defs.item + +import ru.dbotthepony.kvector.vector.ndouble.Vector2d + +interface IItemInHandDefinition : IItemDefinition { + /** + * Позиция инструмента в руке (смещение в пикселях) + */ + val handPosition: Vector2d +}