This is a Java port of inkle's ink, a scripting language for writing interactive narrative.
blade-ink should support pretty much everything the original version does. If you find any bugs, please report them here!
First you need to turn your ink file into a json file as described here. Here is an example to load the ink JSON file as a String:
InputStream systemResourceAsStream = ClassLoader.getSystemResourceAsStream(filename);
BufferedReader br = new BufferedReader(new InputStreamReader(systemResourceAsStream, "UTF-8"));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
} finally {
br.close();
}
String json = sb.toString().replace('\uFEFF', ' ');
Here's a taster of the code you need to get started:
// 1) Load story
Story story = new Story(sourceJsonString);
// 2) Game content, line by line
while (story.canContinue()) {
String line = story.Continue();
System.out.print(line);
}
// 3) Display story.currentChoices list, allow player to choose one
if (story.getCurrentChoices().size() > 0) {
for (Choice c : story.getCurrentChoices()) {
System.out.println(c.getText());
}
story.chooseChoiceIndex(0);
}
// 4) Back to 2
// ...
From there on, you can follow the official guide. All functions are named exactly the same.
The blade-ink library is available in the Maven archives.
Add the following line to your build.gradle
file under the dependencies section of the core project:
compile "com.bladecoder.ink:blade-ink:{version}"
Replace {version} with the newest version number!
Then simply right-click the project and choose Gradle->Refresh All
.
Right-click on your project and choose Maven->Add Dependency
and search for bladecoder. Make sure to choose the most recent version if multiple appear!
First, clone this project to your computer and add it to Eclipse. Then simply click on your project, and choose Build Path->Configure Build Path
. Then go to Projects->Add
and add the cloned project.
There are several open-source sample projects for the blade-ink library on different platforms:
- blade-ink-template: LibGDX and Java (Android, Desktop, and IOS)
- storybytes-android: Kotlin (Android)
- storybytes-desktop: Kotlin and TornadoFX (Desktop)