Skip to content

Commit

Permalink
Merge pull request #11 from benpollarduk/dsl-changes
Browse files Browse the repository at this point in the history
Changes to dsl for clearer dsl syntax
  • Loading branch information
benpollarduk authored Jan 19, 2024
2 parents 9e457dc + 470957f commit 4791f81
Show file tree
Hide file tree
Showing 41 changed files with 318 additions and 320 deletions.
86 changes: 43 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ val narrator = Narrator(configuration.gameAdapter.narratorAdapter)
val story = story {

// add a single chapter
it add chapter {
this add chapter {

// add a new scene
it add scene {
this add scene {

// set the steps that make up the scene
it steps listOf(
this steps listOf(

// include a simple narration step
next { narrator narrates "Welcome to a Ktvn visual novel!" }
Expand Down Expand Up @@ -230,8 +230,8 @@ next { audio sfx sfxFromResource("crash") }
then is very similar to next, but allows the step to be named. This is useful if the story needs to jump to this step.
```kotlin
then {
it name "Michel shows anger"
it does {
this name "Michel shows anger"
this does {
michel looks angry
}
}
Expand All @@ -242,17 +242,17 @@ choice allows the user to present a question to the user and receive an answer.
multiple choice question:
```kotlin
choice {
morgana asks question { question ->
question line "Why we do, don't we dear?"
question option answer { answer ->
answer line "Of course."
answer does { flags ->
morgana asks question {
this line "Why we do, don't we dear?"
this option answer {
this line "Of course."
this does { flags ->
flags setTrue "Michel likes Morgana"
}
}
question option answer { answer ->
answer line "I hate you!"
answer does { flags ->
this option answer {
this line "I hate you!"
this does { flags ->
flags setTrue "Michel hates Morgana"
}
}
Expand All @@ -268,20 +268,20 @@ case a flag is set to register the option that the user picked.
### decision
decision is very similar to choice, but allows the step to be named. This is useful if the story needs to jump to this step.
```kotlin
decision { decision ->
decision name "Michel's feeling towards Morgana"
decision does {
morgana asks question { question ->
question line "Why we do, don't we dear?"
question option answer { answer ->
answer line "Of course."
answer does { flags ->
decision {
this name "Michel's feeling towards Morgana"
this does {
morgana asks question {
this line "Why we do, don't we dear?"
this option answer {
this line "Of course."
this does { flags ->
flags setTrue "Michel likes Morgana"
}
}
question option answer { answer ->
answer line "I hate you!"
answer does { flags ->
this option answer {
this line "I hate you!"
this does { flags ->
flags setTrue "Michel hates Morgana"
}
}
Expand All @@ -294,12 +294,12 @@ decision { decision ->
conditional allows a step to only be invoked if a specified condition is met.
```kotlin
conditional {
it condition "Michel likes Morgana"
it does {
this condition "Michel likes Morgana"
this does {
morgana looks amused
morgana says "Fool, I despise you!"
}
it returns Continue
this returns Continue
}
```
The **condition** keyword specifies the flag. If that flag is set to true then the script specified by the **does**
Expand All @@ -310,7 +310,7 @@ continue, branch or end as required.
pause is a step that prevents the story from progressing for the specified time, in milliseconds.
```kotlin
pause {
it seconds 5
this seconds 5
}
```
The **seconds** keyword allows the delay time to be specified, in seconds. Shorter delays can be specified in
Expand All @@ -329,8 +329,8 @@ example, some visual novels may contain mini-games. Providing the mini game impl
**InteractiveComponent** it can be invoked in a step.
```kotlin
interactive {
it element component
it args arrayOf("args1", "args2")
this element component
this args arrayOf("args1", "args2")
}
```
An example of wrapping a component:
Expand All @@ -356,7 +356,7 @@ val component = object: InteractiveComponent {
end is a simple step that signifies that an ending has been reached.
```kotlin
end {
it ending Ending("True End.", 1)
this ending Ending("True End.", 1)
}
```
The ending that was reached can be specified with the **ending** keyword.
Expand Down Expand Up @@ -398,25 +398,25 @@ The source for some of the above scene:

```kotlin
internal fun onTheLaunchPad(): Scene {
return scene { scene ->
scene name "On the launch pad"
scene background shuttleDay
scene music shuttleDayMusic
scene layout createLayout { layout ->
layout addLeftOf sophie
layout addRightOf toki
layout configure configuration.gameAdapter.layoutAdapter
return scene {
this name "On the launch pad"
this background shuttleDay
this music shuttleDayMusic
this layout createLayout {
this addLeftOf sophie
this addRightOf toki
this configure configuration.gameAdapter.layoutAdapter
}
scene steps listOf(
this steps listOf(
next {
scene.layout moveCenter sophie
layout moveCenter sophie
sophie looks normal
sophie says "Where has that fool gotten to now?"
},
next { audio sfx sfxWoosh },
next {
scene.layout moveLeft sophie
scene.layout moveRight toki
layout moveLeft sophie
layout moveRight toki
toki looks normal
toki says "Here I am!"
toki says "Ready for duty!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.github.benpollarduk.ktvn.structure.Story.Companion.story

public class ShuttleLaunch : VisualNovel(
story {
it name "Shuttle Launch"
it add prologue()
it add launch()
this name "Shuttle Launch"
this add prologue()
this add launch()
},
AssetStore.configuration,
Resolution(RESOLUTION_WIDTH, RESOLUTION_HEIGHT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.github.benpollarduk.ktvn.structure.Chapter.Companion.chapter

internal fun launch(): Chapter {
return chapter {
it name "Chapter 1: Launch"
it add onTheLaunchPad()
it add memoriesOfToki()
it add backOnTheLaunchPad()
this name "Chapter 1: Launch"
this add onTheLaunchPad()
this add memoriesOfToki()
this add backOnTheLaunchPad()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ import com.github.benpollarduk.ktvn.structure.steps.Then.Companion.next

@Suppress("LongMethod")
internal fun backOnTheLaunchPad(): Scene {
return scene { scene ->
scene name "Back on the launch pad"
scene background shuttleDay
scene music shuttleDayMusic
scene transitionIn sceneFadeIn
scene transitionOut sceneFadeOut
scene layout createLayout { layout ->
layout addRightOf sophie
layout addHidden toki
layout configure configuration.gameAdapter.layoutAdapter
layout transition layoutFadeIn
return scene {
this name "Back on the launch pad"
this background shuttleDay
this music shuttleDayMusic
this transitionIn sceneFadeIn
this transitionOut sceneFadeOut
this layout createLayout {
this addRightOf sophie
this addHidden toki
this configure configuration.gameAdapter.layoutAdapter
this transition layoutFadeIn
}
scene steps listOf(
this steps listOf(
next {
scene.layout moveCenter toki
layout moveCenter toki
toki thinks "I know she doesn't trust me... but I aced basic training and the rest of astronaut school."
},
next {
Expand All @@ -48,18 +48,18 @@ internal fun backOnTheLaunchPad(): Scene {
next {
toki thinks "Maybe I left it over here..."
audio sfx sfxWoosh
scene.layout transition layoutSlide
scene.layout moveRight toki
layout transition layoutSlide
layout moveRight toki
},
next {
toki thinks "...or maybe here"
audio sfx sfxWoosh
scene.layout transition layoutSlide
scene.layout moveLeft toki
layout transition layoutSlide
layout moveLeft toki
},
next {
sophie looks normal
scene.layout moveRight sophie
layout moveRight sophie
sophie says "There you are, I've been looking everywhere for you! What's up?"
},
next {
Expand All @@ -72,16 +72,16 @@ internal fun backOnTheLaunchPad(): Scene {
},
next {
sophie looks normal
scene.layout exitRight sophie
layout exitRight sophie
toki says "Why does she always call me that?!"
toki begins shaking
},
next {
scene.layout moveRight sophie
layout moveRight sophie
sophie says "Because you are."
},
next {
scene.layout exitRight sophie
layout exitRight sophie
},
next {
toki says "I should learn to keep quiet."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ import com.github.benpollarduk.ktvn.structure.steps.Then.Companion.next

@Suppress("MaxLineLength")
internal fun memoriesOfToki(): Scene {
return scene { scene ->
scene name "Memory of launch"
scene background shuttleMemory
scene music shuttleDayMusic
scene transitionIn sceneFadeIn
scene transitionOut sceneFadeOut
scene layout createLayout { layout ->
layout addHidden tokiMemory
layout configure configuration.gameAdapter.layoutAdapter
layout transition layoutFadeIn
return scene {
this name "Memory of launch"
this background shuttleMemory
this music shuttleDayMusic
this transitionIn sceneFadeIn
this transitionOut sceneFadeOut
this layout createLayout {
this addHidden tokiMemory
this configure configuration.gameAdapter.layoutAdapter
this transition layoutFadeIn
}
scene steps listOf(
this steps listOf(
next {
sophie thinks "Things never used to be so complex. However everything changed that fateful night..."
},
next {
scene.layout moveCenter tokiMemory
layout moveCenter tokiMemory
sophie thinks "He was always the class clown, but I knew before things went wrong that there was more to him than that."
},
next {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ import com.github.benpollarduk.ktvn.structure.Scene.Companion.scene
import com.github.benpollarduk.ktvn.structure.steps.Then.Companion.next

internal fun onTheLaunchPad(): Scene {
return scene { scene ->
scene name "On the launch pad"
scene background shuttleDay
scene music shuttleDayMusic
scene transitionIn sceneFadeIn
scene transitionOut sceneFadeOut
scene layout createLayout { layout ->
layout addLeftOf sophie
layout addRightOf toki
layout configure configuration.gameAdapter.layoutAdapter
layout transition layoutSlide
return scene {
this name "On the launch pad"
this background shuttleDay
this music shuttleDayMusic
this transitionIn sceneFadeIn
this transitionOut sceneFadeOut
this layout createLayout {
this addLeftOf sophie
this addRightOf toki
this configure configuration.gameAdapter.layoutAdapter
this transition layoutSlide
}
scene steps listOf(
this steps listOf(
next {
scene.layout moveCenter sophie
layout moveCenter sophie
sophie looks normal
sophie says "Where has that fool gotten to now?"
},
next { audio sfx sfxWoosh },
next {
scene.layout moveLeft sophie
scene.layout moveRight toki
layout moveLeft sophie
layout moveRight toki
toki looks normal
toki says "Here I am!"
toki says "Ready for duty!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.github.benpollarduk.ktvn.structure.Chapter.Companion.chapter

internal fun prologue(): Chapter {
return chapter {
it name "Prologue"
it add introduction()
this name "Prologue"
this add introduction()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import com.github.benpollarduk.ktvn.structure.steps.Then.Companion.next

@Suppress("MaxLineLength")
internal fun introduction(): Scene {
return scene { scene ->
scene name "Introduction"
scene background empty
scene music silence
scene type narrative
scene layout createLayout {
it configure configuration.gameAdapter.layoutAdapter
return scene {
this name "Introduction"
this background empty
this music silence
this type narrative
this layout createLayout {
this configure configuration.gameAdapter.layoutAdapter
}
scene steps listOf(
this steps listOf(
next { narrator narrates "It's late afternoon and the the shuttle test flight looms ahead." },
next { narrator narrates "In a few days time the launch sequence will initiate and the shuttle will leave earth for good." },
next { narrator narrates "Is Toki ready?" }
Expand Down
Loading

0 comments on commit 4791f81

Please sign in to comment.