Skip to content

vnjson/vnjson.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Sep 3, 2022
01d432b · Sep 3, 2022
Sep 3, 2022
Sep 3, 2022
Sep 3, 2022
Feb 25, 2021
May 19, 2017
Apr 19, 2021
Sep 1, 2022
Sep 3, 2022
Sep 1, 2022

Repository files navigation

vnjson.js

Vnjson Scripting language interpreter

Description

vnjson/scheme

Demo

Text Quest

Visual Novel

Install

Browser

<script src="https://unpkg.com/vnjson.js@1.6.0/dist/vnjson.js"></script>

NodeJS

npm install vnjson.js
npm install scenes-to-json -D

Utils

vtq-tpl - Text quest template

vpv-tpl - Visual novel template

Synopsis

const vnjs = new Vnjson();
/**
 *  plugins
 */
function notFound(){
	this.on('*', e=>{
		console.error(`Plugin ${e} not found`)
	});
}

vnjs.use(notFound);

vnjs.use(function (){
	this.on('character', (character, reply)=>{
		console(character.name, reply);
	})
});

const TREE = {
	$root: {
		pacakge: {entry: 'scene_1.entry'},
		characters: [
			{id: 'a', name: 'Alice'}
		]
	}, 
	scene_1: {
		assets: [],
		entry: [
			"Some reply",
			{"a": "Alice say hello world"}
			{jump: 'label_2'}
		],
		label_2: [
			{jump: 'scene_2.start'}
		]
	},
	scene_2: {
		start: []
	}
};

vnjs.setTree(TREE);
/**
 * Set first label
 */
vnjs.emit('jump', TREE.$root.package.entry)
/**
 * Called after the scene or label 
 * has been initialized
 */
vnjs.on('init', scene=>{
	if(scene){
		console.log('isScene')
	}
	//Execute first ctx object
	vnjs.exec();
})
/**
 * Each time it is pressed,
 * the float moves down the tree
 */
document.body.addEventListener('click', e=>{
			vnjs.next();
});

API

//execute current obect
.exec({userEvent: "hello world"})
//listen user events emit in game sript
.on('userEvent', function (ctx){
		// [ ctx ] current object
		alert(ctx)
})
.emit('event', ...args)//emit event
.next() //execute next sting in script
.getCurrentLabelBody()//return label Array
.getCtx()// return current Object
.getCurrentCharacter()
.getCharacterById(id)

.setTree(TREE)

.current: {
	index: 0, //Position in current label
	labelName: 'string',
	sceneName: 'string'
}

Community