コード例 #1
0
        /// <summary>
        /// Register the supported by default ReferenceTypes
        /// </summary>
        static ReferenceManager()
        {
            Registry = new Dictionary<string, ReferenceType>();
            ReferenceType current;

            // ===== NOTE
            // As you may notice below, there are some "activeSafe" mappings.
            // The ScriptEngine knows how to handle an active object switch,
            // however this mapping is ONLY used under very specific Scope settings.
            // 
            // If a Scope's MissingObjectHandling is set to CreateNew, than the 
            // ActiveSafe mapping is used to create a new instance of the object type
            // when the scope is unable to find the object instance in itself or parent
            // scopes.
            // ===

            // Create Object Template
            current = new ReferenceType("ObjectTemplate", typeof(ObjectTemplate));
            current.Mappings.Add("create", ObjectTemplate.Create);
            current.Mappings.Add("activeSafe", ObjectTemplate.Create);
            AddType(current);

            // Create Weapon Template
            current = new ReferenceType("weaponTemplate", typeof(WeaponTemplate));
            current.Mappings.Add("create", WeaponTemplate.Create);
            current.Mappings.Add("activeSafe", WeaponTemplate.Create);
            AddType(current);

            // Create Ai Template
            current = new ReferenceType("aiTemplate", typeof(AiTemplate));
            current.Mappings.Add("create", AiTemplate.Create);
            AddType(current);

            // Create Ai Template Plugin
            current = new ReferenceType("aiTemplatePlugIn", typeof(AiTemplatePlugin));
            current.Mappings.Add("create", AiTemplatePlugin.Create);
            AddType(current);

            // Create Kit Template
            current = new ReferenceType("kitTemplate", typeof(KitTemplate));
            current.Mappings.Add("create", KitTemplate.Create);
            AddType(current);

            // Create Kit Template
            current = new ReferenceType("GeometryTemplate", typeof(GeometryTemplate));
            current.Mappings.Add("create", GeometryTemplate.Create);
            current.Mappings.Add("activeSafe", GeometryTemplate.Create);
            AddType(current);

            // Create Kit Template
            current = new ReferenceType("CollisionManager", typeof(CollisionManager));
            current.Mappings.Add("createTemplate", CollisionManager.Create);
            AddType(current);
        }
コード例 #2
0
 /// <summary>
 /// Removes the <see cref="ReferenceType"/> from the Registry
 /// </summary>
 public static bool RemoveType(ReferenceType type)
 {
     return Registry.Remove(type.Name);
 }
コード例 #3
0
 /// <summary>
 /// Adds a new <see cref="ReferenceType"/> to the registry
 /// </summary>
 /// <param name="type">The Reference to add</param>
 /// <exception cref="ArgumentException">
 /// Thrown when a ReferenceType with the same name already exists
 /// </exception>
 public static void AddType(ReferenceType type)
 {
     Registry.Add(type.Name, type);
 }
コード例 #4
0
 /// <summary>
 /// Removes the <see cref="ReferenceType"/> from the Registry
 /// </summary>
 public static bool RemoveType(ReferenceType type)
 {
     return(Registry.Remove(type.Name));
 }
コード例 #5
0
 /// <summary>
 /// Adds a new <see cref="ReferenceType"/> to the registry
 /// </summary>
 /// <param name="type">The Reference to add</param>
 /// <exception cref="ArgumentException">
 /// Thrown when a ReferenceType with the same name already exists
 /// </exception>
 public static void AddType(ReferenceType type)
 {
     Registry.Add(type.Name, type);
 }
コード例 #6
0
        /// <summary>
        /// Executes the the specified token on the specified scope
        /// </summary>
        /// <param name="token"></param>
        /// <param name="scope"></param>
        public static void ExecuteInScope(Token token, Scope scope)
        {
            // create properties
            ConFileObject currentObj;

            switch (token.Kind)
            {
            case TokenType.ObjectStart:
            case TokenType.ActiveSwitch:
                // Fetch our object
                if (token.Kind == TokenType.ActiveSwitch)
                {
                    // Fetch the object and Set as the active object
                    currentObj = scope.GetObject(token);
                    scope.SetActiveObject(currentObj);
                }
                else
                {
                    // Get our method
                    var Method = token.TokenArgs.ReferenceType.GetMethod(
                        token.TokenArgs.PropertyName
                        );

                    // Fetch our new working object.
                    currentObj = Method.Invoke(token);
                    scope.AddObject(currentObj, token);
                }

                // Add file entry?
                if (token.File != null)
                {
                    // see if the object exists in file
                    if (token.File.Entries.Contains(currentObj))
                    {
                        token.File.AddEntry(currentObj, token);
                    }
                }
                break;

            case TokenType.ObjectProperty:
                // Get the last used object
                ReferenceType type = token.TokenArgs.ReferenceType;
                currentObj = scope.GetActiveObject(type);

                // Make sure we have an object to work with and the object
                // reference matches our current working object
                if (currentObj == null)
                {
                    // If we are here, we have an issue...
                    string error = $"Failed to set property \"{token.TokenArgs.ReferenceType.Name}.\""
                                   + $"{token.TokenArgs.PropertyName}. No object reference set!";
                    Logger.Error(error, token.File, token.Position);
                    throw new ParseException(error, token);
                }

                // Let the object parse its own lines...
                try
                {
                    currentObj.Parse(token);
                }
                catch (Exception e)
                {
                    Logger.Error(e.Message, token.File, token.Position, e);
                    throw;
                }
                break;

            case TokenType.RemComment:
            case TokenType.BeginRem:
            case TokenType.IfStart:
            case TokenType.Run:
            case TokenType.Include:
                break;

            case TokenType.Constant:
            case TokenType.Variable:
                Expression exp = new Expression(token);
                scope.Expressions[exp.Name] = exp;
                break;

            case TokenType.None:
                // Throw error if the line is not empty
                if (!String.IsNullOrWhiteSpace(token.Value))
                {
                    string message = $"Unable to parse file entry \"{token.Value}\" on line {token.Position}";
                    Logger.Error(message, token.File, token.Position);
                    throw new ParseException(message, token);
                }
                break;
            }
        }