Skip to content

Commit

Permalink
Merge pull request #1 from inkle/master
Browse files Browse the repository at this point in the history
Merge latest ink changes
  • Loading branch information
y-lohse authored Sep 16, 2016
2 parents 61cbed3 + 488a3e0 commit 17d2c35
Show file tree
Hide file tree
Showing 16 changed files with 584 additions and 130 deletions.
6 changes: 3 additions & 3 deletions ink-engine-runtime/CallStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Element(PushPopType type, Container container, int contentIndex, bool inE
public Element Copy()
{
var copy = new Element (this.type, this.currentContainer, this.currentContentIndex, this.inExpressionEvaluation);
copy.temporaryVariables = this.temporaryVariables;
copy.temporaryVariables = new Dictionary<string,Object>(this.temporaryVariables);
return copy;
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ public void PopThread()
if (canPopThread) {
_threads.Remove (currentThread);
} else {
Debug.Fail ("Can't pop thread");
throw new System.Exception("Can't pop thread");
}
}

Expand Down Expand Up @@ -280,7 +280,7 @@ public void Pop(PushPopType? type = null)
callStack.RemoveAt (callStack.Count - 1);
return;
} else {
Debug.Fail ("Mismatched push/pop in Callstack");
throw new System.Exception("Mismatched push/pop in Callstack");
}
}

Expand Down
12 changes: 12 additions & 0 deletions ink-engine-runtime/ControlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public enum CommandType
NoOp,
ChoiceCount,
TurnsSince,
Random,
SeedRandom,
VisitIndex,
SequenceShuffleIndex,
StartThread,
Expand Down Expand Up @@ -100,6 +102,16 @@ public static ControlCommand TurnsSince() {
return new ControlCommand(CommandType.TurnsSince);
}

public static ControlCommand Random ()
{
return new ControlCommand (CommandType.Random);
}

public static ControlCommand SeedRandom ()
{
return new ControlCommand (CommandType.SeedRandom);
}

public static ControlCommand VisitIndex() {
return new ControlCommand(CommandType.VisitIndex);
}
Expand Down
2 changes: 2 additions & 0 deletions ink-engine-runtime/JsonSerialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ static Json()
_controlCommandNames [(int)ControlCommand.CommandType.NoOp] = "nop";
_controlCommandNames [(int)ControlCommand.CommandType.ChoiceCount] = "choiceCnt";
_controlCommandNames [(int)ControlCommand.CommandType.TurnsSince] = "turns";
_controlCommandNames [(int)ControlCommand.CommandType.Random] = "rnd";
_controlCommandNames [(int)ControlCommand.CommandType.SeedRandom] = "srnd";
_controlCommandNames [(int)ControlCommand.CommandType.VisitIndex] = "visit";
_controlCommandNames [(int)ControlCommand.CommandType.SequenceShuffleIndex] = "seq";
_controlCommandNames [(int)ControlCommand.CommandType.StartThread] = "thread";
Expand Down
3 changes: 1 addition & 2 deletions ink-engine-runtime/Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ internal Path ConvertPathToRelative(Path globalPath)
for (int down = lastSharedPathCompIndex + 1; down < globalPath.components.Count; ++down)
newPathComps.Add (globalPath.components [down]);

var relativePath = new Path (newPathComps);
relativePath.isRelative = true;
var relativePath = new Path (newPathComps, relative:true);
return relativePath;
}

Expand Down
16 changes: 12 additions & 4 deletions ink-engine-runtime/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override int GetHashCode ()

public List<Component> components { get; private set; }

public bool isRelative { get; set; }
public bool isRelative { get; private set; }

public Component head
{
Expand Down Expand Up @@ -145,9 +145,10 @@ public Path(Component head, Path tail) : this()
components.AddRange (tail.components);
}

public Path(IEnumerable<Component> components) : this()
public Path(IEnumerable<Component> components, bool relative = false) : this()
{
this.components.AddRange (components);
this.isRelative = relative;
}

public Path(string componentsString) : this()
Expand Down Expand Up @@ -195,18 +196,25 @@ public string componentsString {
else
return compsStr;
}
set {
private set {
components.Clear ();

var componentsStr = value;

// Empty path, empty components
// (path is to root, like "/" in file system)
if (string.IsNullOrEmpty(componentsStr))
return;

// When components start with ".", it indicates a relative path, e.g.
// .^.^.hello.5
// is equivalent to file system style path:
// ../../hello/5
if (componentsStr [0] == '.') {
isRelative = true;
this.isRelative = true;
componentsStr = componentsStr.Substring (1);
} else {
this.isRelative = false;
}

var componentStrings = componentsStr.Split('.');
Expand Down
67 changes: 23 additions & 44 deletions ink-engine-runtime/SimpleJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,28 @@ object ReadObject ()
{
var currentChar = _text [_offset];

object obj = null;
switch (currentChar) {
case '{':
obj = ReadDictionary ();
break;
case '[':
obj = ReadArray ();
break;
case '"':
obj = ReadString ();
break;
default:
if (IsNumberChar(currentChar)) {
obj = ReadNumber ();
break;
}
if( currentChar == '{' )
return ReadDictionary ();

else if (currentChar == '[')
return ReadArray ();

if (TryRead ("true")) {
return true;
}
else if (currentChar == '"')
return ReadString ();

if (TryRead ("false")) {
return false;
}
else if (IsNumberChar(currentChar))
return ReadNumber ();

if (TryRead ("null")) {
return null;
}
else if (TryRead ("true"))
return true;

throw new System.Exception ("Unhandled object type in JSON: "+_text.Substring (_offset, 30));
}
else if (TryRead ("false"))
return false;

return obj;
else if (TryRead ("null"))
return null;

throw new System.Exception ("Unhandled object type in JSON: "+_text.Substring (_offset, 30));
}

Dictionary<string, object> ReadDictionary ()
Expand All @@ -91,6 +80,8 @@ Dictionary<string, object> ReadDictionary ()

do {

SkipWhitespace ();

// Key
var key = ReadString ();
Expect (key != null, "dictionary key");
Expand All @@ -111,14 +102,7 @@ Dictionary<string, object> ReadDictionary ()

SkipWhitespace ();

if (TryRead (",")) {
SkipWhitespace ();
continue;
} else {
break;
}

} while (true);
} while ( TryRead (",") );

Expect ("}");

Expand All @@ -139,6 +123,8 @@ List<object> ReadArray ()

do {

SkipWhitespace ();

// Value
var val = ReadObject ();

Expand All @@ -147,14 +133,7 @@ List<object> ReadArray ()

SkipWhitespace ();

if (TryRead (",")) {
SkipWhitespace ();
continue;
} else {
break;
}

} while (true);
} while (TryRead (","));

Expect ("]");

Expand Down
Loading

0 comments on commit 17d2c35

Please sign in to comment.