DirectAssetReference
This commit is contained in:
parent
39dd94dc6c
commit
2709f3d005
@ -158,6 +158,7 @@ object Starbound {
|
|||||||
.registerTypeAdapterFactory(IItemDefinition.InventoryIcon.Factory(pathStack))
|
.registerTypeAdapterFactory(IItemDefinition.InventoryIcon.Factory(pathStack))
|
||||||
.registerTypeAdapter(SpriteReference.Adapter(pathStack))
|
.registerTypeAdapter(SpriteReference.Adapter(pathStack))
|
||||||
.registerTypeAdapterFactory(IArmorItemDefinition.ArmorFrames.Factory(pathStack))
|
.registerTypeAdapterFactory(IArmorItemDefinition.ArmorFrames.Factory(pathStack))
|
||||||
|
.registerTypeAdapterFactory(DirectAssetReferenceFactory(pathStack))
|
||||||
.registerTypeAdapter(ImageReference.Adapter(pathStack))
|
.registerTypeAdapter(ImageReference.Adapter(pathStack))
|
||||||
|
|
||||||
.registerTypeAdapterFactory(AssetReferenceFactory(pathStack) {
|
.registerTypeAdapterFactory(AssetReferenceFactory(pathStack) {
|
||||||
|
@ -61,7 +61,12 @@ class AssetReferenceFactory(val remapper: AssetPathStack, val reader: (String) -
|
|||||||
val value = remapper(fullPath) {
|
val value = remapper(fullPath) {
|
||||||
adapter.read(JsonReader(reader).also {
|
adapter.read(JsonReader(reader).also {
|
||||||
it.isLenient = true
|
it.isLenient = true
|
||||||
}) ?: return AssetReference(path, fullPath, null)
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == null) {
|
||||||
|
missing.add(fullPath)
|
||||||
|
return AssetReference(path, fullPath, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
cache[fullPath] = value
|
cache[fullPath] = value
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.defs
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.TypeAdapter
|
||||||
|
import com.google.gson.TypeAdapterFactory
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import com.google.gson.stream.JsonReader
|
||||||
|
import com.google.gson.stream.JsonWriter
|
||||||
|
import ru.dbotthepony.kstarbound.util.AssetPathStack
|
||||||
|
|
||||||
|
class DirectAssetReferenceFactory(val remapper: AssetPathStack) : TypeAdapterFactory {
|
||||||
|
override fun <T : Any?> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T>? {
|
||||||
|
if (type.rawType == DirectAssetReference::class.java) {
|
||||||
|
return object : TypeAdapter<DirectAssetReference>() {
|
||||||
|
private val strings = gson.getAdapter(String::class.java)
|
||||||
|
|
||||||
|
override fun write(out: JsonWriter, value: DirectAssetReference?) {
|
||||||
|
if (value == null)
|
||||||
|
out.nullValue()
|
||||||
|
else
|
||||||
|
out.value(value.fullPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(`in`: JsonReader): DirectAssetReference? {
|
||||||
|
val path = strings.read(`in`) ?: return null
|
||||||
|
if (path == "") return null
|
||||||
|
return DirectAssetReference(path, remapper.remap(path))
|
||||||
|
}
|
||||||
|
} as TypeAdapter<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class DirectAssetReference(val path: String, val fullPath: String)
|
@ -4,7 +4,7 @@ interface IScriptable {
|
|||||||
/**
|
/**
|
||||||
* Lua скрипты для выполнения
|
* Lua скрипты для выполнения
|
||||||
*/
|
*/
|
||||||
val scripts: List<String>
|
val scripts: List<DirectAssetReference>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Через какое количество тиков вызывать обновления скриптов
|
* Через какое количество тиков вызывать обновления скриптов
|
||||||
|
@ -12,7 +12,7 @@ data class StatusEffectDefinition(
|
|||||||
val blockingStat: String? = null,
|
val blockingStat: String? = null,
|
||||||
val label: String? = null,
|
val label: String? = null,
|
||||||
val icon: SpriteReference? = null,
|
val icon: SpriteReference? = null,
|
||||||
override val scripts: ImmutableList<String> = ImmutableList.of(),
|
override val scripts: ImmutableList<DirectAssetReference> = ImmutableList.of(),
|
||||||
override val scriptDelta: Int = 1,
|
override val scriptDelta: Int = 1,
|
||||||
val animationConfig: AssetReference<AnimationDefinition>? = null,
|
val animationConfig: AssetReference<AnimationDefinition>? = null,
|
||||||
) : IScriptable
|
) : IScriptable
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.kstarbound.defs.item
|
package ru.dbotthepony.kstarbound.defs.item
|
||||||
|
|
||||||
|
import ru.dbotthepony.kstarbound.defs.DirectAssetReference
|
||||||
import ru.dbotthepony.kstarbound.defs.IThingWithDescription
|
import ru.dbotthepony.kstarbound.defs.IThingWithDescription
|
||||||
import ru.dbotthepony.kstarbound.defs.ThingDescription
|
import ru.dbotthepony.kstarbound.defs.ThingDescription
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ data class ArmorItemDefinition(
|
|||||||
override val eventCategory: String?,
|
override val eventCategory: String?,
|
||||||
override val consumeOnPickup: Boolean,
|
override val consumeOnPickup: Boolean,
|
||||||
override val pickupQuestTemplates: List<String>,
|
override val pickupQuestTemplates: List<String>,
|
||||||
override val scripts: List<String>,
|
override val scripts: List<DirectAssetReference>,
|
||||||
override val scriptDelta: Int,
|
override val scriptDelta: Int,
|
||||||
override val tooltipKind: ItemTooltipKind,
|
override val tooltipKind: ItemTooltipKind,
|
||||||
override val twoHanded: Boolean,
|
override val twoHanded: Boolean,
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.kstarbound.defs.item
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import ru.dbotthepony.kstarbound.Starbound
|
import ru.dbotthepony.kstarbound.Starbound
|
||||||
|
import ru.dbotthepony.kstarbound.defs.DirectAssetReference
|
||||||
import ru.dbotthepony.kstarbound.defs.util.enrollMap
|
import ru.dbotthepony.kstarbound.defs.util.enrollMap
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.BuilderAdapter
|
import ru.dbotthepony.kstarbound.io.json.builder.BuilderAdapter
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.JsonBuilder
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonBuilder
|
||||||
@ -19,7 +20,7 @@ open class ArmorItemPrototype : ItemPrototype(), IArmorItemDefinition {
|
|||||||
override var level: Double = 1.0
|
override var level: Double = 1.0
|
||||||
override var leveledStatusEffects: ImmutableList<LeveledStatusEffect> = ImmutableList.of()
|
override var leveledStatusEffects: ImmutableList<LeveledStatusEffect> = ImmutableList.of()
|
||||||
|
|
||||||
override var scripts: ImmutableList<String> = ImmutableList.of()
|
override var scripts: ImmutableList<DirectAssetReference> = ImmutableList.of()
|
||||||
override var scriptDelta: Int = 1
|
override var scriptDelta: Int = 1
|
||||||
|
|
||||||
@JsonIgnoreProperty
|
@JsonIgnoreProperty
|
||||||
|
@ -2,13 +2,14 @@ package ru.dbotthepony.kstarbound.defs.player
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import com.google.common.collect.ImmutableMap
|
import com.google.common.collect.ImmutableMap
|
||||||
|
import ru.dbotthepony.kstarbound.defs.DirectAssetReference
|
||||||
import ru.dbotthepony.kstarbound.defs.IScriptable
|
import ru.dbotthepony.kstarbound.defs.IScriptable
|
||||||
import ru.dbotthepony.kstarbound.util.SBPattern
|
import ru.dbotthepony.kstarbound.util.SBPattern
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
|
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class CompanionsConfig(
|
data class CompanionsConfig(
|
||||||
override val scripts: ImmutableList<String>,
|
override val scripts: ImmutableList<DirectAssetReference>,
|
||||||
override val scriptDelta: Int,
|
override val scriptDelta: Int,
|
||||||
|
|
||||||
val activePodLimit: Int,
|
val activePodLimit: Int,
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.kstarbound.defs.player
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import com.google.common.collect.ImmutableMap
|
import com.google.common.collect.ImmutableMap
|
||||||
|
import ru.dbotthepony.kstarbound.defs.DirectAssetReference
|
||||||
import ru.dbotthepony.kstarbound.defs.IScriptable
|
import ru.dbotthepony.kstarbound.defs.IScriptable
|
||||||
import ru.dbotthepony.kstarbound.defs.RegistryReference
|
import ru.dbotthepony.kstarbound.defs.RegistryReference
|
||||||
import ru.dbotthepony.kstarbound.defs.item.IItemDefinition
|
import ru.dbotthepony.kstarbound.defs.item.IItemDefinition
|
||||||
@ -9,7 +10,7 @@ import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
|||||||
|
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
data class DeploymentConfig(
|
data class DeploymentConfig(
|
||||||
override val scripts: ImmutableList<String>,
|
override val scripts: ImmutableList<DirectAssetReference>,
|
||||||
override val scriptDelta: Int,
|
override val scriptDelta: Int,
|
||||||
|
|
||||||
val starterMechSet: ImmutableMap<String, RegistryReference<IItemDefinition>>,
|
val starterMechSet: ImmutableMap<String, RegistryReference<IItemDefinition>>,
|
||||||
|
Loading…
Reference in New Issue
Block a user