public Head_Set randomize(int gender) { Head_Set headSetChoosen = null; headNumberOfUse = personaliser.maleAndfemaleHeadsDB_cleaned[gender].ToDictionary(k => k.name, v => 0); List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >(headNumberOfUse); foreach (KeyValuePair <string, int> kvp in list) { int count = personaliser.KerbalAndTheirHeadsDB.Count(k => k.Value.Contains(kvp.Key)); headNumberOfUse[kvp.Key] = count; } list = new List <KeyValuePair <string, int> >(headNumberOfUse); List <KeyValuePair <string, int> > sortedList = (from kv in headNumberOfUse orderby kv.Value select kv).ToList(); int counter = sortedList[0].Value; foreach (KeyValuePair <string, int> data in sortedList) { if (data.Value <= counter) { headListCleaned.Add(data.Key); } } int number = random.Next(0, headListCleaned.Count); string choice = headListCleaned[number]; headSetChoosen = personaliser.maleAndfemaleHeadsDB_cleaned[gender].Find(x => x.name == choice); return(headSetChoosen); }
/// <summary> /// Loads all Heads into a non gender-specific list and in two gender-specific lists /// </summary> /// <param name="FullList"></param> /// <param name="GenderList"></param> /// <param name="DefaultHead"></param> internal static void LoadHeads(List <Head_Set> FullList, List <Head_Set>[] GenderList, Head_Set[] DefaultHead) { string[] gender = { "Male", "Female" }; var headDirs = new Dictionary <string, int>(); // temp fix when there is no default texture foreach (GameDatabase.TextureInfo texInfo in GameDatabase.Instance.databaseTexture) { Texture2D texture = texInfo.texture; if (texture == null || !texture.name.StartsWith(Folders.DIR_DEFAULT, StringComparison.Ordinal)) { continue; } if (texture.name.StartsWith(Folders.DIR_DEFAULT, StringComparison.Ordinal)) { int lastSlash = texture.name.LastIndexOf('/'); string originalName = texture.name.Substring(lastSlash + 1); if (originalName == "KerbalHead_Male_Default") { DefaultHead[0].setTexture("kerbalHead", texture); texture.wrapMode = TextureWrapMode.Clamp; } else if (originalName == "KerbalHead_Male_NRM_Default") { DefaultHead[0].setTexture("kerbalHeadNRM", texture); texture.wrapMode = TextureWrapMode.Clamp; } else if (originalName == "KerbalHead_Female_Default") { DefaultHead[1].setTexture("kerbalGirl_06_BaseColor", texture); texture.wrapMode = TextureWrapMode.Clamp; } else if (originalName == "KerbalHead_Female_NRM_Default") { DefaultHead[1].setTexture("kerbalGirl_06_BaseColorNRM", texture); texture.wrapMode = TextureWrapMode.Clamp; } } } foreach (string defaultFolders in Folders.DEFAULT) { foreach (GameDatabase.TextureInfo texInfo in GameDatabase.Instance.databaseTexture) { Texture2D texture = texInfo.texture; if (texture == null || !texture.name.StartsWith(defaultFolders, StringComparison.Ordinal)) { continue; } //Util.log("starting loading default head"); if (texture.name.StartsWith(defaultFolders, StringComparison.Ordinal)) { int lastSlash = texture.name.LastIndexOf('/'); string originalName = texture.name.Substring(lastSlash + 1); //Util.log("default folder = " +defaultFolders); //Util.log("DEFAULT : texture name \"{0}\": {1}", originalName, texture.name); if (originalName == "kerbalHead") { DefaultHead[0].setTexture(originalName, texture); texture.wrapMode = TextureWrapMode.Clamp; } else if (originalName == "kerbalHeadNRM") { DefaultHead[0].setTexture(originalName, texture); texture.wrapMode = TextureWrapMode.Clamp; } else if (originalName == "kerbalGirl_06_BaseColor") { DefaultHead[1].setTexture(originalName, texture); texture.wrapMode = TextureWrapMode.Clamp; } else if (originalName == "kerbalGirl_06_BaseColorNRM") { DefaultHead[1].setTexture(originalName, texture); texture.wrapMode = TextureWrapMode.Clamp; } } } } for (int i = 0; i < 2; i++) { // Util.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //Util.log("i = : {0}", i); foreach (string HEADS_Folder in Folders.HEADS) { //Util.log("++++++++++++++++++++++++++++++++++++++++++++++"); // Util.log("HEADS_Folder = : {0}", HEADS_Folder); string genderFolder = (HEADS_Folder + gender[i] + "/"); //Util.log("genderFolder = : {0}", genderFolder); foreach (GameDatabase.TextureInfo texInfo in GameDatabase.Instance.databaseTexture.Where(t => t.name.StartsWith(genderFolder))) { //Util.log("****************************"); Texture2D texture = texInfo.texture; //Util.log("Texture full path = : {0}", texture.name); int lastSlash_full = texture.name.LastIndexOf('/'); //Util.log("lastSlash_full = : {0}", lastSlash_full); string headSetFolder_full = texInfo.name.Substring(genderFolder.Length); //Util.log("headSetFolder_full = : {0}", headSetFolder_full); int lastSlash_headSetFolder = headSetFolder_full.LastIndexOf('/'); //Util.log("lastSlash_headSetFolder = : {0}", lastSlash_headSetFolder); if (lastSlash_headSetFolder < 1) { Util.log("Head texture should be inside a subdirectory: {0}", texture.name); continue; } string TextureFileName = texture.name.Substring(lastSlash_full + 1); string headSetFolder = headSetFolder_full.Remove(headSetFolder_full.Length - (TextureFileName.Length + 1)); //Util.log("headSetFolder = : {0}", headSetFolder); //Util.log("TextureFileName = : {0}", TextureFileName); if (texture == null) { Util.log("texture : {0} == null!! ", TextureFileName); continue; } if (!texture.name.StartsWith(HEADS_Folder, StringComparison.Ordinal)) { Util.log("texture : {0} DON'T start with {1}", TextureFileName, HEADS_Folder); continue; } else { texture.wrapMode = TextureWrapMode.Clamp; int index; if (!headDirs.TryGetValue(headSetFolder, out index)) { index = FullList.Count; Head_Set head = new Head_Set { name = headSetFolder, isFemale = (i == 1) }; FullList.Add(head); headDirs.Add(headSetFolder, index); GenderList[i].Add(head); Util.log("HeadSet added : {0}", headSetFolder); } Head_Set headSet = FullList[index]; //headSet = DefaultHead[i]; if (!headSet.setTexture(TextureFileName, texture)) { //Util.log("Texture {0} properly loaded in {1}", TextureFileName, texture.name); //else Util.log("Unknown head texture name \"{0}\": {1}", TextureFileName, texture.name); } } } } } }