Converser.js

Handles conversation and adaptation in a game.

by Sam Fereday

JavaScript

/*
	Converser expects a database of various strings and conversations to load. Rather than have each string exist as a singleton, we group the various parts of the strings together instead.
  How you manage that collection of strings is entirely up to you. What's different from before is that the conversation has no knowledge of who's saying it. This is something, like quests, that will be set in some sort of game or level data area that binds all the id's together. This allows for complete data decouplment.
  The same thing goes for when you want to say a certain conversation after a certain point of the game has been reached. So what we'll do is put a bit of that in here as a test.
So what does conversor need to do?
- Like quester, it needs to load the data for the conversation database. Might as well do it in the same way. This goes double for mapping the json data to js objects.
- It needs to be able to retrieve data to the thing that asks for it at any point. This includes being able to grab multiple conversations at any one time.
- Frankly that's about it. I mean getting a conversation is a simple case of getting by ID, then sending out the array of data to use. Bindings will be set outside this component as mentioned before.
- For stuff like 'options', we'll add a flag to say that this particular string is allowing the parser to trigger an attached option or action. This will be defined elsewhere, but allows us to use the data at the right points.

Actions aren't stored in convos, only options are. Actions should be defined to be triggered elsewhere, but the options in the convo are allowed since they're still part of the same flow. Weight is a value measured by the option chosen. It depends on what you want to get out of the response to the question asked. All neutral might just lead to another conversation, this would be good for a list. Yes / No answers could carry weight of 1 or -1. It's all about context, you don't need to use it, but it'd make more...