File size: 1,705 Bytes
670a607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import QuestionManager from '../../plugins/logic/quest/questions/QuestionManager.js';
import QuestMethods from './QuestMethods.js';
import DataMethods from './DataMethods.js';

const EE = Phaser.Events.EventEmitter;
const GetValue = Phaser.Utils.Objects.GetValue;

class DialogQuest extends EE {
    constructor(config) {
        super();

        if (config === undefined) {
            config = {};
        }
        if (!config.quest) {
            config.quest = true;
        }

        this.dialog = GetValue(config, 'dialog', undefined);
        this.questionManager = new QuestionManager(config);

        // Attach events
        this.questionManager
            .on('quest', function (question) {
                var choices = this.dialog.getElement('choices');
                var options = question.options, option;
                for (var i = 0, cnt = choices.length; i < cnt; i++) {
                    option = options[i];
                    if (option) {
                        this.dialog.showChoice(i);
                        this.emit('update-choice', choices[i], option, this);
                    } else {
                        this.dialog.hideChoice(i);
                    }
                }
                this.emit('update-dialog', this.dialog, question, this);
            }, this);

        this.dialog
            .on('button.click', function (button, groupName, index) {
                var eventName = 'click-' + ((groupName === 'choices') ? 'choice' : 'action');
                this.emit(eventName, button, this.dialog, this);
            }, this)
    }
}

Object.assign(
    DialogQuest.prototype,
    QuestMethods,
    DataMethods
);


export default DialogQuest;