From 49e90a6dca08227c39e496c06a83e48b77be5fb4 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 23 Jan 2023 14:18:09 +0700 Subject: [PATCH] harvestingtool --- .../ru/dbotthepony/kstarbound/Starbound.kt | 6 ++- .../kstarbound/defs/animation/IAnimated.kt | 13 +++++ .../defs/item/HarvestingToolDefinition.kt | 34 +++++++++++++ .../defs/item/HarvestingToolPrototype.kt | 50 +++++++++++++++++++ .../defs/item/IHarvestingToolDefinition.kt | 25 ++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/IAnimated.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolDefinition.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolPrototype.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 8e90df55..65c92ebc 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -20,6 +20,7 @@ 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.CurrencyItemPrototype +import ru.dbotthepony.kstarbound.defs.item.HarvestingToolPrototype import ru.dbotthepony.kstarbound.defs.item.IArmorItemDefinition import ru.dbotthepony.kstarbound.defs.item.IFossilItemDefinition import ru.dbotthepony.kstarbound.defs.item.IItemDefinition @@ -507,7 +508,7 @@ object Starbound { } private fun loadItemDefinitions(callback: (String) -> Unit) { - val files = listOf(".item", ".currency", ".head", ".chest", ".legs", ".back", ".activeitem", ".matitem", ".liqitem") + val files = listOf(".item", ".currency", ".head", ".chest", ".legs", ".back", ".activeitem", ".matitem", ".liqitem", ".harvestingtool") for (fs in fileSystems) { for (listedFile in fs.explore().filter { it.isFile }.filter { f -> files.any { f.name.endsWith(it) } }) { @@ -519,6 +520,9 @@ object Starbound { 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!" } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/IAnimated.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/IAnimated.kt new file mode 100644 index 00000000..670b887f --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/IAnimated.kt @@ -0,0 +1,13 @@ +package ru.dbotthepony.kstarbound.defs.animation + +interface IAnimated { + /** + * Сколько кадров в анимации + */ + val frames: Int + + /** + * Время в секундах между кадрами + */ + val animationCycle: Double +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolDefinition.kt new file mode 100644 index 00000000..df9a324e --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolDefinition.kt @@ -0,0 +1,34 @@ +package ru.dbotthepony.kstarbound.defs.item + +import com.google.common.collect.ImmutableList +import ru.dbotthepony.kstarbound.defs.IThingWithDescription +import ru.dbotthepony.kstarbound.defs.ThingDescription + +data class HarvestingToolDefinition( + override val itemName: String, + override val price: Long = 4L, + 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 frames: Int, + override val animationCycle: Double, + override val blockRadius: Int, + override val altBlockRadius: Int, + override val idleSound: ImmutableList, + override val strikeSounds: ImmutableList, + + val descriptionData: ThingDescription, + + val json: Map +) : IHarvestingToolDefinition, IThingWithDescription by descriptionData diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolPrototype.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolPrototype.kt new file mode 100644 index 00000000..21739147 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/HarvestingToolPrototype.kt @@ -0,0 +1,50 @@ +package ru.dbotthepony.kstarbound.defs.item + +import com.google.common.collect.ImmutableList +import ru.dbotthepony.kstarbound.defs.util.enrollMap +import ru.dbotthepony.kstarbound.io.json.builder.JsonBuilder +import ru.dbotthepony.kstarbound.util.NotNullVar + +@JsonBuilder +class HarvestingToolPrototype : ItemPrototype(), IHarvestingToolDefinition { + override var frames: Int by NotNullVar() + override var animationCycle: Double by NotNullVar() + override var blockRadius: Int by NotNullVar() + override var altBlockRadius: Int = 0 + override var idleSound: ImmutableList = ImmutableList.of() + override var strikeSounds: ImmutableList = ImmutableList.of() + + init { + maxStack = 1L + } + + override fun assemble(): IItemDefinition { + return HarvestingToolDefinition( + 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), + + frames = frames, + animationCycle = animationCycle, + blockRadius = blockRadius, + altBlockRadius = altBlockRadius, + idleSound = idleSound, + strikeSounds = strikeSounds, + ) + } +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt new file mode 100644 index 00000000..cc1ad316 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/IHarvestingToolDefinition.kt @@ -0,0 +1,25 @@ +package ru.dbotthepony.kstarbound.defs.item + +import ru.dbotthepony.kstarbound.defs.animation.IAnimated + +interface IHarvestingToolDefinition : IItemDefinition, IAnimated { + /** + * Радиус в тайлах, на какое расстояние действует данный инструмент для сбора + */ + val blockRadius: Int + + /** + * Радиус в тайлах, на какое расстояние действует данный инструмент для сбора + */ + val altBlockRadius: Int + + /** + * Звуки в бездействии + */ + val idleSound: List + + /** + * Звуки при работе + */ + val strikeSounds: List +}