X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FScript.cs;h=9676bbb83e62d07b36067d59d9f6dbdd4a137b16;hp=146bb22685249cf7db7449c521a1cbe644aef819;hb=fc34f843ea42a3496a7ff5dd04853695ba628e8b;hpb=b5eebc2087c00bb67b3a3b9ddcec4743aa7a8cdb diff --git a/CarFire/CarFire/CarFire/Script.cs b/CarFire/CarFire/CarFire/Script.cs index 146bb22..9676bbb 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 + /// + /// Construct a script object with code and a game reference. + /// + /// The script code. + /// A game reference. public Script(string code, Game game) { - mGame = game; + mImpl = new Impl(game); 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; @@ -69,6 +92,12 @@ namespace CarFire #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); @@ -118,6 +147,14 @@ namespace CarFire } return true; } + + + public Impl(Game game) + { + mGame = game; + } + + Game mGame; } class Function @@ -140,11 +177,10 @@ namespace CarFire #region Private Variables - Game mGame; + Impl mImpl; List mFunctions = new List(); bool mIsRunning; int mRunningIndex; - Impl mImpl = new Impl(); #endregion }