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();
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);
vnjs.emit('jump', TREE.$root.package.entry)
vnjs.on('init', scene=>{
if(scene){
console.log('isScene')
}
vnjs.exec();
})
document.body.addEventListener('click', e=>{
vnjs.next();
});
API
.exec({userEvent: "hello world"})
.on('userEvent', function (ctx){
alert(ctx)
})
.emit('event', ...args)
.next()
.getCurrentLabelBody()
.getCtx()
.getCurrentCharacter()
.getCharacterById(id)
.setTree(TREE)
.current: {
index: 0,
labelName: 'string',
sceneName: 'string'
}