Пример #1
0
        public string GetSpecialtyBuilding()
        {
            string specialtyBuilding = "";
            string projPath          = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\";

            if (!Directory.Exists(projPath + "SpecialtyDefinitions")) //dir not found, return nothing
            {
                return(specialtyBuilding);
            }

            foreach (var x in Directory.GetFiles(projPath + "SpecialtyDefinitions"))
            {
                string json = File.ReadAllText(x);
                if (JSON_Reader.IsValidJson(json))
                {
                    SpecialtyBuildingClass s = new SpecialtyBuildingClass();
                    s = SpecialtyBuildingClass.FromJson(json);

                    if (s != null)
                    {
                        if (s.RelatedTower != null)
                        {
                            if (s.RelatedTower == towerTypeName)
                            {
                                specialtyBuilding = x.Replace(projPath + "SpecialtyDefinitions\\", "");
                                towerTypeName     = s.RelatedTower;
                                break;
                            }
                        }
                    }
                }
            }
            return(specialtyBuilding);
        }
Пример #2
0
        public string GetSpecialtyBuilding()
        {
            string specialtyBuilding = "";
            string projPath          = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\";

            ConsoleHandler.append("Searching for base tower's specialty building...");
            foreach (var x in Directory.GetFiles(projPath + "SpecialtyDefinitions"))
            {
                string json = File.ReadAllText(x);
                if (!JSON_Reader.IsValidJson(json))
                {
                    continue;
                }

                SpecialtyBuildingClass s = new SpecialtyBuildingClass();
                s = SpecialtyBuildingClass.FromJson(json);

                if (s != null && s.RelatedTower != null && s.RelatedTower == BaseTowerName_NoExt)
                {
                    specialtyBuilding = x.Replace(projPath + "SpecialtyDefinitions\\", "");
                    ConsoleHandler.append("Found base tower's specialty building called:  " + specialtyBuilding);
                    break;
                }
            }
            return(specialtyBuilding);
        }
Пример #3
0
        private void SaveSpecialty(string path, SpecialtyBuildingClass specialty)
        {
            ConsoleHandler.append("Saving specialty building");
            string text = specialty.ToJson();

            StreamWriter serialize = new StreamWriter(path, false);

            serialize.Write(text);
            serialize.Close();
        }
Пример #4
0
        private void MakeNewSpecialty(string savePath)
        {
            ConsoleHandler.append("Creating new Specialty Building");
            SpecialtyBuildingClass specialty = new SpecialtyBuildingClass();

            FileInfo f = new FileInfo(savePath);

            specialty.FileName = f.Name;
            specialty.Name     = "";
            specialty.Icon     = "";
            specialty.Building = "";

            long[] newPrices = { 0, 0, 0, 0 };
            specialty.Prices = newPrices;

            specialty.RelatedTower = TowerName;



            specialty.Tiers = new Tiers()
            {
                I = new I()
                {
                    Text           = "",
                    TowerModifiers = new ITowerModifier[0]
                },
                Ii = new Ii()
                {
                    Text           = "",
                    TowerModifiers = new IiTowerModifier[0]
                },
                Iii = new Iii()
                {
                    Text           = "",
                    TowerModifiers = new IiiTowerModifier[0]
                },
                Iv = new Iv()
                {
                    Text           = "",
                    TowerModifiers = new IvTowerModifier[0]
                },
                X = new I
                {
                    Text           = "",
                    TowerModifiers = new ITowerModifier[0]
                }
            };


            SaveSpecialty(savePath, specialty);
        }
Пример #5
0
        private void MakeDupSpecialty(string savePath)
        {
            ConsoleHandler.append("Duplicating base tower's specialty building");
            SpecialtyBuildingClass specialty = new SpecialtyBuildingClass();

            string baseSpecialName = GetSpecialtyBuilding();

            string baseSpecialPath = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\SpecialtyDefinitions\\" + baseSpecialName;

            if (!File.Exists(baseSpecialPath))
            {
                ConsoleHandler.append("Unable to find the base tower's specialty building by RelatedTower property" +
                                      ". Creating a new one instead.");
                MakeNewSpecialty(savePath);
                return;
            }
            if (!JSON_Reader.IsValidJson(File.ReadAllText(baseSpecialPath)))
            {
                ConsoleHandler.append("The Base specialty building has invalid JSON. Using a new one instead.");
                MakeNewSpecialty(savePath);
                return;
            }

            SpecialtyBuildingClass baseSpecialty = new SpecialtyBuildingClass();

            baseSpecialty = SpecialtyBuildingClass.FromJson(baseSpecialPath);

            FileInfo f = new FileInfo(savePath);

            specialty.FileName = f.Name;
            specialty.Name     = baseSpecialty.Name;
            specialty.Icon     = baseSpecialty.Icon;
            specialty.Building = baseSpecialty.Building;

            specialty.Prices       = baseSpecialty.Prices;
            specialty.RelatedTower = TowerName;

            specialty.Tiers = baseSpecialty.Tiers;
            SaveSpecialty(savePath, specialty);
        }
Пример #6
0
        private void PopulateOpenButton()
        {
            if (path.EndsWith("tower") || path.EndsWith("upgrades") || path.EndsWith("weapon") || path.Contains("TowerSpriteUpgradeDefinitions") || path.Contains("SpecialtyDefinitions"))
            {
                Open_Button.Visible = true;
                Weapons_Button.DropDownItems.Clear();
                file = filename.Replace(".tower", "").Replace(".upgrades", "").Replace(".weapon", "").Replace(".json", "");
                string projPath = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\";

                towerName = GetTowerName();
                if (towerName != "")
                {
                    file = towerName.Replace(".tower", "").Replace(".upgrades", "").Replace(".weapon", "").Replace(".json", "");
                }

                specialty = GetSpecialtyBuilding();
                if (path.Contains("SpecialtyDefinitions"))
                {
                    string json = File.ReadAllText(path);
                    if (JSON_Reader.IsValidJson(json))
                    {
                        SpecialtyBuildingClass s = new SpecialtyBuildingClass();
                        s             = SpecialtyBuildingClass.FromJson(json);
                        towerTypeName = s.RelatedTower;
                    }
                    file = towerTypeName;
                }

                if (File.Exists(projPath + "TowerDefinitions\\" + file + ".tower"))
                {
                    TowerFile_Button.Visible = true;
                    TowerFile_Button.Text    = file + ".tower";
                }
                else
                {
                    TowerFile_Button.Visible = false;
                }

                if (File.Exists(projPath + "UpgradeDefinitions\\" + file + ".upgrades"))
                {
                    UpgradeFIle_Button.Text = file + ".upgrades";
                }
                else
                {
                    UpgradeFIle_Button.Visible = false;
                }

                if (!specialty.Contains(".json"))
                {
                    specialty = specialty + ".json";
                }
                if (specialty != null && specialty != "")
                {
                    if (File.Exists(projPath + "SpecialtyDefinitions\\" + specialty))
                    {
                        specialtyBuildingToolStripMenuItem.Visible = true;
                    }
                    else
                    {
                        specialtyBuildingToolStripMenuItem.Visible = false;
                    }
                }


                if (Directory.Exists(projPath + "WeaponDefinitions\\" + file))
                {
                    string weaponDir = projPath + "WeaponDefinitions\\" + file;
                    foreach (var x in Directory.GetFiles(weaponDir))
                    {
                        string[] split = x.Split('\\');
                        Weapons_Button.DropDownItems.Add(split[split.Length - 1]);
                    }
                }
                else
                {
                    Weapons_Button.Visible = false;
                }


                //TowerSpriteUpgradeDef
                //Attempting to get the TowerSpriteUpgradeDef from tower file
                Tower_Class.Tower tower     = new Tower_Class.Tower();
                string            towerfile = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\TowerDefinitions\\" + file + ".tower";
                if (File.Exists(towerfile))
                {
                    string json = File.ReadAllText(towerfile);
                    if (JSON_Reader.IsValidJson(json))
                    {
                        tower = Tower_Class.Tower.FromJson(json);
                        if (tower != null)
                        {
                            if (tower.SpriteUpgradeDefinition == null || tower.SpriteUpgradeDefinition == "")
                            {
                                TowerSpriteUpgradeDef_Button.Visible = false;
                            }
                            else
                            {
                                towerSpriteUpgradeDef = tower.SpriteUpgradeDefinition;
                            }
                        }
                    }
                    else
                    {
                        if (File.Exists(projPath + "TowerSpriteUpgradeDefinitions\\" + file + ".json"))
                        {
                            ConsoleHandler.append_Force_CanRepeat("Tower file has invalid JSON, and therefore, unable to get current TowerSpriteDefinition file. Using default one instead...");
                        }
                        else
                        {
                            ConsoleHandler.append_Force_CanRepeat("Tower file has invalid JSON, and therefore, unable to get current TowerSpriteDefinition file. Additionally, the default one does not exist. Unable to open TowerSpriteUpgradeDef");
                            TowerSpriteUpgradeDef_Button.Visible = false;
                        }
                    }
                }
                else
                {
                    if (!File.Exists(projPath + "TowerSpriteUpgradeDefinitions\\" + file + ".json"))
                    {
                        TowerSpriteUpgradeDef_Button.Visible = false;
                    }
                }
            }
            else if (!path.EndsWith("tower") && !path.EndsWith("upgrades") && !path.EndsWith("weapon") && !path.Contains("TowerSpriteUpgradeDefinitions"))
            {
                Open_Button.Visible = false;
            }
        }