Exemplo n.º 1
0
 /// <summary>
 /// Called every time the simulation is advanced.
 /// </summary>
 public virtual void Advance()
 {
     Console.WriteLine("Advance!");
     Time += 1;
     VariableManager.SetVariable("time", FormattedTime);
     CustomComponents.Advance();
 }
 /// <summary>
 /// Register a custom component
 /// </summary>
 /// <typeparam name="TComponent">Type implementing IComponent</typeparam>
 /// <param name="name"></param>
 public void RegisterComponent <TComponent>(string name)
     where TComponent : IComponent
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     CustomComponents.Add(name, typeof(TComponent));
 }
 /// <summary>
 /// Register a custom component
 /// </summary>
 /// <param name="name"></param>
 /// <param name="component"></param>
 public void RegisterComponent(string name, Type component)
 {
     if (!component.GetInterfaces().Contains(typeof(IComponent)))
     {
         throw new ArgumentException(nameof(component), $"Type must implement IComponent");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     CustomComponents.Add(name, component);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Loads the currently selected mod.
        /// </summary>
        protected virtual void LoadMod()
        {
            TypeManager.Load();
            GameInfo.Load();
            TextureManager.Load();
            FontManager.Load();
            GameScreenManager.Load();
            GuiManager.Load();
            ScriptManager.Load();

            CustomComponents.Add(VariableManager.Id, VariableManager);

            // Load all the custom components - note that the instancing of the components occurs earlier, in GameInfo.Load
            CustomComponents.Load();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads the specified save game.
        /// </summary>
        /// <param name="fileName">The Xml document of the save game.</param>
        protected virtual void LoadGame(XmlDocument doc)
        {
            foreach (XmlNode node in doc.SelectSingleNode("FDRFile/CustomComponents").ChildNodes)
            {
                if (node is XmlElement)
                {
                    var el = node as XmlElement;

                    if (CustomComponents.ContainsKey(el.Name))
                    {
                        var bsc = CustomComponents[el.Name] as IBlackbirdSavegameComponent;

                        if (bsc != null)
                        {
                            bsc.LoadGame(el);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads the specified save game.
        /// </summary>
        /// <param name="fileName">The Xml document of the save game.</param>
        protected virtual void SaveGame(XmlDocument doc)
        {
            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", "yes"));

            XmlElement root;

            doc.AppendChild(root = doc.CreateElement("FDRFile"));

            root.Attributes.Append(doc.CreateAttributeWithValue("version", "0.1"));
            root.Attributes.Append(doc.CreateAttributeWithValue("type", "save"));

            XmlElement components = doc.CreateElement("CustomComponents");

            root.AppendChild(components);

            foreach (var component in CustomComponents.Select(i => i.Value).OfType <IBlackbirdSavegameComponent>())
            {
                var el = doc.CreateElement(component.Id);
                components.AppendChild(el);

                component.SaveGame(el);
            }
        }