AtlasDefinition.spriteList
This commit is contained in:
parent
c7952ba53d
commit
9357835f4e
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.kstarbound.defs.animation
|
package ru.dbotthepony.kstarbound.defs.animation
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList
|
||||||
import com.google.common.collect.ImmutableMap
|
import com.google.common.collect.ImmutableMap
|
||||||
import com.google.gson.JsonArray
|
import com.google.gson.JsonArray
|
||||||
import com.google.gson.JsonNull
|
import com.google.gson.JsonNull
|
||||||
@ -31,6 +32,11 @@ class AtlasDefinition private constructor(
|
|||||||
* Спрайты данного атласа, включая спрайты под псевдонимами
|
* Спрайты данного атласа, включая спрайты под псевдонимами
|
||||||
*/
|
*/
|
||||||
val sprites: ImmutableMap<String, Sprite>,
|
val sprites: ImmutableMap<String, Sprite>,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Спрайты данного атласа, в последовательности, в которой они указаны в JSON файле
|
||||||
|
*/
|
||||||
|
val spriteList: ImmutableList<Sprite>,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Первый спрайт, по своему имени (естественная сортировка)
|
* Первый спрайт, по своему имени (естественная сортировка)
|
||||||
@ -143,7 +149,12 @@ class AtlasDefinition private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val EMPTY = AtlasDefinition("null", ImmutableMap.of("root", Sprite("root", Vector4i(0, 0, 0, 0)), "default", Sprite("root", Vector4i(0, 0, 0, 0))))
|
val EMPTY: AtlasDefinition
|
||||||
|
|
||||||
|
init {
|
||||||
|
val sprite = Sprite("root", Vector4i(0, 0, 0, 0))
|
||||||
|
EMPTY = AtlasDefinition("null", ImmutableMap.of("root", sprite, "default", sprite, "0", sprite), ImmutableList.of(sprite))
|
||||||
|
}
|
||||||
|
|
||||||
private val cache = ConcurrentHashMap<String, AtlasDefinition>()
|
private val cache = ConcurrentHashMap<String, AtlasDefinition>()
|
||||||
|
|
||||||
@ -172,7 +183,7 @@ class AtlasDefinition private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val frameGrid = read["frameGrid"]
|
val frameGrid = read["frameGrid"]
|
||||||
val sprites = HashMap<String, Sprite>()
|
val sprites = LinkedHashMap<String, Sprite>()
|
||||||
|
|
||||||
if (frameGrid is JsonObject) {
|
if (frameGrid is JsonObject) {
|
||||||
val size = Starbound.gson.fromJson(frameGrid["size"] ?: throw JsonSyntaxException("Missing frameGrid.size"), Vector2i::class.java)
|
val size = Starbound.gson.fromJson(frameGrid["size"] ?: throw JsonSyntaxException("Missing frameGrid.size"), Vector2i::class.java)
|
||||||
@ -219,6 +230,7 @@ class AtlasDefinition private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val spriteList = ImmutableList.copyOf(sprites.values)
|
||||||
val aliases = read["aliases"]
|
val aliases = read["aliases"]
|
||||||
|
|
||||||
if (aliases != null) {
|
if (aliases != null) {
|
||||||
@ -229,7 +241,7 @@ class AtlasDefinition private constructor(
|
|||||||
sprites[k] = sprites[v.asString] ?: throw JsonSyntaxException("$k want to refer to sprite $v, but it does not exist")
|
sprites[k] = sprites[v.asString] ?: throw JsonSyntaxException("$k want to refer to sprite $v, but it does not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
return AtlasDefinition(name, ImmutableMap.copyOf(sprites))
|
return AtlasDefinition(name, ImmutableMap.copyOf(sprites), spriteList)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recursiveGet(name: String, folder: String): AtlasDefinition? {
|
private fun recursiveGet(name: String, folder: String): AtlasDefinition? {
|
||||||
|
Loading…
Reference in New Issue
Block a user