/// <summary>
        /// Constructor for item creation
        /// </summary>
        public ItemEditorViewModell(IFactorioLogic logic, Window window)
        {
            init(logic, window);

            m_item      = new FactorioItem();
            m_itemDummy = new FactorioItem(-1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create new ProductionView for an <see cref="FactorioItem"/>
        /// </summary>
        public ProductionViewerViewModell(FactorioItem item)
        {
            m_factorioAssembly = new FactorioAssembly(item);
            m_PVLogic          = new PVTreeStructure(m_factorioAssembly);

            m_factorioItemContainers = m_PVLogic.FactorioItemContainers;
            m_lines = m_PVLogic.Lines;
        }
        /// <summary>
        /// Initializer for constructors
        /// </summary>
        /// <param name="logic"></param>
        /// <param name="window"></param>
        private void init(IFactorioLogic logic, Window window)
        {
            this.m_fLogic        = logic;
            this.m_currentWindow = window;

            // Select default recipe item
            if (m_fLogic.Items.Count > 0)
            {
                SelectedComboBoxRecipeItem = m_fLogic.Items[0];
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Remove an item and save Items list to xml file
        /// </summary>
        /// <param name="item"></param>
        public void RemoveItem(FactorioItem item)
        {
            this.Items.Remove(item);

            foreach (var i in this.Items)
            {
                i.RemoveRecipeItem(item);
            }

            this.SaveItems();
        }
        /// <summary>
        /// Constructor for item editing
        /// </summary>
        /// <param name="logic"></param>
        /// <param name="window"></param>
        /// <param name="item"></param>
        public ItemEditorViewModell(IFactorioLogic logic, Window window, FactorioItem item)
        {
            init(logic, window);

            this.Title            = "Edit item";
            this.TxtItemName      = item.Name;
            this.TxtItemOutput    = item.CraftingOutput.ToString();
            this.TxtItemTime      = item.CraftingTime.ToString();
            this.SelectedCrafting = item.DefaultCraftingType.ToString();
            this.PicturePath      = item.ImagePath;

            this.m_item      = item;
            this.m_itemDummy = item.GetCopy();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create new <see cref="FactorioItem"/> from data in the XElement
        /// </summary>
        /// <param name="xmlData">Xml data for the item</param>
        /// <returns>New <see cref="FactorioItem"/></returns>
        public static FactorioItem GetFactorioItemFromXmlData(XElement xmlData, List <FactorioItem> knownItems, List <FactorioItem> unknownItems)
        {
            FactorioItem item;

            try
            {
                int id = Convert.ToInt32(xmlData.Attribute(XmlItemAttributeId).Value);

                if (unknownItems.Exists(i => i.Id == id))
                {
                    item = unknownItems.Find(i => i.Id == id);

                    item.Name                = xmlData.Attribute(XmlItemAttributeName).Value;
                    item.CraftingOutput      = Convert.ToInt32(xmlData.Attribute(XmlItemAttributeOutput).Value);
                    item.CraftingTime        = Convert.ToDouble(xmlData.Attribute(XmlItemAttributeTime).Value);
                    item.DefaultCraftingType = (CraftingType)Enum.Parse(typeof(CraftingType), xmlData.Attribute(XmlItemAttributeCraftingStation).Value);
                    item.ImagePath           = xmlData.Attribute(XmlItemAttributePicture).Value;

                    unknownItems.Remove(item);
                }
                else
                {
                    item = new FactorioItem(id)
                    {
                        Name                = xmlData.Attribute(XmlItemAttributeName).Value,
                        CraftingOutput      = Convert.ToInt32(xmlData.Attribute(XmlItemAttributeOutput).Value),
                        CraftingTime        = Convert.ToDouble(xmlData.Attribute(XmlItemAttributeTime).Value),
                        DefaultCraftingType = (CraftingType)Enum.Parse(typeof(CraftingType), xmlData.Attribute(XmlItemAttributeCraftingStation).Value),
                    };

                    if (xmlData.Attribute(XmlItemAttributePicture) != null)
                    {
                        item.ImagePath = xmlData.Attribute(XmlItemAttributePicture).Value;
                    }
                }

                if (FactorioXmlHelper.IsImagePathValid(item.ImagePath) == false)
                {
                    item.ImagePath = String.Empty;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(item);
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="assemblyItem"></param>
        public FactorioAssembly(FactorioItem assemblyItem)
        {
            AssemblyItem = assemblyItem;

            Quantity = 1;

            if (assemblyItem.Recipe == null)
            {
                return;
            }

            foreach (var item in assemblyItem.Recipe)
            {
                SubAssembly.Add(new FactorioAssembly(item.Key, this, item.Value));
            }
        }
        /// <summary>
        /// Constructor for subassemblies
        /// </summary>
        /// <param name="assemblyItem"></param>
        /// <param name="topAssembly"></param>
        /// <param name="quantity"></param>
        public FactorioAssembly(FactorioItem assemblyItem, FactorioAssembly topAssembly, int quantity)
        {
            AssemblyItem = assemblyItem;

            ItemQuantity = quantity;

            m_topAssembly = topAssembly;

            Quantity = (quantity * ((topAssembly.Quantity * topAssembly.AssemblyItem.Productivity)) / (assemblyItem.Productivity * topAssembly.AssemblyItem.CraftingOutput));

            Quantity *= topAssembly.CraftingSpeed / CraftingSpeed;

            if (assemblyItem.Recipe != null)
            {
                foreach (var item in assemblyItem.Recipe)
                {
                    SubAssembly.Add(new FactorioAssembly(item.Key, this, item.Value));
                }
            }
        }
Ejemplo n.º 9
0
        public ObservableCollection <FactorioItem> ReadItems(string path)
        {
            // Contains all items that are currently known
            var knownItems = new List <FactorioItem>();

            // Contains items that are found in recipes but aren't loaded yet
            var unknownItems = new List <FactorioItem>();

            try
            {
                // Check if file exists, create one if it doesn't
                if (!File.Exists(path))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    FactorioXmlHelper.CreateXml(path, XmlMainElement);
                }

                XDocument itemsFile = XDocument.Load(path);

                foreach (var xmlItemData in itemsFile.Descendants(XmlItemElement))
                {
                    FactorioItem newItem = GetFactorioItemFromXmlData(xmlItemData, knownItems, unknownItems);

                    knownItems.Add(newItem);

                    TryAddRecipeData(newItem, xmlItemData, knownItems, unknownItems);
                }
            }
            catch (FactorioException)
            {
                // pass through
                throw;
            }
            catch (Exception ex)
            {
                // create a new exception to add the event code
                throw new FactorioException(DiagnosticEvents.DalXmlRead, "An error occurred while reading a xml file with the message: " + ex.Message, ex);
            }

            return(new ObservableCollection <FactorioItem>(knownItems));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Try to add a recipe to the this <see cref="FactorioItem"/>
        /// </summary>
        /// <param name="item">Item to add reipe for</param>
        /// <param name="xmlData">Xml data for this item</param>
        /// <param name="knownItems">List of all known items</param>
        /// <param name="unknownItems">List of all unkown items</param>
        public static void TryAddRecipeData(FactorioItem item, XElement xmlData, List <FactorioItem> knownItems, List <FactorioItem> unknownItems)
        {
            if (xmlData.Descendants(XmlCraftingElement).FirstOrDefault() != null)
            {
                try
                {
                    // Get a list of all recipe parts of XElement
                    var recipes = xmlData.Descendants(XmlCraftingElement);

                    foreach (var recipe in recipes)
                    {
                        // Id of the recipe item
                        int id = Convert.ToInt32(recipe.Attribute(XmlCraftingAttributeId).Value);

                        // Quantity of the recipe item
                        int quantity = Convert.ToInt32(recipe.Attribute(XmlCraftingAttributeQuantity).Value);

                        // Look for a known item with id of the recipe item
                        FactorioItem recipeItem = knownItems.Find(i => i.Id == id);

                        if (recipeItem != null)
                        {
                            item.AddRecipeItem(recipeItem, quantity);
                        }
                        // If the recipe item is not known create a dummy item with its id and add it to unkown items
                        else if (unknownItems.Exists(i => i.Id == id) == false)
                        {
                            recipeItem = new FactorioItem(id);

                            unknownItems.Add(recipeItem);

                            item.AddRecipeItem(recipeItem, quantity);
                        }
                    }
                }
                catch (FormatException)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Add this object to the <see cref="writer"/>.
        /// </summary>
        /// <param name="writer"></param>
        public static void WriteItemXml(FactorioItem item, XmlWriter writer)
        {
            writer.WriteAttributeString(XmlItemAttributeId, item.Id.ToString());
            writer.WriteAttributeString(XmlItemAttributeName, item.Name);
            writer.WriteAttributeString(XmlItemAttributeOutput, item.CraftingOutput.ToString());
            writer.WriteAttributeString(XmlItemAttributeTime, item.CraftingTime.ToString());
            writer.WriteAttributeString(XmlItemAttributeCraftingStation, item.DefaultCraftingType.ToString());

            if (item.ImagePath != null)
            {
                writer.WriteAttributeString(XmlItemAttributePicture, item.ImagePath);
            }

            if (item.Recipe != null)
            {
                foreach (var craft in item.Recipe)
                {
                    writer.WriteStartElement(XmlCraftingElement);
                    writer.WriteAttributeString(XmlCraftingAttributeId, craft.Key.Id.ToString());
                    writer.WriteAttributeString(XmlCraftingAttributeQuantity, craft.Value.ToString());
                    writer.WriteEndElement();
                }
            }
        }
Ejemplo n.º 12
0
 public void RemoveRecipe(FactorioItem item, FactorioItem recipeItem)
 {
     item.RemoveRecipeItem(recipeItem);
 }
        public ItemEditorWindow(IFactorioLogic logic, FactorioItem item)
        {
            InitializeComponent();

            this.DataContext = new ItemEditorViewModell(logic, this, item);
        }
        public ProductionViewerWindow(IFactorioLogic logic, FactorioItem item)
        {
            InitializeComponent();

            this.DataContext = new ProductionViewerViewModell(item);
        }
Ejemplo n.º 15
0
 public ItemDetailViewModell(FactorioItem item)
 {
     Item = item;
 }
Ejemplo n.º 16
0
 public void AddRecipe(FactorioItem item, int quantity, FactorioItem recipeItem)
 {
     item.AddRecipeItem(recipeItem, quantity);
 }
Ejemplo n.º 17
0
        public ItemDetailWindow(FactorioItem item)
        {
            InitializeComponent();

            this.DataContext = new ItemDetailViewModell(item);
        }