A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AlmasB/FXGL/commit/4b9214be5 below:

dialogue nodes can now be copied · AlmasB/FXGL@4b9214b · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+80

-9

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+80

-9

lines changed Original file line number Diff line number Diff line change

@@ -6,6 +6,7 @@

6 6 7 7

package com.almasb.fxgl.cutscene.dialogue

8 8 9 +

import com.almasb.fxgl.core.Copyable

9 10

import com.almasb.fxgl.core.collection.PropertyMap

10 11

import com.almasb.fxgl.cutscene.dialogue.DialogueNodeType.*

11 12

import javafx.beans.property.SimpleStringProperty

@@ -37,7 +38,7 @@ fun interface DialogueContext {

37 38

sealed class DialogueNode(

38 39

val type: DialogueNodeType,

39 40

text: String

40 -

) {

41 +

) : Copyable<DialogueNode> {

41 42 42 43

val textProperty: StringProperty = SimpleStringProperty(text)

43 44

@@ -54,17 +55,29 @@ sealed class DialogueNode(

54 55

}

55 56

}

56 57 57 -

class StartNode(text: String) : DialogueNode(START, text)

58 +

class StartNode(text: String) : DialogueNode(START, text) {

59 +

override fun copy(): StartNode = StartNode(text)

60 +

}

58 61 59 -

class EndNode(text: String) : DialogueNode(END, text)

62 +

class EndNode(text: String) : DialogueNode(END, text) {

63 +

override fun copy(): EndNode = EndNode(text)

64 +

}

60 65 61 -

class TextNode(text: String) : DialogueNode(TEXT, text)

66 +

class TextNode(text: String) : DialogueNode(TEXT, text) {

67 +

override fun copy(): TextNode = TextNode(text)

68 +

}

62 69 63 -

class SubDialogueNode(text: String) : DialogueNode(SUBDIALOGUE, text)

70 +

class SubDialogueNode(text: String) : DialogueNode(SUBDIALOGUE, text) {

71 +

override fun copy(): SubDialogueNode = SubDialogueNode(text)

72 +

}

64 73 65 -

class FunctionNode(text: String) : DialogueNode(FUNCTION, text)

74 +

class FunctionNode(text: String) : DialogueNode(FUNCTION, text) {

75 +

override fun copy(): FunctionNode = FunctionNode(text)

76 +

}

66 77 67 -

class BranchNode(text: String) : DialogueNode(BRANCH, text)

78 +

class BranchNode(text: String) : DialogueNode(BRANCH, text) {

79 +

override fun copy(): BranchNode = BranchNode(text)

80 +

}

68 81 69 82

class ChoiceNode(text: String) : DialogueNode(CHOICE, text) {

70 83

@@ -87,6 +100,17 @@ class ChoiceNode(text: String) : DialogueNode(CHOICE, text) {

87 100

*/

88 101

val lastOptionID: Int

89 102

get() = options.keys.maxOrNull() ?: -1

103 + 104 +

override fun copy(): ChoiceNode {

105 +

val copy = ChoiceNode(text)

106 +

options.forEach { (k, v) ->

107 +

copy.options[k] = SimpleStringProperty(v.value)

108 +

}

109 +

conditions.forEach { (k, v) ->

110 +

copy.conditions[k] = SimpleStringProperty(v.value)

111 +

}

112 +

return copy

113 +

}

90 114

}

91 115 92 116

/* EDGES */

Original file line number Diff line number Diff line change

@@ -7,9 +7,9 @@

7 7

package com.almasb.fxgl.cutscene.dialogue

8 8 9 9

import com.almasb.fxgl.cutscene.dialogue.DialogueNodeType.*

10 +

import javafx.beans.property.SimpleStringProperty

10 11

import org.hamcrest.MatcherAssert.assertThat

11 -

import org.hamcrest.Matchers.`is`

12 -

import org.hamcrest.Matchers.contains

12 +

import org.hamcrest.Matchers.*

13 13

import org.junit.jupiter.api.Assertions.assertFalse

14 14

import org.junit.jupiter.api.Assertions.assertTrue

15 15

import org.junit.jupiter.api.BeforeEach

@@ -185,6 +185,53 @@ class DialogueGraphTest {

185 185

assertTrue(graph.containsNode(node1))

186 186

}

187 187 188 +

@Test

189 +

fun `Copy nodes`() {

190 +

listOf(

191 +

StartNode("TestText"),

192 +

EndNode("TestText"),

193 +

TextNode("TestText"),

194 +

SubDialogueNode("TestText"),

195 +

FunctionNode("TestText"),

196 +

BranchNode("TestText"),

197 +

ChoiceNode("TestText")

198 +

).forEach {

199 +

val copy = it.copy()

200 +

assertThat(it.text, `is`(copy.text))

201 +

assertThat(it.type, `is`(copy.type))

202 +

}

203 +

}

204 + 205 +

@Test

206 +

fun `Copy choice options`() {

207 +

val choice = ChoiceNode("Choice")

208 +

choice.options[0] = SimpleStringProperty("Choice A")

209 +

choice.options[1] = SimpleStringProperty("Choice B")

210 +

choice.options[2] = SimpleStringProperty("Choice C")

211 + 212 +

choice.conditions[0] = SimpleStringProperty("Condition A")

213 +

choice.conditions[1] = SimpleStringProperty("Condition B")

214 +

choice.conditions[2] = SimpleStringProperty("Condition C")

215 + 216 +

val copy = choice.copy()

217 + 218 +

assertThat(choice.lastOptionID, `is`(copy.lastOptionID))

219 + 220 +

// StringProperty has to be a deep copy, not shallow

221 +

assertThat(choice.options, `is`(not(copy.options)))

222 +

assertThat(choice.conditions, `is`(not(copy.conditions)))

223 +

assertThat(choice.options.size, `is`(copy.options.size))

224 +

assertThat(choice.conditions.size, `is`(copy.conditions.size))

225 + 226 +

choice.options.forEach { (k, v) ->

227 +

assertThat(v.value, `is`(copy.options[k]!!.value))

228 +

}

229 + 230 +

choice.conditions.forEach { (k, v) ->

231 +

assertThat(v.value, `is`(copy.conditions[k]!!.value))

232 +

}

233 +

}

234 + 188 235

@Test

189 236

fun `Copy`() {

190 237

val node1 = ChoiceNode("")

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4