private static string _generateNameHelper(List <NamePart> nameParts, Randomizer randomizer)
        {
            List <BuildableNamePart> bnpList = new List <BuildableNamePart>();
            int nameLength = 0;

            for (int i = 0; i < nameParts.Count; i++)
            {
                NamePart part = nameParts[i];
                bool     buildableIsOptional = false;

                if (part.isOptional)
                {
                    if (randomizer.Int32(10) > 5)
                    {
                        continue;
                    }
                    buildableIsOptional = true;
                }

                string newWord = part.nameList[randomizer.Int32((uint)part.nameList.Count)];
                if (!newWord.Trim().Equals(""))
                {
                    newWord += " ";
                }

                BuildableNamePart bnp = new BuildableNamePart(buildableIsOptional, newWord);
                bnpList.Add(bnp);
                nameLength += newWord.Length;
            }
            return(_bestFitName(bnpList, nameLength));
        }
コード例 #2
0
        private void _readNamesFromFile()
        {
            List <string> filesToCheck = new List <string> {
                WufireNameGenerator.CommercialNameFile, WufireNameGenerator.OfficeNameFile, WufireNameGenerator.IndustryNameFile, WufireNameGenerator.ResidentialNameFile
            };

            buildingNames = new Dictionary <string, List <NamePart> >();

            foreach (string file in filesToCheck)
            {
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
                fileInfo.Directory.Create();
                if (!FileUtils.Exists(file))
                {
                    DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, "Name file not found. Writing a new name file to " + file);
                    string defaultText = _stringFromDefaultFile(file);
                    System.IO.File.WriteAllText(file, defaultText);
                }
                object obj = null;
                try {
                    string fileText = System.IO.File.ReadAllText(file);
                    obj = ColossalFramework.HTTP.JSON.JsonDecode(fileText);
                } catch {
                    // Error - Load default name file
                    DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Error, "Error parsing name file. Loading default names.");
                    string fileText = _stringFromDefaultFile(file);
                    obj = ColossalFramework.HTTP.JSON.JsonDecode(fileText);
                }
                if (obj != null)
                {
                    Hashtable dictionary = (Hashtable)obj;
                    foreach (string subServiceKey in dictionary.Keys)
                    {
                        ArrayList       subObj      = (ArrayList)dictionary[subServiceKey];
                        List <NamePart> newPartList = new List <NamePart>();
                        foreach (Hashtable d in subObj)
                        {
                            NamePart n = new NamePart(d);
                            newPartList.Add(n);
                        }
                        buildingNames.Add(subServiceKey, newPartList);
                    }
                }
            }
        }
コード例 #3
0
        private void _readNamesFromFile()
        {
            List<string> filesToCheck = new List<string>{WufireNameGenerator.CommercialNameFile, WufireNameGenerator.OfficeNameFile, WufireNameGenerator.IndustryNameFile, WufireNameGenerator.ResidentialNameFile};
              buildingNames = new Dictionary<string, List<NamePart>>();

              foreach (string file in filesToCheck) {
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
            fileInfo.Directory.Create();
            if ( ! FileUtils.Exists(file)) {
              DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, "Name file not found. Writing a new name file to " + file);
              string defaultText = _stringFromDefaultFile(file);
              System.IO.File.WriteAllText(file, defaultText);
            }
            object obj = null;
            try {
              string fileText = System.IO.File.ReadAllText(file);
              obj = ColossalFramework.HTTP.JSON.JsonDecode(fileText);
            } catch {
              // Error - Load default name file
              DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Error, "Error parsing name file. Loading default names.");
              string fileText = _stringFromDefaultFile(file);
              obj = ColossalFramework.HTTP.JSON.JsonDecode(fileText);
            }
            if (obj != null) {
              Hashtable dictionary = (Hashtable) obj;
              foreach(string subServiceKey in dictionary.Keys) {
            ArrayList subObj = (ArrayList)dictionary[subServiceKey];
            List<NamePart> newPartList = new List<NamePart>();
            foreach(Hashtable d in subObj) {
              NamePart n = new NamePart(d);
              newPartList.Add(n);
            }
            buildingNames.Add(subServiceKey, newPartList);
              }
            }
              }
        }