vnjson.js
v1.6.0
Published
Vnjson Scripting language interpreter
Downloads
1
Readme
vnjson.js
Vnjson Scripting language interpreter
Discription
Install
Browser
<script src="https://unpkg.com/vnjson.js/dist/vnjson.js"></script>
NodeJS
npm install vnjson.js
Demo
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'
}