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 7, 2016
2 parents 198041a + d88f912 commit ed8cbf0
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 58 deletions.
36 changes: 19 additions & 17 deletions engine/Container.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {StringValue} from './Value';
import {StoryException} from './StoryException';
import {StringBuilder} from './StringBuilder';
import {Object as InkObject} from './Object';

export class Container extends InkObject{//also implements INamedContent. Not sure how to do it cleanly in JS.
Expand Down Expand Up @@ -210,28 +211,30 @@ export class Container extends InkObject{//also implements INamedContent. Not su
}
BuildStringOfHierarchy(sb, indentation, pointedObj){
if (arguments.length == 0){
return this.BuildStringOfHierarchy('', 0, null);
var sb = new StringBuilder();
this.BuildStringOfHierarchy(sb, 0, null);
return sb.toString();
}

function appendIndentation(){
var spacesPerIndent = 4;
for(var i = 0; i < spacesPerIndent*indentation; ++i) {
sb += " ";
sb.Append(" ");
}
}

appendIndentation();
sb += "[";
sb.Append("[");

if (this.hasValidName) {
sb += " (" + this.name + ")";
sb.AppendFormat(" ({0})", this.name);
}

if (this == pointedObj) {
sb += " <---";
sb.Append(" <---");
}

sb += "\n";
sb.AppendLine();

indentation++;

Expand All @@ -248,23 +251,23 @@ export class Container extends InkObject{//also implements INamedContent. Not su
} else {
appendIndentation();
if (obj instanceof StringValue) {
sb += "\"";
sb += obj.toString().replace("\n", "\\n");
sb += "\"";
sb.Append("\"");
sb.Append(obj.toString().replace("\n", "\\n"));
sb.Append("\"");
} else {
sb += obj.toString();
sb.Append(obj.toString());
}
}

if (i != this.content.length - 1) {
sb += ",";
sb.Append(",");
}

if ( !(obj instanceof Container) && obj == pointedObj ) {
sb += " <---";
sb.Append(" <---");
}

sb += "\n";
sb.AppendLine();
}


Expand All @@ -280,22 +283,21 @@ export class Container extends InkObject{//also implements INamedContent. Not su

if (Object.keys(onlyNamed).length > 0) {
appendIndentation();
sb += "\n";
sb += "-- named: --";
sb.AppendLine("-- named: --");

for (var key in onlyNamed){
if (!(onlyNamed[key] instanceof Container)) console.warn("Can only print out named Containers");

var container = onlyNamed[key];
container.BuildStringOfHierarchy(sb, indentation, pointedObj);
sb += "\n";
sb.Append("\n");
}
}


indentation--;

appendIndentation();
sb += "]";
sb.Append("]");
}
}
17 changes: 9 additions & 8 deletions engine/Divert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Path} from './Path';
import {PushPopType} from './PushPop';
import {StringBuilder} from './StringBuilder';
import {Object as InkObject} from './Object';

export class Divert extends InkObject{
Expand Down Expand Up @@ -84,7 +85,7 @@ export class Divert extends InkObject{
return "Divert(null)";
} else {

var sb = '';
var sb = new StringBuilder;

var targetStr = this.targetPath.toString();
// int? targetLineNum = DebugLineNumberOfPath (targetPath);
Expand All @@ -93,20 +94,20 @@ export class Divert extends InkObject{
targetStr = "line " + targetLineNum;
}

sb += "Divert";
sb.Append("Divert");
if (this.pushesToStack) {
if (this.stackPushType == PushPopType.Function) {
sb += " function";
sb.Append(" function");
} else {
sb += " tunnel";
sb.Append(" tunnel");
}
}

sb += " (";
sb += targetStr;
sb += ")";
sb.Append(" (");
sb.Append(targetStr);
sb.Append(")");

return sb;
return sb.toString();
}
}
}
12 changes: 12 additions & 0 deletions engine/JsonSerialisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {VariableReference} from './VariableReference';
import {VariableAssignment} from './VariableAssignment';
import {NativeFunctionCall} from './NativeFunctionCall';
import {Void} from './Void';
import {Tag} from './Tag';
import {Path} from './Path';
import {Choice} from './Choice';
import {Object as InkObject} from './Object';
Expand Down Expand Up @@ -223,6 +224,9 @@ export class JsonSerialisation{
varAss.isGlobal = isGlobalVar;
return varAss;
}
if (propValue = obj["#"]){
return new Tag(propValue.toString());
}

if (obj["originalChoicePath"] != null)
return this.JObjectToChoice(obj);
Expand Down Expand Up @@ -378,6 +382,14 @@ export class JsonSerialisation{
var voidObj = obj;
if (voidObj instanceof Void)
return "void";

// var tag = obj as Tag;
var tag = obj;
if (tag instanceof Tag) {
var jObj = {};
jObj["#"] = tag.text;
return jObj;
}

// Used when serialising save state only
// var choice = obj as Choice;
Expand Down
Loading

0 comments on commit ed8cbf0

Please sign in to comment.