-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from benpollarduk/conversation-update
Added tests, updated documentation
- Loading branch information
Showing
27 changed files
with
645 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/Paragraph.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletions
12
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/Response.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package com.github.benpollarduk.ktaf.conversations | ||
|
||
import com.github.benpollarduk.ktaf.conversations.instructions.EndOfParagraphInstruction | ||
import com.github.benpollarduk.ktaf.conversations.instructions.Next | ||
|
||
/** | ||
* A response which forms part of a [Conversation]. The [line] forms the body of the response and the [delta] is a | ||
* relative pointer to the next element within the [Conversation]. | ||
* A response which forms part of a [Conversation]. The [line] forms the body of the response and the [instruction] is | ||
* applied to direct the conversation after this paragraph. | ||
*/ | ||
public data class Response(public val line: String, public val delta: Int = 1) | ||
public data class Response( | ||
public val line: String, | ||
public val instruction: EndOfParagraphInstruction = Next() | ||
) |
13 changes: 13 additions & 0 deletions
13
...tlin/com/github/benpollarduk/ktaf/conversations/instructions/EndOfParagraphInstruction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* Provides a contract for providing instructions for ends of paragraphs. | ||
*/ | ||
public fun interface EndOfParagraphInstruction { | ||
/** | ||
* Get the index of the next paragraph from a [current] paragraph and an array of [paragraphs]. | ||
*/ | ||
public fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int | ||
} |
12 changes: 12 additions & 0 deletions
12
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/First.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that shifts paragraphs to the start. | ||
*/ | ||
public class First : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
return 0 | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/GoTo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that shifts paragraphs based on an absolute [index]. | ||
*/ | ||
public class GoTo(public val index: Int) : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
return if (index < 0) { | ||
0 | ||
} else if (index >= paragraphs.size) { | ||
paragraphs.size - 1 | ||
} else { | ||
index | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/Jump.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that shifts paragraphs based on a delta. | ||
*/ | ||
public class Jump(public val delta: Int) : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
val index = paragraphs.indexOf(current) | ||
val offset = index + delta | ||
return if (offset < 0) { | ||
0 | ||
} else if (offset >= paragraphs.size) { | ||
paragraphs.size - 1 | ||
} else { | ||
offset | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/Last.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that shifts paragraphs to the end. | ||
*/ | ||
public class Last : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
return paragraphs.size - 1 | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/Next.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that shifts paragraphs to the next paragraph. | ||
*/ | ||
public class Next : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
val index = paragraphs.indexOf(current) | ||
return if (index == -1) { | ||
0 | ||
} else if (index < paragraphs.size - 1) { | ||
index + 1 | ||
} else { | ||
paragraphs.size - 1 | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/Previous.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that shifts paragraphs to the previous paragraph. | ||
*/ | ||
public class Previous : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
val index = paragraphs.indexOf(current) | ||
return if (index > 0) { | ||
index - 1 | ||
} else { | ||
0 | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/Repeat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that repeats. | ||
*/ | ||
public class Repeat : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
val index = paragraphs.indexOf(current) | ||
return if (index < 0) { | ||
0 | ||
} else { | ||
index | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
ktaf/src/main/kotlin/com/github/benpollarduk/ktaf/conversations/instructions/ToName.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.benpollarduk.ktaf.conversations.instructions | ||
|
||
import com.github.benpollarduk.ktaf.conversations.Paragraph | ||
|
||
/** | ||
* An end of paragraph instruction that shifts paragraphs based on a name. | ||
*/ | ||
public class ToName(public val name: String) : EndOfParagraphInstruction { | ||
override fun getIndexOfNext(current: Paragraph, paragraphs: List<Paragraph>): Int { | ||
val target = paragraphs.firstOrNull { | ||
it.name.equals(name, true) | ||
} | ||
|
||
return if (target != null) { | ||
paragraphs.indexOf(target) | ||
} else { | ||
0 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.