Socket
Socket
Sign inDemoInstall

vnjson.js

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vnjson.js

Vnjson Scripting language interpreter


Version published
Weekly downloads
4
Maintainers
1
Created
Weekly downloads
 

Readme

Source

vnjson.js

Vnjson Scripting language interpreter

Discription

vnjson/scheme

Install

Browser

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

NodeJS

npm install vnjson.js

Demo

Text Quest

Visual Novel

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

FAQs

Last updated on 28 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc