Conversationer
This is to be a plugin to drop in to the likes of Unity. It should support a basic graph structure for conversation trees. We aren't using any conditions here, etc. Just a basic implementation is fine for now.
by Sam Fereday
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.0/vis.min.js"></script>
<div id="mynetwork"></div>
CSS
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
#network {
width: 100%;
height: 100%;
}
JavaScript
/// You could quite easily re-engineer this 'thing' to use for scripted events also. With a couple of asyn and event callbacks. I'd suggest bolting on a module to the core however, as it should be left pristine.
// Data mockup (we'd likely auto-generate this on the fly). So for each new node made with text, it gets a guid. Then when we set a link to it, we plant that guid in the linked bit. Or an index, whatever works.
var json = [{
"id": "0",
"text": "Huh.",
"linked": ["1"],
"actions": []
}, {
"id": "1",
"text": "You don't look like you're from around here.",
"linked": ["2", "3"],
"actions": []
}, {
"id": "2",
"text": "I've lived here all my life!",
"linked": ["4"],
"actions": []
}, {
"id": "3",
"text": "I came here from Newton.",
"linked": ["4"],
"actions": []
}, {
"id": "4",
"text": "I don't care either way. This was fun.",
"linked": [],
"actions": []
}];
// Actions would be small nodes on their own that might trigger certain events. It may be wise to set some sort of 'async' flag, as if set, you could run them all at once whilst the conversation happens. Such as if you have people talking in a cutscene, but need to walk around also. You may also want some sort of 'wait' mechanism to halt it at certain points. This, is out of the scope of this tool however.
// Actions should also just be id's in this instance. It makes no sense to carry that extra weight around. It 'might' even make sense to do this for nodes too.
// ...
// https://gamedev.stackexchange.com/questions/40519/how-do-dialog-trees-work
// A node is universal. For every sentence, a node will exist in memory, ready to be used for whatever purpose.
var QNode = function(data, isRoot) {
// Sanitize - Let us make the assumption that all text must be set. For automated events, you may wish to handle these elsewhere.
if (!data.text)
throw "- Node would be redundant (are you passing any data?)";
this.id = data.id;
this.text = data.text;
//...