Skip to content

Commit

Permalink
added audioFileName support to nodes, #651
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Nov 21, 2021
1 parent 994cfff commit 444c951
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ sealed class DialogueNode(
val text: String
get() = textProperty.value

val audioFileNameProperty: StringProperty = SimpleStringProperty()

val audioFileName: String
get() = audioFileNameProperty.value

override fun toString(): String {
return javaClass.simpleName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import javafx.beans.property.SimpleStringProperty
* An equivalent of serialVersionUID.
* Any changes to the serializable graph data structure need to increment this number by 1.
*/
private const val GRAPH_VERSION = 1
private const val GRAPH_VERSION = 2

/*
* We can't use jackson-module-kotlin yet since no module-info.java is provided.
Expand All @@ -39,7 +39,10 @@ data class SerializableTextNode

@JsonProperty("text")
val text: String
)
) {

var audio: String = ""
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class SerializableChoiceNode
Expand All @@ -55,7 +58,10 @@ data class SerializableChoiceNode

@JsonProperty("conditions")
val conditions: Map<Int, String>
)
) {

var audio: String = ""
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class SerializableEdge
Expand Down Expand Up @@ -126,12 +132,13 @@ object DialogueGraphSerializer {
fun toSerializable(dialogueGraph: DialogueGraph): SerializableGraph {
val nodesS = dialogueGraph.nodes
.filterValues { it.type != CHOICE }
.mapValues { (_, n) -> SerializableTextNode(n.type, n.text) }
.mapValues { (_, n) -> SerializableTextNode(n.type, n.text).also { it.audio = n.audioFileName } }

val choiceNodesS = dialogueGraph.nodes
.filterValues { it.type == CHOICE }
.mapValues { (_, n) ->
SerializableChoiceNode(n.type, n.text, (n as ChoiceNode).options.mapValues { it.value.value }, n.conditions.mapValues { it.value.value })
.also { it.audio = n.audioFileName }
}

val edgesS = dialogueGraph.edges
Expand Down Expand Up @@ -162,6 +169,8 @@ object DialogueGraphSerializer {
else -> throw IllegalArgumentException("Unknown node type: ${n.type}")
}

node.audioFileNameProperty.value = n.audio

graph.nodes[id] = node
}

Expand All @@ -176,6 +185,8 @@ object DialogueGraphSerializer {
node.conditions[option.key] = SimpleStringProperty(option.value)
}

node.audioFileNameProperty.value = n.audio

graph.nodes[id] = node
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ abstract class NodeView(val node: DialogueNode) : Pane() {
val audioField = AudioField()
audioField.visibleProperty().bind(getbp(IS_SHOW_AUDIO_LINES))

audioField.field.text = node.audioFileNameProperty.value

node.audioFileNameProperty.bindBidirectional(audioField.field.textProperty())

contentRoot.children.add(0, audioField)

prefHeightProperty().bind(textArea.prefHeightProperty().add(85))
Expand Down Expand Up @@ -173,12 +177,13 @@ class AudioField() : HBox(5.0) {
private val audioFileChooser = FileChooser()
}

val field = TextField()

init {
audioFileChooser.initialDirectory = File(System.getProperty("user.dir"))

val icon = makeSoundIcon()

val field = TextField()
field.prefWidth = 190.0

val button = CustomButton("...", 14.0)
Expand Down

0 comments on commit 444c951

Please sign in to comment.