From 7a04b7ed41108f6f2c13cbcb0aa98927a4756a74 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Fri, 26 Nov 2021 16:48:49 +0100 Subject: [PATCH 1/2] Update dependencies for Rhubarb for Spine --- extras/EsotericSoftwareSpine/build.gradle.kts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extras/EsotericSoftwareSpine/build.gradle.kts b/extras/EsotericSoftwareSpine/build.gradle.kts index c30eab4..dcfe621 100644 --- a/extras/EsotericSoftwareSpine/build.gradle.kts +++ b/extras/EsotericSoftwareSpine/build.gradle.kts @@ -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 { From a86ec43f23154d9ac6ceb5aaaa1b13d96e4f7120 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Sun, 21 Nov 2021 11:16:07 +0100 Subject: [PATCH 2/2] Add support for skinning in Rhubarb for Spine --- CHANGELOG.md | 2 ++ .../src/main/kotlin/SpineJson.kt | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f041ecd..bb9326b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/extras/EsotericSoftwareSpine/src/main/kotlin/SpineJson.kt b/extras/EsotericSoftwareSpine/src/main/kotlin/SpineJson.kt index 22d4bef..e8f5d41 100644 --- a/extras/EsotericSoftwareSpine/src/main/kotlin/SpineJson.kt +++ b/extras/EsotericSoftwareSpine/src/main/kotlin/SpineJson.kt @@ -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).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 { - val attachments = defaultSkin.obj(slotName) - ?: defaultSkin.obj("attachments")?.obj(slotName) - ?: JsonObject() - return attachments.map { it.key } + @Suppress("UNCHECKED_CAST") + val skins: Collection = when (val skinsObject = json["skins"]) { + is JsonObject -> skinsObject.values as Collection + is JsonArray<*> -> skinsObject as Collection + 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() + } + .distinct() } val animationNames = observableSet( @@ -156,4 +160,4 @@ class SpineJson(private val filePath: Path) { fun save() { Files.write(filePath, listOf(toString()), StandardCharsets.UTF_8) } -} \ No newline at end of file +}