X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FScript.cs;h=0cf9dbdbd56c5e22e4145ed37a05506ac1cbaef6;hp=146bb22685249cf7db7449c521a1cbe644aef819;hb=08f41ef45f3c41ca6302150bc6d5270c8e7143db;hpb=d167160264cd2c33de81a71039eddbb959c40bb2
diff --git a/CarFire/CarFire/CarFire/Script.cs b/CarFire/CarFire/CarFire/Script.cs
index 146bb22..0cf9dbd 100644
--- a/CarFire/CarFire/CarFire/Script.cs
+++ b/CarFire/CarFire/CarFire/Script.cs
@@ -7,10 +7,17 @@ using System.Diagnostics;
namespace CarFire
{
+ ///
+ /// The Script class handles the parsing and execution of lists
+ /// of functions. Scripts are closely related to triggers.
+ ///
public class Script
{
#region Public Properties
+ ///
+ /// Determine if the script is in the process of being run.
+ ///
public bool IsRunning { get { return mIsRunning; } }
#endregion
@@ -18,9 +25,14 @@ namespace CarFire
#region Public Methods
- public Script(string code, Game game)
+ ///
+ /// Construct a script object with code and a game reference.
+ ///
+ /// The script code.
+ /// A game reference.
+ public Script(string code, object bindings)
{
- mGame = game;
+ mBindings = bindings;
string[] functions = Parse.List(code);
if (functions != null)
@@ -44,6 +56,17 @@ namespace CarFire
else throw new Exception("Script could not be parsed: " + code);
}
+ ///
+ /// Start execution of the script. If there is no need to break
+ /// execution before the script ends, it will finish before this method
+ /// call ends. Otherwise, execution will be delayed and will finish sometime
+ /// in the future. This will execute each function in sequence as long
+ /// as each function evaluates to true. If a function does not evaluate to true,
+ /// this method will return and execution will be delayed. In either case,
+ /// the evaluation of the last function is returned by this method.
+ ///
+ /// The player associated with this script.
+ /// Evaluation of the last function call.
public bool Run(Player player)
{
bool result = false;
@@ -64,11 +87,23 @@ namespace CarFire
return result;
}
+ public void Reset()
+ {
+ mIsRunning = false;
+
+ }
+
#endregion
#region Private Methods
+ ///
+ /// Call a function in the last at a certain index.
+ ///
+ /// The function index.
+ /// The associated player object.
+ /// The evaluation of the function.
bool Call(int index, Player player)
{
Debug.Assert(0 <= index && index < mFunctions.Count);
@@ -77,7 +112,7 @@ namespace CarFire
object[] args = new object[2];
args[0] = player;
args[1] = mFunctions[index].Arguments;
- return (bool)typeof(Impl).InvokeMember(mFunctions[index].Name, BindingFlags.InvokeMethod, null, null, args);
+ return (bool)mBindings.GetType().InvokeMember(mFunctions[index].Name, BindingFlags.InvokeMethod, null, mBindings, args);
}
#pragma warning disable 0168
catch (System.MissingMethodException ex)
@@ -92,34 +127,6 @@ namespace CarFire
#region Private Types
- class Impl
- {
- public static bool True(Player player, string[] args)
- {
- return true;
- }
-
- public static bool False(Player player, string[] args)
- {
- return false;
- }
-
- public static bool Has(Player player, string[] args)
- {
- return false;
- }
-
- public static bool Print(Player player, string[] args)
- {
- foreach (string arg in args)
- {
- string line = Parse.String(arg);
- if (line != null) Console.WriteLine(line);
- }
- return true;
- }
- }
-
class Function
{
public string Name { get { return mName; } }
@@ -140,11 +147,10 @@ namespace CarFire
#region Private Variables
- Game mGame;
+ object mBindings;
List mFunctions = new List();
bool mIsRunning;
int mRunningIndex;
- Impl mImpl = new Impl();
#endregion
}