Ejemplo n.º 1
0
        public static void BuildCharIndex(string cachePattern)
        {
            CharaIndexNode fullGuide = new CharaIndexNode();
            string         search    = Path.GetDirectoryName(String.Format(cachePattern, '*'));
            string         pattern   = Path.GetFileName(String.Format(cachePattern, '*'));

            try
            {
                foreach (string dir in Directory.GetFiles(search, pattern))
                {
                    string file = Path.GetFileNameWithoutExtension(dir);
                    int    num  = Convert.ToInt32(file.Split('-')[1]);
                    using (FileStream stream = File.OpenRead(dir))
                    {
                        using (BinaryReader reader = new BinaryReader(stream))
                        {
                            CharaIndexNode speciesGuide = CharaIndexNode.Load(reader);
                            fullGuide.Nodes[num] = speciesGuide;
                        }
                    }
                }

                using (FileStream stream = new FileStream(search + "/index.idx", FileMode.Create, FileAccess.Write))
                {
                    using (BinaryWriter writer = new BinaryWriter(stream))
                        fullGuide.Save(writer);
                }
            }
            catch (Exception ex)
            {
                DiagManager.Instance.LogError(new Exception("Error importing index at " + search + "\n", ex));
            }
        }
Ejemplo n.º 2
0
        public static void SaveSpecies(string destinationPath, Dictionary <MonsterID, byte[]> spriteData)
        {
            if (spriteData.Count == 0)
            {
                DiagManager.Instance.LogInfo("Skipped data for " + Path.GetFullPath(destinationPath));
                return;
            }

            //generate formtree
            CharaIndexNode guide = new CharaIndexNode();
            Dictionary <MonsterID, long> spritePositions = new Dictionary <MonsterID, long>();
            long currentPosition = 0;

            foreach (MonsterID key in spriteData.Keys)
            {
                spritePositions[key] = currentPosition;
                currentPosition     += spriteData[key].LongLength;
            }
            foreach (MonsterID key in spritePositions.Keys)
            {
                guide.AddSubValue(0, key.Form, key.Skin, (int)key.Gender);
            }

            using (FileStream stream = new FileStream(destinationPath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    //save the guide
                    guide.Save(writer);

                    //update how much space it takes
                    foreach (MonsterID key in spritePositions.Keys)
                    {
                        guide.AddSubValue(spritePositions[key] + writer.BaseStream.Position, key.Form, key.Skin, (int)key.Gender);
                    }

                    //save it again
                    writer.Seek(0, SeekOrigin.Begin);
                    guide.Save(writer);

                    //save data
                    foreach (byte[] formData in spriteData.Values)
                    {
                        writer.Write(formData);
                    }
                }
            }
            DiagManager.Instance.LogInfo("Wrote data to " + Path.GetFullPath(destinationPath));
        }
Ejemplo n.º 3
0
        private Dictionary <MonsterID, byte[]> LoadSpeciesData(int num)
        {
            Dictionary <MonsterID, byte[]> dict = new Dictionary <MonsterID, byte[]>();

            MonsterData    dex       = DataManager.Instance.GetMonster(num);
            CharaIndexNode charaNode = GetIndexNode();

            if (charaNode.Nodes.ContainsKey(num))
            {
                if (charaNode.Nodes[num].Position > 0)
                {
                    LoadSpeciesFormData(dict, new MonsterID(num, -1, -1, Gender.Unknown));
                }

                foreach (int form in charaNode.Nodes[num].Nodes.Keys)
                {
                    if (charaNode.Nodes[num].Nodes[form].Position > 0)
                    {
                        LoadSpeciesFormData(dict, new MonsterID(num, form, -1, Gender.Unknown));
                    }

                    foreach (int skin in charaNode.Nodes[num].Nodes[form].Nodes.Keys)
                    {
                        if (charaNode.Nodes[num].Nodes[form].Nodes[skin].Position > 0)
                        {
                            LoadSpeciesFormData(dict, new MonsterID(num, form, skin, Gender.Unknown));
                        }

                        foreach (int gender in charaNode.Nodes[num].Nodes[form].Nodes[skin].Nodes.Keys)
                        {
                            if (charaNode.Nodes[num].Nodes[form].Nodes[skin].Nodes[gender].Position > 0)
                            {
                                LoadSpeciesFormData(dict, new MonsterID(num, form, skin, (Gender)gender));
                            }
                        }
                    }
                }
            }

            return(dict);
        }
Ejemplo n.º 4
0
        public void LoadFormDataEntries(bool checkSprites)
        {
            this.checkSprites = checkSprites;
            this.Text         = checkSprites ? "Char Sheets" : "Portraits";

            CharaIndexNode charaNode = GetIndexNode();

            for (int ii = 0; ii < DataManager.Instance.DataIndices[DataManager.DataType.Monster].Count; ii++)
            {
                FormEntrySummary dex = (FormEntrySummary)DataManager.Instance.DataIndices[DataManager.DataType.Monster].Entries[ii];

                TreeNode node = new TreeNode("#" + ii.ToString() + ": " + dex.Name.ToLocal(), 0, 0);
                node.Tag = new MonsterID(ii, -1, -1, Gender.Unknown);
                for (int jj = 0; jj < dex.FormTexts.Count; jj++)
                {
                    TreeNode formNode = new TreeNode("Form" + jj.ToString() + ": " + dex.FormTexts[jj].ToLocal(), 0, 0);
                    formNode.Tag = new MonsterID(ii, jj, -1, Gender.Unknown);

                    for (int kk = 0; kk < DataManager.Instance.DataIndices[DataManager.DataType.Skin].Count; kk++)
                    {
                        SkinData skinData = DataManager.Instance.GetSkin(kk);
                        if (!skinData.Challenge)
                        {
                            TreeNode skinNode = new TreeNode(skinData.Name.ToLocal(), 0, 0);
                            skinNode.Tag = new MonsterID(ii, jj, kk, Gender.Unknown);
                            for (int mm = 0; mm < 3; mm++)
                            {
                                TreeNode genderNode = new TreeNode(((Gender)mm).ToString(), 0, 0);
                                genderNode.Tag = new MonsterID(ii, jj, kk, (Gender)mm);
                                skinNode.Nodes.Add(genderNode);
                            }

                            formNode.Nodes.Add(skinNode);
                        }
                    }

                    node.Nodes.Add(formNode);
                }

                try
                {
                    if (charaNode.Nodes.ContainsKey(ii))
                    {
                        if (charaNode.Nodes[ii].Position > 0)
                        {
                            node.ImageIndex         = 1;
                            node.SelectedImageIndex = 1;
                        }

                        foreach (int form in charaNode.Nodes[ii].Nodes.Keys)
                        {
                            if (charaNode.Nodes[ii].Nodes[form].Position > 0)
                            {
                                node.Nodes[form].ImageIndex         = 1;
                                node.Nodes[form].SelectedImageIndex = 1;
                            }

                            foreach (int skin in charaNode.Nodes[ii].Nodes[form].Nodes.Keys)
                            {
                                if (charaNode.Nodes[ii].Nodes[form].Nodes[skin].Position > 0)
                                {
                                    node.Nodes[form].Nodes[skin].ImageIndex         = 1;
                                    node.Nodes[form].Nodes[skin].SelectedImageIndex = 1;
                                }


                                foreach (int gender in charaNode.Nodes[ii].Nodes[form].Nodes[skin].Nodes.Keys)
                                {
                                    if (charaNode.Nodes[ii].Nodes[form].Nodes[skin].Nodes[gender].Position > 0)
                                    {
                                        node.Nodes[form].Nodes[skin].Nodes[gender].ImageIndex         = 1;
                                        node.Nodes[form].Nodes[skin].Nodes[gender].SelectedImageIndex = 1;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    DiagManager.Instance.LogError(ex);
                }

                tvForms.Nodes.Add(node);
            }
        }