Merge branch 'feature/#108-spine-skins'

This commit is contained in:
Daniel Wolf 2022-03-12 15:25:11 +01:00
commit b967f00c29
3 changed files with 24 additions and 18 deletions

View File

@ -2,6 +2,8 @@
## Unreleased
* **Added** support for skinning in Rhubarb for Spine ([issue #108](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/108))
## Version 1.11.0
* **Added** support for more WAVE file features ([issue #101](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/101))

View File

@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.File
plugins {
kotlin("jvm") version "1.3.41"
kotlin("jvm") version "1.6.0"
id("org.openjfx.javafxplugin") version "0.0.10"
}
@ -27,12 +27,12 @@ repositories {
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("com.beust:klaxon:5.0.1")
implementation("org.apache.commons:commons-lang3:3.9")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0")
implementation("com.beust:klaxon:5.5")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("no.tornado:tornadofx:2.0.0-SNAPSHOT")
testImplementation("org.junit.jupiter:junit-jupiter:5.5.0")
testCompile("org.assertj:assertj-core:3.11.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("org.assertj:assertj-core:3.21.0")
}
javafx {

View File

@ -10,7 +10,6 @@ class SpineJson(private val filePath: Path) {
private val fileDirectoryPath: Path = filePath.parent
private val json: JsonObject
private val skeleton: JsonObject
private val defaultSkin: JsonObject
init {
if (!Files.exists(filePath)) {
@ -22,12 +21,6 @@ class SpineJson(private val filePath: Path) {
throw EndUserException("Wrong file format. This is not a valid JSON file.")
}
skeleton = json.obj("skeleton") ?: throw EndUserException("JSON file is corrupted.")
val skins = json["skins"] ?: throw EndUserException("JSON file doesn't contain skins.")
defaultSkin = when (skins) {
is JsonObject -> skins.obj("default")
is JsonArray<*> -> (skins as JsonArray<JsonObject>).find { it.string("name") == "default" }
else -> null
} ?: throw EndUserException("JSON file doesn't have a default skin.")
validateProperties()
}
@ -96,10 +89,21 @@ class SpineJson(private val filePath: Path) {
}
fun getSlotAttachmentNames(slotName: String): List<String> {
val attachments = defaultSkin.obj(slotName)
?: defaultSkin.obj("attachments")?.obj(slotName)
?: JsonObject()
return attachments.map { it.key }
@Suppress("UNCHECKED_CAST")
val skins: Collection<JsonObject> = when (val skinsObject = json["skins"]) {
is JsonObject -> skinsObject.values as Collection<JsonObject>
is JsonArray<*> -> skinsObject as Collection<JsonObject>
else -> emptyList()
}
// Get attachment names for all skins
return skins
.flatMap { skin ->
skin.obj(slotName)?.keys?.toList()
?: skin.obj("attachments")?.obj(slotName)?.keys?.toList()
?: emptyList<String>()
}
.distinct()
}
val animationNames = observableSet<String>(
@ -156,4 +160,4 @@ class SpineJson(private val filePath: Path) {
fun save() {
Files.write(filePath, listOf(toString()), StandardCharsets.UTF_8)
}
}
}