-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from exodrifter/refactor_compiler
* You can now add the enum argument `cant_skip` to the end of a pause statement to ignore advances until the pause ends * You can now add the enum argument `no_wait` to the end of an add or say statement to auto advance the dialog * Variable substitution with `{` and `}` in strings is now supported * The compiler no longer uses a tokenizer except when parsing expressions * Compiler errors are more specific and descriptive * The `Exodrifter.Rumor.Lang` namespace has been renamed to `Exodrifter.Rumor.Language` * All unit tests and examples are wrapped in a `UNITY_EDITOR` ifdef to make it easier to use this repository as a submodule in non-unity project * Bindings are no longer stored in `Rumor`; instead, it is now stored in `Bindings` * `Rumor.Run` has been renamed to `Rumor.Start` in order to match the language used in C# `Thread.Start` and Unity's `StartCoroutine` method to improve consistency
- Loading branch information
Showing
118 changed files
with
5,455 additions
and
3,030 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#if UNITY_EDITOR | ||
|
||
using Exodrifter.Rumor.Engine; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace Exodrifter.Rumor.Test.Engine | ||
{ | ||
/// <summary> | ||
/// Ensure function calls work as expected | ||
/// </summary> | ||
public class BindingsTest | ||
{ | ||
/// <summary> | ||
/// Check if <see cref="Action"/> bindings work. | ||
/// </summary> | ||
[Test] | ||
public void Action() | ||
{ | ||
var bindings = new Bindings(); | ||
|
||
bool a0 = false; | ||
bindings.Bind("a0", () => a0 = true); | ||
bindings.CallBinding("a0"); | ||
Assert.IsTrue(a0); | ||
|
||
int a1 = 0; | ||
bindings.Bind("a1", (int p1) => a1 = p1); | ||
bindings.CallBinding("a1", 1); | ||
Assert.AreEqual(1, a1); | ||
|
||
int a2 = 0; | ||
bindings.Bind("a2", (int p1, int p2) => { a1 = p1; a2 = p2; }); | ||
bindings.CallBinding("a2", 2, 3); | ||
Assert.AreEqual(2, a1); | ||
Assert.AreEqual(3, a2); | ||
|
||
int a3 = 0; | ||
bindings.Bind("a3", (int p1, int p2, int p3) => { | ||
a1 = p1; a2 = p2; a3 = p3; | ||
}); | ||
bindings.CallBinding("a3", 3, 4, 5); | ||
Assert.AreEqual(3, a1); | ||
Assert.AreEqual(4, a2); | ||
Assert.AreEqual(5, a3); | ||
|
||
int a4 = 0; | ||
bindings.Bind("a4", (int p1, int p2, int p3, int p4) => { | ||
a1 = p1; a2 = p2; a3 = p3; a4 = p4; | ||
}); | ||
bindings.CallBinding("a4", 4, 5, 6, 7); | ||
Assert.AreEqual(4, a1); | ||
Assert.AreEqual(5, a2); | ||
Assert.AreEqual(6, a3); | ||
Assert.AreEqual(7, a4); | ||
} | ||
|
||
/// <summary> | ||
/// Check if <see cref="Func"/> bindings work. | ||
/// </summary> | ||
[Test] | ||
public void Func() | ||
{ | ||
var bindings = new Bindings(); | ||
|
||
bindings.Bind("a0", () => { return true; }); | ||
var a0 = bindings.CallBinding("a0"); | ||
Assert.IsTrue((bool)a0); | ||
|
||
bindings.Bind("a1", (int p1) => { return p1; }); | ||
var a1 = bindings.CallBinding("a1", 1); | ||
Assert.AreEqual(1, a1); | ||
|
||
bindings.Bind("a2", (int p1, int p2) => { return p1 + p2; }); | ||
var a2 = bindings.CallBinding("a2", 1, 2); | ||
Assert.AreEqual(3, a2); | ||
|
||
bindings.Bind("a3", (int p1, int p2, int p3) => { | ||
return p1 + p2 + p3; | ||
}); | ||
var a3 = bindings.CallBinding("a3", 1, 2, 3); | ||
Assert.AreEqual(6, a3); | ||
|
||
bindings.Bind("a4", (int p1, int p2, int p3, int p4) => { | ||
return p1 + p2 + p3 + p4; | ||
}); | ||
var a4 = bindings.CallBinding("a4", 1, 2, 3, 5); | ||
Assert.AreEqual(11, a4); | ||
} | ||
|
||
[Test] | ||
public void CallUnmappedBinding() | ||
{ | ||
var bindings = new Bindings(); | ||
bindings.Bind("foo", () => { return true; }); | ||
|
||
Assert.Throws<InvalidOperationException>( | ||
() => bindings.CallBinding("bar") | ||
); | ||
} | ||
|
||
[Test] | ||
public void BindAgain() | ||
{ | ||
var bindings = new Bindings(); | ||
bindings.Bind("foo", () => { return true; }); | ||
|
||
Assert.Throws<InvalidOperationException>( | ||
() => bindings.Bind("foo", () => { return false; }) | ||
); | ||
} | ||
} | ||
} | ||
|
||
#endif |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#if UNITY_EDITOR | ||
|
||
using Exodrifter.Rumor.Engine; | ||
using NUnit.Framework; | ||
|
||
namespace Exodrifter.Rumor.Test.Engine | ||
{ | ||
/// <summary> | ||
/// Ensure Scope objects operate as expected. | ||
/// </summary> | ||
public class ScopeTest | ||
{ | ||
#region Events | ||
|
||
[Test] | ||
public void OnClearTest() | ||
{ | ||
var success = false; | ||
var scope = new Scope(); | ||
scope.OnSet += (name, value) => Assert.Fail(); | ||
scope.OnClear += () => | ||
{ | ||
success = true; | ||
}; | ||
|
||
scope.ClearVars(); | ||
Assert.IsTrue(success); | ||
} | ||
|
||
[Test] | ||
public void OnSetTest() | ||
{ | ||
var scope = new Scope(); | ||
scope.OnClear += () => Assert.Fail(); | ||
scope.OnSet += (name, value) => | ||
{ | ||
Assert.AreEqual("foo", name); | ||
Assert.IsTrue(value.IsBool()); | ||
Assert.IsTrue(value.AsBool()); | ||
}; | ||
|
||
scope.SetVar("foo", true); | ||
} | ||
|
||
#endregion | ||
|
||
#region Setters | ||
|
||
[Test] | ||
public void SetBoolTest() | ||
{ | ||
var scope = new Scope(); | ||
|
||
scope.SetVar("foo", true); | ||
Assert.IsTrue(scope.GetVar("foo").IsBool()); | ||
Assert.IsTrue(scope.GetVar("foo").AsBool()); | ||
|
||
scope.SetVar("foo", false); | ||
Assert.IsTrue(scope.GetVar("foo").IsBool()); | ||
Assert.IsFalse(scope.GetVar("foo").AsBool()); | ||
} | ||
|
||
[Test] | ||
public void SetIntTest() | ||
{ | ||
var scope = new Scope(); | ||
|
||
scope.SetVar("foo", 1); | ||
Assert.IsTrue(scope.GetVar("foo").IsInt()); | ||
Assert.AreEqual(1, scope.GetVar("foo").AsInt()); | ||
|
||
scope.SetVar("foo", -100); | ||
Assert.IsTrue(scope.GetVar("foo").IsInt()); | ||
Assert.AreEqual(-100, scope.GetVar("foo").AsInt()); | ||
} | ||
|
||
[Test] | ||
public void SetFloatTest() | ||
{ | ||
var scope = new Scope(); | ||
|
||
scope.SetVar("foo", 1.0f); | ||
Assert.IsTrue(scope.GetVar("foo").IsFloat()); | ||
Assert.AreEqual(1.0f, scope.GetVar("foo").AsFloat()); | ||
|
||
scope.SetVar("foo", -100.0f); | ||
Assert.IsTrue(scope.GetVar("foo").IsFloat()); | ||
Assert.AreEqual(-100.0f, scope.GetVar("foo").AsFloat()); | ||
} | ||
|
||
[Test] | ||
public void SetStringTest() | ||
{ | ||
var scope = new Scope(); | ||
|
||
scope.SetVar("foo", "bar"); | ||
Assert.IsTrue(scope.GetVar("foo").IsString()); | ||
Assert.AreEqual("bar", scope.GetVar("foo").AsString()); | ||
} | ||
|
||
[Test] | ||
public void SetObjectTest() | ||
{ | ||
var scope = new Scope(); | ||
|
||
var obj = new object(); | ||
scope.SetVar("foo", obj); | ||
Assert.IsTrue(scope.GetVar("foo").IsObject()); | ||
Assert.AreEqual(obj, scope.GetVar("foo").AsObject()); | ||
|
||
scope.SetVar("foo", (object)true); | ||
Assert.IsTrue(scope.GetVar("foo").IsBool()); | ||
Assert.IsTrue(scope.GetVar("foo").AsBool()); | ||
|
||
scope.SetVar("foo", (object)1); | ||
Assert.IsTrue(scope.GetVar("foo").IsInt()); | ||
Assert.AreEqual(1, scope.GetVar("foo").AsInt()); | ||
|
||
scope.SetVar("foo", (object)1.0f); | ||
Assert.IsTrue(scope.GetVar("foo").IsFloat()); | ||
Assert.AreEqual(1.0f, scope.GetVar("foo").AsFloat()); | ||
|
||
scope.SetVar("foo", (object)"bar"); | ||
Assert.IsTrue(scope.GetVar("foo").IsString()); | ||
Assert.AreEqual("bar", scope.GetVar("foo").AsString()); | ||
} | ||
|
||
#endregion | ||
} | ||
} | ||
|
||
#endif |
4 changes: 2 additions & 2 deletions
4
Editor/Tests/Lang/TokenizerTest.cs.meta → Editor/Tests/Engine/ScopeTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.