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 30, 2016
2 parents aa42152 + 3ff3285 commit 4783700
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion engine/NativeFunctionCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class NativeFunctionCall extends InkObject{
this.AddIntBinaryOp(this.Add, (x, y) => {return x + y});
this.AddIntBinaryOp(this.Subtract, (x, y) => {return x - y});
this.AddIntBinaryOp(this.Multiply, (x, y) => {return x * y});
this.AddIntBinaryOp(this.Divide, (x, y) => {return x / y});
this.AddIntBinaryOp(this.Divide, (x, y) => {return parseInt(x / y)});
this.AddIntBinaryOp(this.Mod, (x, y) => {return x % y});
this.AddIntUnaryOp(this.Negate, x => {return -x});

Expand Down
12 changes: 1 addition & 11 deletions engine/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,22 +1058,12 @@ export class Story extends InkObject{

// Error for all missing externals
else {
var message = "Missing function binding for external";
var message = "Error: 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);
}
Expand Down
46 changes: 36 additions & 10 deletions engine/StoryState.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@ export class StoryState{
});
}

MatchRightGlueForLeftGlue(leftGlue){
if (!leftGlue.isLeft) return null;

for (var i = this._outputStream.length - 1; i >= 0; i--) {
var c = this._outputStream[i];
// var g = c as Glue;
var g = c;
if (g instanceof Glue && g.isRight && g.parent == leftGlue.parent) {
return g;
} else if (c instanceof ControlCommand) // e.g. BeginString
break;
}

return null;
}
GoToStart(){
this.callStack.currentElement.currentContainer = this.story.mainContentContainer;
this.callStack.currentElement.currentContentIndex = 0;
Expand Down Expand Up @@ -410,12 +425,16 @@ export class StoryState{
// Found matching left-glue for right-glue? Close it.
var existingRightGlue = this.currentRightGlue;
var foundMatchingLeftGlue = !!(glue.isLeft && existingRightGlue && glue.parent == existingRightGlue.parent);
var matchingRightGlue = null;

if (glue.isLeft)
matchingRightGlue = this.MatchRightGlueForLeftGlue(glue);

// Left/Right glue is auto-generated for inline expressions
// where we want to absorb newlines but only in a certain direction.
// "Bi" glue is written by the user in their ink with <>
if (glue.isLeft || glue.isBi) {
this.TrimNewlinesFromOutputStream(foundMatchingLeftGlue);
this.TrimNewlinesFromOutputStream(matchingRightGlue);
}

includeInOutput = glue.isBi || glue.isRight;
Expand Down Expand Up @@ -447,7 +466,7 @@ export class StoryState{
this._outputStream.push(obj);
}
}
TrimNewlinesFromOutputStream(stopAndRemoveRightGlue){
TrimNewlinesFromOutputStream(rightGlueToStopAt){
var removeWhitespaceFrom = -1;
var rightGluePos = -1;
var foundNonWhitespace = false;
Expand All @@ -468,9 +487,9 @@ export class StoryState{

if (cmd instanceof ControlCommand || (txt instanceof StringValue && txt.isNonWhitespace)) {
foundNonWhitespace = true;
if( !stopAndRemoveRightGlue )
if( rightGlueToStopAt == null )
break;
} else if (stopAndRemoveRightGlue && glue instanceof Glue && glue.isRight) {
} else if (rightGlueToStopAt && glue instanceof Glue && glue == rightGlueToStopAt) {
rightGluePos = i;
break;
} else if (txt instanceof StringValue && txt.isNewline && !foundNonWhitespace) {
Expand All @@ -493,10 +512,16 @@ export class StoryState{
}
}

// Remove the glue (it will come before the whitespace,
// so index is still valid)
if (stopAndRemoveRightGlue && rightGluePos > -1)
this._outputStream.splice(rightGluePos, 1);
if (rightGlueToStopAt && rightGluePos > -1) {
i = rightGluePos;
while(i < this._outputStream.length) {
if (this._outputStream[i] instanceof Glue && (this._outputStream[i]).isRight) {
this.outputStream.splice(i, 1);
} else {
i++;
}
}
}
}
TrimFromExistingGlue(){
var i = this.currentGlueIndex;
Expand All @@ -520,15 +545,16 @@ export class StoryState{
}
}
ForceEnd(){
this.currentContentObject = null;

while (this.callStack.canPopThread)
this.callStack.PopThread();

while (this.callStack.canPop)
this.callStack.Pop();

this.currentChoices.length = 0;

this.currentContentObject = null;
this.previousContentObject = null;

this.didSafeExit = true;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inkjs",
"version": "1.4.2",
"version": "1.4.3",
"description": "A javascript port of inkle's ink scripting language (http://www.inklestudios.com/ink/)",
"main": "dist/ink-es2015.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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.globalTags);

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

0 comments on commit 4783700

Please sign in to comment.