Beispiel #1
0
        private string GetTowerName()
        {
            string towerName = "";
            string projPath  = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\";

            if (!Directory.Exists(projPath + "TowerDefinitions"))
            {
                return(towerName);
            }
            foreach (var x in Directory.GetFiles(projPath + "TowerDefinitions"))
            {
                string json = File.ReadAllText(x);
                if (JSON_Reader.IsValidJson(json))
                {
                    Tower_Class.Tower t = new Tower_Class.Tower();
                    t = Tower_Class.Tower.FromJson(json);
                    if (t != null)
                    {
                        if (t.SpriteUpgradeDefinition != null)
                        {
                            if (t.SpriteUpgradeDefinition.Replace(".json", "") == file.Replace(".json", ""))
                            {
                                towerName     = x.Replace(projPath + "TowerDefinitions\\", "");
                                towerTypeName = t.TypeName;
                                break;
                            }
                        }
                    }
                }
            }
            return(towerName);
        }
Beispiel #2
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;
            }
        }