-
Notifications
You must be signed in to change notification settings - Fork 2
/
phreaknation.manager.dialog.min.js
1 lines (1 loc) · 3.83 KB
/
phreaknation.manager.dialog.min.js
1
!function(){"use strict";var __modulename="dialog_manager",__pluginname="DialogManager",__version=[0,0,1],__description="Dialog system that pulls scripts of dialog based on scripts.",__author="Joel Dies <[email protected]>",__schemas={},__types=["actor","answer","dialog","emotion"],__dialogStore={},plugin=function(game,parent){return Phaser.Plugin.call(this,game,parent),"undefined"==typeof console.error&&(console.error=console.log),this.game=game,this.parent=parent,this.schemas=__schemas,this};plugin.prototype=Object.create(Phaser.Plugin.prototype),plugin.prototype.constructor=Phaser.Plugin.SamplePlugin,plugin.prototype.description=function(){return _.toTitleCase(_.replace(__modulename,/\_/g," "))+" plugin by "+__author+". "+__description},plugin.prototype.version=function(){return __version.join(".")},plugin.prototype.format=function(text){for(var match,regexp=/{([a-zA-Z]+):(0x[0-9]{3})}/g,markers=[],matches=0,maxMatches=50,result=text;null!==(match=regexp.exec(text))&&matches<maxMatches;)markers.push(match),matches++;return _.each(markers,function(marker){var type=marker[1],index=marker[2];if(_.isString(type)&&_.isString(index))switch(type){case"actor":if(_.isUndefined(index))return"falseA";var actor=this.get(parseInt(index),"actor");if(_.isUndefined(actor))return"falseB";result=_.replace(text,/\{.*\}/,actor.name())}}.bind(this)),result},plugin.prototype.get=function(id,type){if(_.isUndefined(type)&&(type="dialog"),_.isString(type)){if(type=_.toLower(type),__types.indexOf(type)!==-1){var config,db=__dialogStore[type];return _.isString(db[0])?config=_.get(db,id):_.isObject(db[0])&&(config=_.find(db,{id:id})),_.isUndefined(config)?"false3":"dialog"===type?new dialog(this,config):"actor"===type?new actor(this,config):{_config:config}}return"false2"}return"false1"},plugin.prototype.load=function(config){return!!_.isObject(config)&&(__dialogStore=config,!0)};var dialog=function(scope,config){return!!_.isObject(config)&&(this._config=config,this._manager=scope,this)};plugin.prototype.Dialog=dialog,dialog.prototype.actor=function(){return!_.isUndefined(this._actor)&&this._actor},dialog.prototype.answers=function answers(){if(_.isArray(this._config.answers)){var answers=[];return _.each(this._config.answers,function(ans){if(_.isNumber(ans.answerId)){var answer=this._manager.get(ans.answerId,"answer");answers.push(this._manager.format(answer._config.text))}}.bind(this)),answers}return!1},dialog.prototype.choose=function(id){if("question"===_.toLower(this._config.type)){var answer=_.get(this._config.answers,id);return this.process(answer.answerId,"answer"),this._config.next=answer.next,this}return!1},dialog.prototype.emotion=function(){return!!_.isString(this._config.emotion)&&this._manager.get(this._config.emotion,"emotion")},dialog.prototype.next=function(){return!!_.isNumber(this._config.next)&&this.play(this._config.next)},dialog.prototype.play=function(id){return id=id||1,this.process(id),this},dialog.prototype.process=function(id,type){return type=type||"dialog",_.isNumber(id)?(this._config=this._manager.get(id,type)._config,this._config.actorId=this._config.actorId||1,this._config.actorId&&(this._actor=this._manager.get(this._config.actorId,"actor")),"question"===_.toLower(this._config.type)?this.isQuestion=!0:this.isQuestion=!1,this):(console.log("FAILED"),!1)},dialog.prototype.text=function(){return!!_.isString(this._config.text)&&this._manager.format(this._config.text)};var actor=function(scope,config){return!_.isUndefined(scope),this._manager=scope,!!_.isObject(config)&&(this._config=config,this)};plugin.prototype.Actor=actor,actor.prototype.name=function(full){return full=full||!1,!!_.isObject(this._config)&&(full?this._config.name.first+" "+this._config.name.last:this._config.name.first)},window.PhreakNation=window.PhreakNation||{},window.PhreakNation.Plugins=window.PhreakNation.Plugins||{},window.PhreakNation.Plugins[__pluginname]=plugin}();