Small type fixes and cleanup

This commit is contained in:
Daniel Wolf 2018-04-10 22:51:28 +02:00
parent 1784458931
commit 8f2cc2c5e6
8 changed files with 35 additions and 40 deletions

View File

@ -16,41 +16,41 @@ class AnimationFileModel(val parentModel: MainModel, animationFilePath: Path, pr
val spineJson = SpineJson(animationFilePath)
val slotsProperty = SimpleObjectProperty<ObservableList<String>>()
var slots by slotsProperty
private set
private var slots: ObservableList<String> by slotsProperty
val mouthSlotProperty: SimpleStringProperty = SimpleStringProperty().alsoListen {
mouthNaming = if (mouthSlot != null)
val mouthSlot = this.mouthSlot
val mouthNaming = if (mouthSlot != null)
MouthNaming.guess(spineJson.getSlotAttachmentNames(mouthSlot))
else null
this.mouthNaming = mouthNaming
mouthShapes = if (mouthSlot != null) {
mouthShapes = if (mouthSlot != null && mouthNaming != null) {
val mouthNames = spineJson.getSlotAttachmentNames(mouthSlot)
MouthShape.values().filter { mouthNames.contains(mouthNaming.getName(it)) }
} else listOf()
mouthSlotError = if (mouthSlot != null) null
else "No slot with mouth drawings specified."
mouthSlotError = if (mouthSlot != null)
null
else
"No slot with mouth drawings specified."
}
var mouthSlot by mouthSlotProperty
private var mouthSlot: String? by mouthSlotProperty
val mouthSlotErrorProperty = SimpleStringProperty()
var mouthSlotError by mouthSlotErrorProperty
private set
private var mouthSlotError: String? by mouthSlotErrorProperty
val mouthNamingProperty = SimpleObjectProperty<MouthNaming>()
var mouthNaming by mouthNamingProperty
private set
private var mouthNaming: MouthNaming? by mouthNamingProperty
val mouthShapesProperty = SimpleObjectProperty<List<MouthShape>>().alsoListen {
mouthShapesError = getMouthShapesErrorString()
}
var mouthShapes by mouthShapesProperty
var mouthShapes: List<MouthShape> by mouthShapesProperty
private set
val mouthShapesErrorProperty = SimpleStringProperty()
var mouthShapesError by mouthShapesErrorProperty
private set
private var mouthShapesError: String? by mouthShapesErrorProperty
val audioFileModelsProperty = SimpleListProperty<AudioFileModel>(
spineJson.audioEvents
@ -63,7 +63,7 @@ class AnimationFileModel(val parentModel: MainModel, animationFilePath: Path, pr
}
.observable()
)
val audioFileModels by audioFileModelsProperty
val audioFileModels: ObservableList<AudioFileModel> by audioFileModelsProperty
val busyProperty = SimpleBooleanProperty().apply {
bind(object : BooleanBinding() {
@ -90,10 +90,9 @@ class AnimationFileModel(val parentModel: MainModel, animationFilePath: Path, pr
}
})
}
val valid by validProperty
private fun saveAnimation(animationName: String, audioEventName: String, mouthCues: List<MouthCue>) {
spineJson.createOrUpdateAnimation(mouthCues, audioEventName, animationName, mouthSlot, mouthNaming)
spineJson.createOrUpdateAnimation(mouthCues, audioEventName, animationName, mouthSlot!!, mouthNaming!!)
spineJson.save()
}

View File

@ -11,6 +11,7 @@ import javafx.scene.control.Alert
import javafx.scene.control.ButtonType
import tornadofx.getValue
import tornadofx.setValue
import java.nio.file.Path
import java.util.concurrent.ExecutorService
import java.util.concurrent.Future
@ -20,15 +21,14 @@ class AudioFileModel(
private val executor: ExecutorService,
private val reportResult: (List<MouthCue>) -> Unit
) {
val spineJson = parentModel.spineJson
private val spineJson = parentModel.spineJson
val audioFilePath = spineJson.audioDirectoryPath.resolve(audioEvent.relativeAudioFilePath)
private val audioFilePath: Path = spineJson.audioDirectoryPath.resolve(audioEvent.relativeAudioFilePath)
val eventNameProperty = SimpleStringProperty(audioEvent.name)
val eventName by eventNameProperty
val eventName: String by eventNameProperty
val displayFilePathProperty = SimpleStringProperty(audioEvent.relativeAudioFilePath)
val displayFilePath by displayFilePathProperty
val animationNameProperty = SimpleStringProperty().apply {
val mainModel = parentModel.parentModel
@ -45,13 +45,13 @@ class AudioFileModel(
}
})
}
val animationName by animationNameProperty
val animationName: String by animationNameProperty
val dialogProperty = SimpleStringProperty(audioEvent.dialog)
val dialog: String? by dialogProperty
private val dialog: String? by dialogProperty
val animationProgressProperty = SimpleObjectProperty<Double?>(null)
var animationProgress by animationProgressProperty
var animationProgress: Double? by animationProgressProperty
private set
private val animatedProperty = SimpleBooleanProperty().apply {
@ -92,7 +92,6 @@ class AudioFileModel(
}
})
}
val audioFileState by audioFileStateProperty
val busyProperty = SimpleBooleanProperty().apply {
bind(object : BooleanBinding() {
@ -120,7 +119,6 @@ class AudioFileModel(
}
})
}
val actionLabel by actionLabelProperty
fun performAction() {
if (future == null) {

View File

@ -32,21 +32,19 @@ class MainModel(private val executor: ExecutorService) {
animationFileModel = AnimationFileModel(this, path, executor)
}
}
var filePathString by filePathStringProperty
val filePathErrorProperty = SimpleStringProperty()
var filePathError by filePathErrorProperty
private set
private var filePathError: String? by filePathErrorProperty
val animationFileModelProperty = SimpleObjectProperty<AnimationFileModel?>()
var animationFileModel by animationFileModelProperty
private set
val animationPrefixProperty = SimpleStringProperty("say_")
var animationPrefix by animationPrefixProperty
var animationPrefix: String by animationPrefixProperty
val animationSuffixProperty = SimpleStringProperty("")
var animationSuffix by animationSuffixProperty
var animationSuffix: String by animationSuffixProperty
private fun getDefaultPathString() = FX.application.parameters.raw.firstOrNull()
}

View File

@ -2,7 +2,7 @@ package com.rhubarb_lip_sync.rhubarb_for_spine
import java.util.*
class MouthNaming(val prefix: String, val suffix: String, val mouthShapeCasing: MouthShapeCasing) {
class MouthNaming(private val prefix: String, private val suffix: String, private val mouthShapeCasing: MouthShapeCasing) {
companion object {
fun guess(mouthNames: List<String>): MouthNaming {

View File

@ -10,7 +10,7 @@ enum class MouthShape {
get() = !this.isBasic
companion object {
val basicShapeCount = 6
const val basicShapeCount = 6
val basicShapes = MouthShape.values().take(basicShapeCount)

View File

@ -24,7 +24,7 @@ class RhubarbTask(
throw InterruptedException()
}
if (!Files.exists(audioFilePath)) {
throw EndUserException("File '$audioFilePath' does not exist.");
throw EndUserException("File '$audioFilePath' does not exist.")
}
val dialogFile = if (dialog != null) TemporaryTextFile(dialog) else null
@ -60,7 +60,7 @@ class RhubarbTask(
} catch (e: EOFException) {
throw EndUserException("Rhubarb terminated unexpectedly.")
} finally {
process.waitFor();
process.waitFor()
}
}}

View File

@ -6,9 +6,9 @@ import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
class SpineJson(val filePath: Path) {
val fileDirectoryPath: Path = filePath.parent
val json: JsonObject
class SpineJson(private val filePath: Path) {
private val fileDirectoryPath: Path = filePath.parent
private val json: JsonObject
private val skeleton: JsonObject
private val defaultSkin: JsonObject
@ -32,7 +32,7 @@ class SpineJson(val filePath: Path) {
audioDirectoryPath
}
val imagesDirectoryPath: Path get() {
private val imagesDirectoryPath: Path get() {
val relativeImagesDirectory = skeleton.string("images")
?: throw EndUserException("JSON file is incomplete: Images path is missing."
+ "Make sure to check 'Nonessential data' when exporting.")

View File

@ -28,7 +28,7 @@ fun <TValue, TProperty : Property<TValue>> TProperty.alsoListen(listener: (TValu
fun getExceptionMessage(action: () -> Unit): String? {
try {
action();
action()
} catch (e: Exception) {
return e.message
}