Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lohse committed Oct 16, 2016
2 parents 52839d1 + 2bd2543 commit 9b73a75
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
74 changes: 48 additions & 26 deletions engine/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,27 +1045,55 @@ export class Story extends InkObject{
if (typeof this._externals[funcName] === 'undefined') console.warn("Function '" + funcName + "' has not been bound.");
delete this._externals[funcName];
}
ValidateExternalBindings(containerOrObject){
ValidateExternalBindings(containerOrObject, missingExternals){
if (!containerOrObject){
this.ValidateExternalBindings(this._mainContentContainer);
var missingExternals = [];
this.ValidateExternalBindings(this._mainContentContainer, missingExternals);
this._hasValidatedExternals = true;

// No problem! Validation complete
if( missingExternals.length == 0 ) {
this._hasValidatedExternals = true;
}

// Error for all missing externals
else {
var message = "Missing function binding for external";
message += (missingExternals.length > 1) ? "s" : "";
message += ": '";
message += missingExternals.join("', '");
message += "' ";
message += (this.allowExternalFunctionFallbacks) ? ", and no fallback ink function found." : " (ink fallbacks disabled)";

var errorPreamble = "ERROR: ";
if (this._mainContentContainer.debugMetadata) {
errorPreamble += "'" + this._mainContentContainer.debugMetadata.fileName + "'";
errorPreamble += " line ";
errorPreamble += this._mainContentContainer.debugMetadata.startLineNumber;
errorPreamble += ": ";

message = errorPreamble + message;
}

this.Error(message);
}
}
else if (containerOrObject instanceof Container){
var c = containerOrObject;

c.content.forEach(innerContent => {
this.ValidateExternalBindings(innerContent);
this.ValidateExternalBindings(innerContent, missingExternals);
});
for (var key in c.namedContent){
this.ValidateExternalBindings(c.namedContent[key]);
this.ValidateExternalBindings(c.namedContent[key], missingExternals);
}
}
else{
var o = containerOrObject;
//the following code is already taken care of above in this implementation
// var container = o as Container;
// if (container) {
// ValidateExternalBindings (container);
// ValidateExternalBindings (container, missingExternals);
// return;
// }

Expand All @@ -1075,22 +1103,13 @@ export class Story extends InkObject{
var name = divert.targetPathString;

if (!this._externals[name]) {

var fallbackFunction = this.mainContentContainer.namedContent[name];
var fallbackFound = typeof fallbackFunction !== 'undefined';

var message = null;
if (!this.allowExternalFunctionFallbacks)
message = "Missing function binding for external '" + name + "' (ink fallbacks disabled)";
else if( !fallbackFound ) {
message = "Missing function binding for external '" + name + "', and no fallback ink function found.";
}

if (message != null){
var errorPreamble = "ERROR: ";
//misses a bit about metadata, which isn't implemented

throw new StoryException(errorPreamble + message);
if( this.allowExternalFunctionFallbacks ) {
var fallbackFound = !!this.mainContentContainer.namedContent[name];
if( !fallbackFound ) {
missingExternals.push(name);
}
} else {
missingExternals.push(name);
}
}
}
Expand Down Expand Up @@ -1156,15 +1175,18 @@ export class Story extends InkObject{
// Expected to be global story, knot or stitch
// var flowContainer = ContentAtPath (path) as Container;
var flowContainer = this.ContentAtPath(path);

// First element of the above constructs is a compiled weave
// var innerWeaveContainer = flowContainer.content [0] as Container;
var innerWeaveContainer = flowContainer.content[0];
while(true) {
var firstContent = flowContainer.content[0];
if (firstContent instanceof Container)
flowContainer = firstContent;
else break;
}


// Any initial tag objects count as the "main tags" associated with that story/knot/stitch
var tags = null;

innerWeaveContainer.content.every(c => {
flowContainer.content.every(c => {
// var tag = c as Runtime.Tag;
var tag = c;
if (tag instanceof Tag) {
Expand Down
5 changes: 4 additions & 1 deletion engine/Tag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export class Tag{
import {Object as InkObject} from './Object';

export class Tag extends InkObject{
constructor(tagText){
super();
this._text = tagText.toString() || '';
}
get text(){
Expand Down
2 changes: 2 additions & 0 deletions test/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var rl = readline.createInterface({
var inkFile = fs.readFileSync(__dirname + '/stories/test.ink.json', 'UTF-8').replace(/^\uFEFF/, '');
var s = new Story(inkFile);

console.log(s.globalTags);

//console.log(s.BuildStringOfHierarchy());
//console.log(s.EvaluateFunction('describe_health', [50], true));

Expand Down

0 comments on commit 9b73a75

Please sign in to comment.