Browse Source

Merge branch '101-extended-dialogue-actions' into 'staging'

Resolve "Dialogue options should be able to call methods on other objects' components"

See merge request !57
tags/v0.1.2^2
Big Bad Waffle 7 years ago
parent
commit
2b82e1eb23
2 changed files with 37 additions and 2 deletions
  1. +5
    -0
      src/client/ui/templates/talk/talk.js
  2. +32
    -2
      src/server/components/dialogue.js

+ 5
- 0
src/client/ui/templates/talk/talk.js View File

@@ -18,6 +18,11 @@ define([

postRender: function() {
this.onEvent('onGetTalk', this.onGetTalk.bind(this));
this.onEvent('onRezone', this.onRezone.bind(this));
},

onRezone: function() {
this.hide();
},

onGetTalk: function(dialogue) {


+ 32
- 2
src/server/components/dialogue.js View File

@@ -95,8 +95,18 @@ define([

if (stateConfig.cpn) {
var cpn = sourceObj[stateConfig.cpn];
cpn[stateConfig.method].apply(cpn, stateConfig.args);
return;
var newArgs = extend(true, [], stateConfig.args);
newArgs.push(this.obj);
var result = cpn[stateConfig.method].apply(cpn, newArgs);

if (stateConfig.goto) {
if (result)
return this.getState(sourceObj, stateConfig.goto.success);
else
return this.getState(sourceObj, stateConfig.goto.failure);
}
else
return null;
}

var result = {
@@ -158,6 +168,26 @@ define([
return {
type: 'dialogue'
};
},

//These don't belong here, but I can't figure out where to put them right now
//They are actions that can be performed while chatting with someone
teleport: function(msg) {
this.obj.syncer.set(true, 'dialogue', 'state', null);

var portal = extend(true, {}, require('./components/portal'), msg);
portal.collisionEnter(this.obj);
},

getItem: function(msg, source) {
var inventory = this.obj.inventory;
var exists = inventory.items.find(i => (i.name == msg.item.name));
if (!exists) {
inventory.getItem(msg.item);
return true;
}
else
return false;
}
};
});

Loading…
Cancel
Save