All Projects → bladecoder → blade-ink

bladecoder / blade-ink

Licence: MIT license
Inkle Ink runtime implementation in Java

Programming Languages

java
68154 projects - #9 most used programming language
Ink
2 projects

blade-ink

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!

Getting started

Loading a json file

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', ' ');

Starting a story

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.

Integration

The blade-ink library is available in the Maven archives.

Using with Gradle

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.

Using with Maven

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!

Eclipse

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.

Sample Projects

There are several open-source sample projects for the blade-ink library on different platforms:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].