Beispiel #1
0
 private void DisplayDuplicants(RetiredColonyData data, GameObject container, int range_min = -1, int range_max = -1)
 {
     for (int num = container.transform.childCount - 1; num >= 0; num--)
     {
         UnityEngine.Object.DestroyImmediate(container.transform.GetChild(num).gameObject);
     }
     for (int i = 0; i < data.Duplicants.Length; i++)
     {
         if (i < range_min || (i > range_max && range_max != -1))
         {
             GameObject gameObject = new GameObject();
             gameObject.transform.SetParent(container.transform);
         }
         else
         {
             RetiredColonyData.RetiredDuplicantData retiredDuplicantData = data.Duplicants[i];
             GameObject          gameObject2 = Util.KInstantiateUI(duplicantPrefab, container, true);
             HierarchyReferences component   = gameObject2.GetComponent <HierarchyReferences>();
             component.GetReference <LocText>("NameLabel").SetText(retiredDuplicantData.name);
             component.GetReference <LocText>("AgeLabel").SetText(string.Format(UI.RETIRED_COLONY_INFO_SCREEN.DUPLICANT_AGE, retiredDuplicantData.age.ToString()));
             component.GetReference <LocText>("SkillLabel").SetText(string.Format(UI.RETIRED_COLONY_INFO_SCREEN.SKILL_LEVEL, retiredDuplicantData.skillPointsGained.ToString()));
             SymbolOverrideController reference = component.GetReference <SymbolOverrideController>("SymbolOverrideController");
             reference.RemoveAllSymbolOverrides(0);
             KBatchedAnimController componentInChildren = gameObject2.GetComponentInChildren <KBatchedAnimController>();
             componentInChildren.SetSymbolVisiblity("snapTo_neck", false);
             componentInChildren.SetSymbolVisiblity("snapTo_goggles", false);
             componentInChildren.SetSymbolVisiblity("snapTo_hat", false);
             componentInChildren.SetSymbolVisiblity("snapTo_hat_hair", false);
             foreach (KeyValuePair <string, string> accessory in retiredDuplicantData.accessories)
             {
                 KAnim.Build.Symbol symbol        = Db.Get().Accessories.Get(accessory.Value).symbol;
                 AccessorySlot      accessorySlot = Db.Get().AccessorySlots.Get(accessory.Key);
                 reference.AddSymbolOverride(accessorySlot.targetSymbolId, symbol, 0);
                 gameObject2.GetComponentInChildren <KBatchedAnimController>().SetSymbolVisiblity(accessory.Key, true);
             }
             reference.ApplyOverrides();
         }
     }
     StartCoroutine(ActivatePortraitsWhenReady(container));
 }
    private static RetiredColonyData LoadRetiredColony(string file, bool skipStats, Encoding enc)
    {
        RetiredColonyData retiredColonyData = new RetiredColonyData();

        using (FileStream stream = File.Open(file, FileMode.Open))
        {
            using (StreamReader reader = new StreamReader(stream, enc))
            {
                using (JsonReader jsonReader = new JsonTextReader(reader))
                {
                    string        a    = string.Empty;
                    List <string> list = new List <string>();
                    List <Tuple <string, int> > list2 = new List <Tuple <string, int> >();
                    List <RetiredColonyData.RetiredDuplicantData>   list3 = new List <RetiredColonyData.RetiredDuplicantData>();
                    List <RetiredColonyData.RetiredColonyStatistic> list4 = new List <RetiredColonyData.RetiredColonyStatistic>();
                    while (jsonReader.Read())
                    {
                        JsonToken tokenType = jsonReader.TokenType;
                        if (tokenType == JsonToken.PropertyName)
                        {
                            a = jsonReader.Value.ToString();
                        }
                        if (tokenType == JsonToken.String && a == "colonyName")
                        {
                            retiredColonyData.colonyName = jsonReader.Value.ToString();
                        }
                        if (tokenType == JsonToken.String && a == "date")
                        {
                            retiredColonyData.date = jsonReader.Value.ToString();
                        }
                        if (tokenType == JsonToken.Integer && a == "cycleCount")
                        {
                            retiredColonyData.cycleCount = int.Parse(jsonReader.Value.ToString());
                        }
                        if (tokenType == JsonToken.String && a == "achievements")
                        {
                            list.Add(jsonReader.Value.ToString());
                        }
                        if (tokenType == JsonToken.StartObject && a == "Duplicants")
                        {
                            string a2 = null;
                            RetiredColonyData.RetiredDuplicantData retiredDuplicantData = new RetiredColonyData.RetiredDuplicantData();
                            retiredDuplicantData.accessories = new Dictionary <string, string>();
                            while (true)
                            {
                                if (jsonReader.Read())
                                {
                                    tokenType = jsonReader.TokenType;
                                    switch (tokenType)
                                    {
                                    case JsonToken.PropertyName:
                                        a2 = jsonReader.Value.ToString();
                                        goto default;

                                    default:
                                        if (a2 == "name" && tokenType == JsonToken.String)
                                        {
                                            retiredDuplicantData.name = jsonReader.Value.ToString();
                                        }
                                        if (a2 == "age" && tokenType == JsonToken.Integer)
                                        {
                                            retiredDuplicantData.age = int.Parse(jsonReader.Value.ToString());
                                        }
                                        if (a2 == "skillPointsGained" && tokenType == JsonToken.Integer)
                                        {
                                            retiredDuplicantData.skillPointsGained = int.Parse(jsonReader.Value.ToString());
                                        }
                                        if (a2 == "accessories")
                                        {
                                            string text = null;
                                            while (true)
                                            {
                                                if (jsonReader.Read())
                                                {
                                                    tokenType = jsonReader.TokenType;
                                                    switch (tokenType)
                                                    {
                                                    case JsonToken.PropertyName:
                                                        text = jsonReader.Value.ToString();
                                                        goto default;

                                                    default:
                                                        if (text != null && jsonReader.Value != null && tokenType == JsonToken.String)
                                                        {
                                                            string value = jsonReader.Value.ToString();
                                                            retiredDuplicantData.accessories.Add(text, value);
                                                        }
                                                        continue;

                                                    case JsonToken.EndObject:
                                                        break;
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                        continue;

                                    case JsonToken.EndObject:
                                        break;
                                    }
                                }
                                break;
                            }
                            list3.Add(retiredDuplicantData);
                        }
                        if (tokenType == JsonToken.StartObject && a == "buildings")
                        {
                            string a3 = null;
                            string a4 = null;
                            int    b  = 0;
                            while (true)
                            {
                                if (jsonReader.Read())
                                {
                                    tokenType = jsonReader.TokenType;
                                    switch (tokenType)
                                    {
                                    case JsonToken.PropertyName:
                                        a3 = jsonReader.Value.ToString();
                                        goto default;

                                    default:
                                        if (a3 == "first" && tokenType == JsonToken.String)
                                        {
                                            a4 = jsonReader.Value.ToString();
                                        }
                                        if (a3 == "second" && tokenType == JsonToken.Integer)
                                        {
                                            b = int.Parse(jsonReader.Value.ToString());
                                        }
                                        continue;

                                    case JsonToken.EndObject:
                                        break;
                                    }
                                }
                                break;
                            }
                            Tuple <string, int> item = new Tuple <string, int>(a4, b);
                            list2.Add(item);
                        }
                        if (tokenType == JsonToken.StartObject && a == "Stats")
                        {
                            if (skipStats)
                            {
                                break;
                            }
                            string a5 = null;
                            RetiredColonyData.RetiredColonyStatistic retiredColonyStatistic = new RetiredColonyData.RetiredColonyStatistic();
                            List <Tuple <float, float> >             list5 = new List <Tuple <float, float> >();
                            while (true)
                            {
                                if (jsonReader.Read())
                                {
                                    tokenType = jsonReader.TokenType;
                                    switch (tokenType)
                                    {
                                    case JsonToken.PropertyName:
                                        a5 = jsonReader.Value.ToString();
                                        goto default;

                                    default:
                                        if (a5 == "id" && tokenType == JsonToken.String)
                                        {
                                            retiredColonyStatistic.id = jsonReader.Value.ToString();
                                        }
                                        if (a5 == "name" && tokenType == JsonToken.String)
                                        {
                                            retiredColonyStatistic.name = jsonReader.Value.ToString();
                                        }
                                        if (a5 == "nameX" && tokenType == JsonToken.String)
                                        {
                                            retiredColonyStatistic.nameX = jsonReader.Value.ToString();
                                        }
                                        if (a5 == "nameY" && tokenType == JsonToken.String)
                                        {
                                            retiredColonyStatistic.nameY = jsonReader.Value.ToString();
                                        }
                                        if (a5 == "value" && tokenType == JsonToken.StartObject)
                                        {
                                            string a6 = null;
                                            float  a7 = 0f;
                                            float  b2 = 0f;
                                            while (true)
                                            {
                                                if (jsonReader.Read())
                                                {
                                                    tokenType = jsonReader.TokenType;
                                                    switch (tokenType)
                                                    {
                                                    case JsonToken.PropertyName:
                                                        a6 = jsonReader.Value.ToString();
                                                        goto default;

                                                    default:
                                                        if (a6 == "first" && (tokenType == JsonToken.Float || tokenType == JsonToken.Integer))
                                                        {
                                                            a7 = float.Parse(jsonReader.Value.ToString());
                                                        }
                                                        if (a6 == "second" && (tokenType == JsonToken.Float || tokenType == JsonToken.Integer))
                                                        {
                                                            b2 = float.Parse(jsonReader.Value.ToString());
                                                        }
                                                        continue;

                                                    case JsonToken.EndObject:
                                                        break;
                                                    }
                                                }
                                                break;
                                            }
                                            Tuple <float, float> item2 = new Tuple <float, float>(a7, b2);
                                            list5.Add(item2);
                                        }
                                        continue;

                                    case JsonToken.EndObject:
                                        break;
                                    }
                                }
                                break;
                            }
                            retiredColonyStatistic.value = list5.ToArray();
                            list4.Add(retiredColonyStatistic);
                        }
                    }
                    retiredColonyData.Duplicants   = list3.ToArray();
                    retiredColonyData.Stats        = list4.ToArray();
                    retiredColonyData.achievements = list.ToArray();
                    retiredColonyData.buildings    = list2;
                    return(retiredColonyData);
                }
            }
        }
    }