Beispiel #1
0
 // Create a cycle directive for this
 private string ConstructCycleDirective(Loadable loadable)
 {
     if (loadable.SpawningCycles.Count > 0)
     {
         string line = "@cycle ";
         loadable.SpawningCycles.ForEach(x => line = line + x.ToString() + " ");
         return(line + "\n");
     }
     else
     {
         return("@immediate\n");
     }
 }
Beispiel #2
0
        // Remove a loadable
        public void RemoveLoadable(Loadable loadable)
        {
            Loadables.Remove(loadable);

            if (loadable is EntityDefinition)
            {
                EntityDefinition ent = (EntityDefinition)loadable;
                // Remove existing elements
                foreach (var enemy in ent.Instances)
                {
                    this.entities.Remove(enemy);
                }
            }
        }
Beispiel #3
0
 // Add new loadable to loadables
 public void AddLoadable(Loadable loadable)
 {
     Loadables.Add(loadable);
 }
Beispiel #4
0
        // Loads level
        public void LoadLevel()
        {
            // Reset loadables
            Loadables.Clear();

            // Get level's load table
            var loadTable = GetExpandedLevelLoadTable().Split('\n');

            // Variables used in parsing
            List <int> cycles = new List <int>();

            // Current Entity definition being worked on
            Loadable loadable = null;

            // Current component
            Component component = null;

            foreach (string line in loadTable)
            {
                var vec = line.Split(' ');

                // Look for starting cycle
                if (line.StartsWith("@cycle") || line.StartsWith("@immediate"))
                {
                    // Clear old loadable
                    loadable = null;
                    cycles.Clear();
                    for (int i = 1; i < vec.Length; i++)
                    {
                        cycles.Add(Int32.Parse(vec[i]));
                    }
                }

                // Look for an ent declaration
                else if (line.StartsWith("ent"))
                {
                    // Generate new entities
                    loadable = new EntityDefinition(cycles);
                    Loadables.Add(loadable);
                }

                // Sets flags on which component to update
                else if (line.StartsWith("+"))
                {
                    string   name       = line.Substring(1).Split(' ')[0];
                    string[] parameters = line.Split(' ').Skip(1).ToArray();

                    component = Component.TranslateToComponentType(name);
                    if (component is Object)
                    {
                        component.Initialise(parameters, (EntityDefinition)loadable);
                        ((EntityDefinition)loadable).AddComponent(name, component);
                    }
                }

                // Conduct update to component
                else if (line.StartsWith("->"))
                {
                    if (component is Object)
                    {
                        component.UpdateEntity(line, (EntityDefinition)loadable);
                    }
                }

                // Update script
                else if (line.StartsWith("<<"))
                {
                    // Either extend or generate new script
                    if (!(loadable is Script))
                    {
                        loadable = new Script(cycles);
                        Loadables.Add(loadable);
                    }
                    ((Script)loadable).Extend(line.Substring(2));
                }

                // Add a template
                else if (line.StartsWith("#"))
                {
                    // Look up template
                    string        templateName = line.Substring(1).Split(' ')[0];
                    List <string> parameters   = line.Substring(1).Split(' ').Skip(1).ToList();

                    if (Templates.ContainsKey(templateName))
                    {
                        var template = Templates[templateName];
                        ((EntityDefinition)loadable).AddTemplate(template, parameters);
                    }
                }
            }

            EvaluateEntities();
        }