All Projects → y-lohse → Inkjs

y-lohse / Inkjs

Licence: mit
A javascript port of inkle's ink scripting language.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Inkjs

Ggez
Rust library to create a Good Game Easily
Stars: ✭ 3,120 (+964.85%)
Mutual labels:  game-development
Games
Create interesting games by pure python.
Stars: ✭ 3,431 (+1070.99%)
Mutual labels:  game-development
Stride
Stride Game Engine (formerly Xenko)
Stars: ✭ 3,524 (+1102.73%)
Mutual labels:  game-development
Raylib Rs
Rust bindings for raylib
Stars: ✭ 263 (-10.24%)
Mutual labels:  game-development
Quiz Game
Multiple choice questions answer game for android (Quiz game).
Stars: ✭ 277 (-5.46%)
Mutual labels:  game-development
Minigolf
A minigolf game written without a game engine in C
Stars: ✭ 282 (-3.75%)
Mutual labels:  game-development
Gamedevelopmentlinks
This is a collection of useful game-development links including, but not restricted to, development with MonoGame.
Stars: ✭ 257 (-12.29%)
Mutual labels:  game-development
Apecs
a fast, type driven, extensible ECS for game development
Stars: ✭ 292 (-0.34%)
Mutual labels:  game-development
Game Programmer Study Notes
⚓ 我的游戏程序员生涯的读书笔记合辑。你可以把它看作一个加强版的Blog。涉及图形学、实时渲染、编程实践、GPU编程、设计模式、软件工程等内容。Keep Reading , Keep Writing , Keep Coding.
Stars: ✭ 6,050 (+1964.85%)
Mutual labels:  game-development
Blog
gamedev blog
Stars: ✭ 3,076 (+949.83%)
Mutual labels:  game-development
Noahgameframe
A fast, scalable, distributed game server engine/framework for C++, include the actor library, network library, can be used as a real time multiplayer game engine ( MMO RPG/MOBA ), which support C#/Lua script/ Unity3d, Cocos2dx and plan to support Unreal.
Stars: ✭ 3,258 (+1011.95%)
Mutual labels:  game-development
Talos
Talos Particle Engine
Stars: ✭ 275 (-6.14%)
Mutual labels:  game-development
Game Programming Patterns
Source repo for the book
Stars: ✭ 3,096 (+956.66%)
Mutual labels:  game-development
Rust Psp
Rust on PSP. Panic and allocation support. Access PSP system libraries.
Stars: ✭ 265 (-9.56%)
Mutual labels:  game-development
Ecsrx
A reactive take on the ECS pattern for .net game developers
Stars: ✭ 288 (-1.71%)
Mutual labels:  game-development
Dascript
daScript - high-performance statically strong typed scripting language
Stars: ✭ 259 (-11.6%)
Mutual labels:  game-development
Glas
WebGL in WebAssembly with AssemblyScript
Stars: ✭ 278 (-5.12%)
Mutual labels:  game-development
Terasology
Terasology - open source voxel world
Stars: ✭ 3,247 (+1008.19%)
Mutual labels:  game-development
Defaultecs
Entity Component System framework aiming for syntax and usage simplicity with maximum performance for game development.
Stars: ✭ 286 (-2.39%)
Mutual labels:  game-development
Zzfx
A Tiny Sound FX System / Zuper Zmall Zound Zynth
Stars: ✭ 279 (-4.78%)
Mutual labels:  game-development

inkjs

build npm codecov

This is a javascript port of inkle's ink, a scripting language for writing interactive narrative.

inkjs is fully compatible with the original version, has zero dependency and works in all browsers and node.js. Please have a look at the demo!

Table of content

Installation

Install using npm install inkjs.

If you are not using npm you can grab the latest release directly from here. Simply include that file with a script tag and you'll be on your way!

For projects targeting older browsers that have no support for ES2015 features, a (heavier but) more backward compatible version is also exposed. Grab it by either:

  • import ink from 'inkjs/dist/ink.js
  • Directly downloading the file from here

Quickstart

The simplest way to get started with inkjs is to use the serverless boilerplate in the templates folder. Replace the placeholder story in story.js with your own and open index.html!

Here's what happens behind the scenes: inkjs gives you access to a global object named inkjs which has a property called Story. This is the main class we interact with.

We simply create a new story by calling var story = new inkjs.Story(storyContent); — the variable storyContent is defined in the story.js file. After that, we can use story.Continue() and story.currentChoices as described in the the official documentation.

Working with a JSON file

If you frequently need to update your story, pasting the content into story.js will probably get tedious. So another option is to dynamically load the JSON file for your story. Unfortunately, your browser won't let you do that because of CORS policy, which means you need a web server to do this. You could do this without much hassle with node.js or python for example.

Once the server is running, use the other boilerplate and place your story content inside story.json. Behind the scenes, the only difference is that we load the JSON file via ajax before creating the story:

fetch("story.json")
  .then(function (response) {
    return response.text();
  })
  .then(function (storyContent) {
    story = new inkjs.Story(storyContent);
    continueStory();
  });

Using node.js

You can find some boilerplate code for node.js here.

Loading inkjs

Require the module: var Story = require('inkjs').Story;.

Loading a json file

You can load the json file using a simple call to require:

var json = require("./ink_file.json");

You can also load it using fs. In that case, please note that inklecate outputs a json file encoded with BOM, and node isn't very good at handling that.

var fs = require("fs");
var json = fs.readFileSync("./ink_file.json", "UTF-8").replace(/^\uFEFF/, ""); //strips the BOM

Starting a story

Now that you have a Story object and a json file, it's time to bring it all together:

var inkStory = new Story(json);

console.log(inkStory.ContinueMaximally());
//etc

From there on, you can follow the official documentation.

Differences with the C# API

There are a few very minor API differences between ink C# and inkjs:

Getting and setting ink variables.

On platforms that do not support ES2015 Proxies (basically node.js v5, IE 11, Safari 9 and everything below), you can't directly read and write variables to the story state. Instead you will have to use the $ function:

_inkStory.variablesState.$("player_health", 100);
//instead of _inkStory.variablesState["player_health"] = 100;

var health = _inkStory.variablesState.$("player_health");
//instead of var health = _inkStory.variablesState["player_health"];

Getting the output text when calling EvaluateFunction

EvaluateFunction() lets you evaluate an ink function from within your javascript. The "normal" call is the same than in C#:

var result = EvaluateFunction("my_ink_function", ["arg1", "arg2"]);
//result is the return value of my_ink_function("arg1", "arg2")

However, if you also wish to retrieve the text that my_ink_function output, you need to call it like this:

var result = EvaluateFunction("my_ink_function", ["arg1", "arg2"], true);
//now result is an object with two properties:
// result.returned is the return value of my_ink_function("arg1", "arg2")
// result.output is the text that was written to the output while the function was evaluated

Compatibility table

inklecate version inkjs version
0.3.5 – 0.4.0 1.0.0 – 1.1.0
0.4.1 – 0.5.0 1.1.1 – 1.1.3
0.5.1 1.2.0
0.6.0 1.3.0
0.6.1 1.4.0 – 1.4.1
0.6.2 1.4.2
0.6.3 1.4.3
0.6.4 1.4.4 – 1.4.6
0.7.0 1.5.0 – 1.5.1
0.7.1 1.5.2
0.7.2 – 0.7.4 1.6.0
0.8.0 – 0.8.1 1.7.1 – 1.7.2
0.8.2 1.8.0 – 1.9.0
0.8.3 1.10.0 – 1.10.5
0.9.0 1.11.0
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].