예제 #1
0
        public void MapMeshDrawerUpdate_First()
        {
            CellRect visibleSections = this.VisibleSections;
            bool     flag            = false;

            CellRect.CellRectIterator iterator = visibleSections.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 current = iterator.Current;
                Section sect    = this.sections[current.x, current.z];
                if (this.TryUpdateSection(sect))
                {
                    flag = true;
                }
                iterator.MoveNext();
            }
            if (!flag)
            {
                int num = 0;
                while (true)
                {
                    int     num2         = num;
                    IntVec2 sectionCount = this.SectionCount;
                    if (num2 < sectionCount.x)
                    {
                        int num3 = 0;
                        while (true)
                        {
                            int     num4          = num3;
                            IntVec2 sectionCount2 = this.SectionCount;
                            if (num4 < sectionCount2.z)
                            {
                                if (!this.TryUpdateSection(this.sections[num, num3]))
                                {
                                    num3++;
                                    continue;
                                }
                                return;
                            }
                            break;
                        }
                        num++;
                        continue;
                    }
                    break;
                }
            }
        }
예제 #2
0
        public bool TryFindRandomInnerRect(IntVec2 size, out CellRect rect, Predicate <CellRect> predicate = null)
        {
            bool result;

            if (this.Width < size.x || this.Height < size.z)
            {
                rect   = CellRect.Empty;
                result = false;
            }
            else if (size.x <= 0 || size.z <= 0 || this.IsEmpty)
            {
                rect   = CellRect.Empty;
                result = false;
            }
            else
            {
                CellRect cellRect = this;
                cellRect.maxX -= size.x - 1;
                cellRect.maxZ -= size.z - 1;
                IntVec3 intVec;
                if (cellRect.Cells.Where(delegate(IntVec3 x)
                {
                    bool result2;
                    if (predicate == null)
                    {
                        result2 = true;
                    }
                    else
                    {
                        CellRect obj = new CellRect(x.x, x.z, size.x, size.z);
                        result2 = predicate(obj);
                    }
                    return(result2);
                }).TryRandomElement(out intVec))
                {
                    rect   = new CellRect(intVec.x, intVec.z, size.x, size.z);
                    result = true;
                }
                else
                {
                    rect   = CellRect.Empty;
                    result = false;
                }
            }
            return(result);
        }
예제 #3
0
        private void AdjustWindowsIfResolutionChanged()
        {
            IntVec2 a = new IntVec2(UI.screenWidth, UI.screenHeight);

            if (a != this.prevResolution)
            {
                this.prevResolution = a;
                for (int i = 0; i < this.windows.Count; i++)
                {
                    this.windows[i].Notify_ResolutionChanged();
                }
                if (Current.ProgramState == ProgramState.Playing)
                {
                    Find.ColonistBar.MarkColonistsDirty();
                }
            }
        }
예제 #4
0
        private void AdjustWindowsIfResolutionChanged()
        {
            IntVec2 a = new IntVec2(UI.screenWidth, UI.screenHeight);

            if (!UnityGUIBugsFixer.ResolutionsEqual(a, prevResolution))
            {
                prevResolution = a;
                for (int i = 0; i < windows.Count; i++)
                {
                    windows[i].Notify_ResolutionChanged();
                }
                if (Current.ProgramState == ProgramState.Playing)
                {
                    Find.ColonistBar.MarkColonistsDirty();
                }
            }
        }
예제 #5
0
        public void RegenerateEverythingNow()
        {
            if (this.sections == null)
            {
                IntVec2 sectionCount  = this.SectionCount;
                int     x             = sectionCount.x;
                IntVec2 sectionCount2 = this.SectionCount;
                this.sections = new Section[x, sectionCount2.z];
            }
            int num = 0;

            while (true)
            {
                int     num2          = num;
                IntVec2 sectionCount3 = this.SectionCount;
                if (num2 < sectionCount3.x)
                {
                    int num3 = 0;
                    while (true)
                    {
                        int     num4          = num3;
                        IntVec2 sectionCount4 = this.SectionCount;
                        if (num4 < sectionCount4.z)
                        {
                            if (this.sections[num, num3] == null)
                            {
                                Section[,] array = this.sections;
                                int     num5    = num;
                                int     num6    = num3;
                                Section section = new Section(new IntVec3(num, 0, num3), this.map);
                                array[num5, num6] = section;
                            }
                            this.sections[num, num3].RegenerateAllLayers();
                            num3++;
                            continue;
                        }
                        break;
                    }
                    num++;
                    continue;
                }
                break;
            }
        }
예제 #6
0
        public static void AdjustForRotation(ref IntVec3 center, ref IntVec2 size, Rot4 rot)
        {
            if (size.x == 1 && size.z == 1)
            {
                return;
            }
            if (rot.IsHorizontal)
            {
                int x = size.x;
                size.x = size.z;
                size.z = x;
            }
            switch (rot.AsInt)
            {
            case 0:
                break;

            case 1:
                if (size.z % 2 == 0)
                {
                    center.z--;
                }
                break;

            case 2:
                if (size.x % 2 == 0)
                {
                    center.x--;
                }
                if (size.z % 2 == 0)
                {
                    center.z--;
                }
                break;

            case 3:
                if (size.x % 2 == 0)
                {
                    center.x--;
                }
                break;
            }
        }
예제 #7
0
        public void RegenerateEverythingNow()
        {
            if (sections == null)
            {
                IntVec2 sectionCount  = SectionCount;
                int     x             = sectionCount.x;
                IntVec2 sectionCount2 = SectionCount;
                sections = new Section[x, sectionCount2.z];
            }
            int num = 0;

            while (true)
            {
                int     num2          = num;
                IntVec2 sectionCount3 = SectionCount;
                if (num2 >= sectionCount3.x)
                {
                    break;
                }
                int num3 = 0;
                while (true)
                {
                    int     num4          = num3;
                    IntVec2 sectionCount4 = SectionCount;
                    if (num4 >= sectionCount4.z)
                    {
                        break;
                    }
                    if (sections[num, num3] == null)
                    {
                        Section[,] array = sections;
                        int     num5    = num;
                        int     num6    = num3;
                        Section section = new Section(new IntVec3(num, 0, num3), map);
                        array[num5, num6] = section;
                    }
                    sections[num, num3].RegenerateAllLayers();
                    num3++;
                }
                num++;
            }
        }
예제 #8
0
        public static IEnumerable <IntVec3> CellsAdjacent8WayAndInside(this Thing thing)
        {
            IntVec3 center   = thing.Position;
            IntVec2 size     = thing.def.size;
            Rot4    rotation = thing.Rotation;

            GenAdj.AdjustForRotation(ref center, ref size, rotation);
            int minX = center.x - (size.x - 1) / 2 - 1;
            int minZ = center.z - (size.z - 1) / 2 - 1;
            int maxX = minX + size.x + 1;
            int maxZ = minZ + size.z + 1;

            for (int i = minX; i <= maxX; i++)
            {
                for (int j = minZ; j <= maxZ; j++)
                {
                    yield return(new IntVec3(i, 0, j));
                }
            }
        }
        public void MapMeshDirty(IntVec3 loc, MapMeshFlag dirtyFlags, bool regenAdjacentCells, bool regenAdjacentSections)
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }
            Section section = this.SectionAt(loc);

            section.dirtyFlags |= dirtyFlags;
            if (regenAdjacentCells)
            {
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 intVec = loc + GenAdj.AdjacentCells[i];
                    if (intVec.InBounds(this.map))
                    {
                        this.SectionAt(intVec).dirtyFlags |= dirtyFlags;
                    }
                }
            }
            if (regenAdjacentSections)
            {
                IntVec2 a = this.SectionCoordsAt(loc);
                for (int j = 0; j < 8; j++)
                {
                    IntVec3 intVec2      = GenAdj.AdjacentCells[j];
                    IntVec2 intVec3      = a + new IntVec2(intVec2.x, intVec2.z);
                    IntVec2 sectionCount = this.SectionCount;
                    if (intVec3.x >= 0 && intVec3.z >= 0 && intVec3.x <= sectionCount.x - 1 && intVec3.z <= sectionCount.z - 1)
                    {
                        Section section2 = this.sections[intVec3.x, intVec3.z];
                        section2.dirtyFlags |= dirtyFlags;
                    }
                }
            }
        }
예제 #10
0
 public static IntVec2 ParseIntVec2(string str)
 {
     return(IntVec2.FromString(str));
 }
예제 #11
0
 public static bool ResolutionsEqual(IntVec2 a, IntVec2 b)
 {
     return(a == b);
 }
예제 #12
0
 public static Rot4 FromIntVec2(IntVec2 offset)
 {
     return(Rot4.FromIntVec3(offset.ToIntVec3));
 }
예제 #13
0
 public CellRect MovedBy(IntVec2 offset)
 {
     return(MovedBy(offset.ToIntVec3));
 }
예제 #14
0
        public Section SectionAt(IntVec3 loc)
        {
            IntVec2 intVec = this.SectionCoordsAt(loc);

            return(this.sections[intVec.x, intVec.z]);
        }
예제 #15
0
        public static IntVec3 InteractionCellWhenAt(ThingDef def, IntVec3 center, Rot4 rot, Map map)
        {
            if (def.hasInteractionCell)
            {
                IntVec3 b = def.interactionCellOffset.RotatedBy(rot);
                return(center + b);
            }
            IntVec2 size = def.Size;

            if (size.x == 1)
            {
                IntVec2 size2 = def.Size;
                if (size2.z == 1)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        IntVec3 intVec = center + GenAdj.AdjacentCells[i];
                        if (intVec.Standable(map) && intVec.GetDoor(map) == null && ReachabilityImmediate.CanReachImmediate(intVec, center, map, PathEndMode.Touch, null))
                        {
                            return(intVec);
                        }
                    }
                    for (int j = 0; j < 8; j++)
                    {
                        IntVec3 intVec2 = center + GenAdj.AdjacentCells[j];
                        if (intVec2.Standable(map) && ReachabilityImmediate.CanReachImmediate(intVec2, center, map, PathEndMode.Touch, null))
                        {
                            return(intVec2);
                        }
                    }
                    for (int k = 0; k < 8; k++)
                    {
                        IntVec3 intVec3 = center + GenAdj.AdjacentCells[k];
                        if (intVec3.Walkable(map) && ReachabilityImmediate.CanReachImmediate(intVec3, center, map, PathEndMode.Touch, null))
                        {
                            return(intVec3);
                        }
                    }
                    return(center);
                }
            }
            List <IntVec3> list = GenAdjFast.AdjacentCells8Way(center, rot, def.size);
            CellRect       rect = GenAdj.OccupiedRect(center, rot, def.size);

            for (int l = 0; l < list.Count; l++)
            {
                if (list[l].Standable(map) && list[l].GetDoor(map) == null && ReachabilityImmediate.CanReachImmediate(list[l], rect, map, PathEndMode.Touch, null))
                {
                    return(list[l]);
                }
            }
            for (int m = 0; m < list.Count; m++)
            {
                if (list[m].Standable(map) && ReachabilityImmediate.CanReachImmediate(list[m], rect, map, PathEndMode.Touch, null))
                {
                    return(list[m]);
                }
            }
            for (int n = 0; n < list.Count; n++)
            {
                if (list[n].Walkable(map) && ReachabilityImmediate.CanReachImmediate(list[n], rect, map, PathEndMode.Touch, null))
                {
                    return(list[n]);
                }
            }
            return(center);
        }
 public Dialog_ResolutionConfirm(IntVec2 oldRes) : this()
 {
     this.oldFullscreen = Screen.fullScreen;
     this.oldRes        = oldRes;
     this.oldUIScale    = Prefs.UIScale;
 }
예제 #17
0
 public static bool TryFindRandomAdjacentCell8WayWithRoomGroup(IntVec3 center, Rot4 rot, IntVec2 size, Map map, out IntVec3 result)
 {
     GenAdj.AdjustForRotation(ref center, ref size, rot);
     GenAdj.validCells.Clear();
     foreach (IntVec3 current in GenAdj.CellsAdjacent8Way(center, rot, size))
     {
         if (current.InBounds(map) && current.GetRoomGroup(map) != null)
         {
             GenAdj.validCells.Add(current);
         }
     }
     return(GenAdj.validCells.TryRandomElement(out result));
 }
예제 #18
0
 public static bool TryFindRandomAdjacentCell8WayWithRoomGroup(IntVec3 center, Rot4 rot, IntVec2 size, Map map, out IntVec3 result)
 {
     AdjustForRotation(ref center, ref size, rot);
     validCells.Clear();
     foreach (IntVec3 item in CellsAdjacent8Way(center, rot, size))
     {
         if (item.InBounds(map) && item.GetRoomGroup(map) != null)
         {
             validCells.Add(item);
         }
     }
     return(validCells.TryRandomElement(out result));
 }
예제 #19
0
        public static IEnumerable <IntVec3> CellsAdjacentAlongEdge(IntVec3 thingCent, Rot4 thingRot, IntVec2 thingSize, LinkDirections dir)
        {
            GenAdj.AdjustForRotation(ref thingCent, ref thingSize, thingRot);
            int minX = thingCent.x - (thingSize.x - 1) / 2 - 1;
            int minZ = thingCent.z - (thingSize.z - 1) / 2 - 1;
            int maxX = minX + thingSize.x + 1;
            int maxZ = minZ + thingSize.z + 1;

            if (dir == LinkDirections.Down)
            {
                for (int x = minX; x <= maxX; x++)
                {
                    yield return(new IntVec3(x, thingCent.y, minZ - 1));
                }
            }
            if (dir == LinkDirections.Up)
            {
                for (int x2 = minX; x2 <= maxX; x2++)
                {
                    yield return(new IntVec3(x2, thingCent.y, maxZ + 1));
                }
            }
            if (dir == LinkDirections.Left)
            {
                for (int z = minZ; z <= maxZ; z++)
                {
                    yield return(new IntVec3(minX - 1, thingCent.y, z));
                }
            }
            if (dir == LinkDirections.Right)
            {
                for (int z2 = minZ; z2 <= maxZ; z2++)
                {
                    yield return(new IntVec3(maxX + 1, thingCent.y, z2));
                }
            }
        }
예제 #20
0
        public static IEnumerable <IntVec3> CellsAdjacentCardinal(IntVec3 center, Rot4 rot, IntVec2 size)
        {
            GenAdj.AdjustForRotation(ref center, ref size, rot);
            int     minX = center.x - (size.x - 1) / 2 - 1;
            int     maxX = minX + size.x + 1;
            int     minZ = center.z - (size.z - 1) / 2 - 1;
            int     maxZ = minZ + size.z + 1;
            IntVec3 cur  = new IntVec3(minX, 0, minZ);

            do
            {
                cur.x++;
                yield return(cur);
            }while (cur.x < maxX - 1);
            cur.x++;
            do
            {
                cur.z++;
                yield return(cur);
            }while (cur.z < maxZ - 1);
            cur.z++;
            do
            {
                cur.x--;
                yield return(cur);
            }while (cur.x > minX + 1);
            cur.x--;
            do
            {
                cur.z--;
                yield return(cur);
            }while (cur.z > minZ + 1);
        }
예제 #21
0
        public static IEnumerable <IntVec3> CellsAdjacent8Way(IntVec3 thingCenter, Rot4 thingRot, IntVec2 thingSize)
        {
            GenAdj.AdjustForRotation(ref thingCenter, ref thingSize, thingRot);
            int     minX = thingCenter.x - (thingSize.x - 1) / 2 - 1;
            int     maxX = minX + thingSize.x + 1;
            int     minZ = thingCenter.z - (thingSize.z - 1) / 2 - 1;
            int     maxZ = minZ + thingSize.z + 1;
            IntVec3 cur  = new IntVec3(minX - 1, 0, minZ);

            do
            {
                cur.x++;
                yield return(cur);
            }while (cur.x < maxX);
            do
            {
                cur.z++;
                yield return(cur);
            }while (cur.z < maxZ);
            do
            {
                cur.x--;
                yield return(cur);
            }while (cur.x > minX);
            do
            {
                cur.z--;
                yield return(cur);
            }while (cur.z > minZ + 1);
        }
예제 #22
0
        public static IEnumerable <IntVec3> CellsOccupiedBy(IntVec3 center, Rot4 rotation, IntVec2 size)
        {
            GenAdj.AdjustForRotation(ref center, ref size, rotation);
            int minX = center.x - (size.x - 1) / 2;
            int minZ = center.z - (size.z - 1) / 2;
            int maxX = minX + size.x - 1;
            int maxZ = minZ + size.z - 1;

            for (int i = minX; i <= maxX; i++)
            {
                for (int j = minZ; j <= maxZ; j++)
                {
                    yield return(new IntVec3(i, 0, j));
                }
            }
        }
        public static List <IntVec3> AdjacentCells8Way(IntVec3 thingCenter, Rot4 thingRot, IntVec2 thingSize)
        {
            if (thingSize.x == 1 && thingSize.z == 1)
            {
                return(GenAdjFast.AdjacentCells8Way(thingCenter));
            }
            if (GenAdjFast.working)
            {
                throw new InvalidOperationException("GenAdjFast is already working.");
            }
            GenAdjFast.resultList.Clear();
            GenAdjFast.working = true;
            GenAdj.AdjustForRotation(ref thingCenter, ref thingSize, thingRot);
            int     num  = thingCenter.x - (thingSize.x - 1) / 2 - 1;
            int     num2 = num + thingSize.x + 1;
            int     num3 = thingCenter.z - (thingSize.z - 1) / 2 - 1;
            int     num4 = num3 + thingSize.z + 1;
            IntVec3 item = new IntVec3(num - 1, 0, num3);

            do
            {
                item.x++;
                GenAdjFast.resultList.Add(item);
            }while (item.x < num2);
            do
            {
                item.z++;
                GenAdjFast.resultList.Add(item);
            }while (item.z < num4);
            do
            {
                item.x--;
                GenAdjFast.resultList.Add(item);
            }while (item.x > num);
            do
            {
                item.z--;
                GenAdjFast.resultList.Add(item);
            }while (item.z > num3 + 1);
            GenAdjFast.working = false;
            return(GenAdjFast.resultList);
        }
예제 #24
0
        public static bool AdjacentTo8WayOrInside(this IntVec3 root, IntVec3 center, Rot4 rot, IntVec2 size)
        {
            GenAdj.AdjustForRotation(ref center, ref size, rot);
            int num  = center.x - (size.x - 1) / 2 - 1;
            int num2 = center.z - (size.z - 1) / 2 - 1;
            int num3 = num + size.x + 1;
            int num4 = num2 + size.z + 1;

            return(root.x >= num && root.x <= num3 && root.z >= num2 && root.z <= num4);
        }
 public Dialog_ResolutionConfirm(bool oldFullscreen) : this()
 {
     this.oldFullscreen = oldFullscreen;
     this.oldRes        = new IntVec2(Screen.width, Screen.height);
     this.oldUIScale    = Prefs.UIScale;
 }
예제 #26
0
 public static CellRect OccupiedRect(IntVec3 center, Rot4 rot, IntVec2 size)
 {
     GenAdj.AdjustForRotation(ref center, ref size, rot);
     return(new CellRect(center.x - (size.x - 1) / 2, center.z - (size.z - 1) / 2, size.x, size.z));
 }
 public Dialog_ResolutionConfirm(float oldUIScale) : this()
 {
     this.oldFullscreen = Screen.fullScreen;
     this.oldRes        = new IntVec2(Screen.width, Screen.height);
     this.oldUIScale    = oldUIScale;
 }
예제 #28
0
        public static object FromString(string str, Type itemType)
        {
            object result;

            try
            {
                itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
                if (itemType == typeof(string))
                {
                    str    = str.Replace("\\n", "\n");
                    result = str;
                }
                else if (itemType == typeof(int))
                {
                    result = int.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(float))
                {
                    result = float.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(bool))
                {
                    result = bool.Parse(str);
                }
                else if (itemType == typeof(long))
                {
                    result = long.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(double))
                {
                    result = double.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(sbyte))
                {
                    result = sbyte.Parse(str, CultureInfo.InvariantCulture);
                }
                else
                {
                    if (itemType.IsEnum)
                    {
                        try
                        {
                            result = Enum.Parse(itemType, str);
                            return(result);
                        }
                        catch (ArgumentException innerException)
                        {
                            string text = string.Concat(new object[]
                            {
                                "'",
                                str,
                                "' is not a valid value for ",
                                itemType,
                                ". Valid values are: \n"
                            });
                            text += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                            ArgumentException ex = new ArgumentException(text, innerException);
                            throw ex;
                        }
                    }
                    if (itemType == typeof(Type))
                    {
                        if (str == "null" || str == "Null")
                        {
                            result = null;
                        }
                        else
                        {
                            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
                            if (typeInAnyAssembly == null)
                            {
                                Log.Error("Could not find a type named " + str);
                            }
                            result = typeInAnyAssembly;
                        }
                    }
                    else if (itemType == typeof(Action))
                    {
                        string[] array = str.Split(new char[]
                        {
                            '.'
                        });
                        string methodName = array[array.Length - 1];
                        string typeName   = string.Empty;
                        if (array.Length == 3)
                        {
                            typeName = array[0] + "." + array[1];
                        }
                        else
                        {
                            typeName = array[0];
                        }
                        Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(typeName);
                        MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
                        result = (Action)Delegate.CreateDelegate(typeof(Action), method);
                    }
                    else if (itemType == typeof(Vector3))
                    {
                        result = ParseHelper.FromStringVector3(str);
                    }
                    else if (itemType == typeof(Vector2))
                    {
                        result = ParseHelper.FromStringVector2(str);
                    }
                    else if (itemType == typeof(Rect))
                    {
                        result = ParseHelper.FromStringRect(str);
                    }
                    else if (itemType == typeof(Color))
                    {
                        str = str.TrimStart(new char[]
                        {
                            '(',
                            'R',
                            'G',
                            'B',
                            'A'
                        });
                        str = str.TrimEnd(new char[]
                        {
                            ')'
                        });
                        string[] array2 = str.Split(new char[]
                        {
                            ','
                        });
                        float num  = (float)ParseHelper.FromString(array2[0], typeof(float));
                        float num2 = (float)ParseHelper.FromString(array2[1], typeof(float));
                        float num3 = (float)ParseHelper.FromString(array2[2], typeof(float));
                        bool  flag = num > 1f || num3 > 1f || num2 > 1f;
                        float num4 = (float)((!flag) ? 1 : 255);
                        if (array2.Length == 4)
                        {
                            num4 = (float)ParseHelper.FromString(array2[3], typeof(float));
                        }
                        Color color;
                        if (!flag)
                        {
                            color.r = num;
                            color.g = num2;
                            color.b = num3;
                            color.a = num4;
                        }
                        else
                        {
                            color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
                        }
                        result = color;
                    }
                    else if (itemType == typeof(PublishedFileId_t))
                    {
                        result = new PublishedFileId_t(ulong.Parse(str));
                    }
                    else if (itemType == typeof(IntVec2))
                    {
                        result = IntVec2.FromString(str);
                    }
                    else if (itemType == typeof(IntVec3))
                    {
                        result = IntVec3.FromString(str);
                    }
                    else if (itemType == typeof(Rot4))
                    {
                        result = Rot4.FromString(str);
                    }
                    else if (itemType == typeof(CellRect))
                    {
                        result = CellRect.FromString(str);
                    }
                    else
                    {
                        if (itemType != typeof(CurvePoint))
                        {
                            if (itemType == typeof(NameTriple))
                            {
                                NameTriple nameTriple = NameTriple.FromString(str);
                                nameTriple.ResolveMissingPieces(null);
                            }
                            else
                            {
                                if (itemType == typeof(FloatRange))
                                {
                                    result = FloatRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(IntRange))
                                {
                                    result = IntRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(QualityRange))
                                {
                                    result = QualityRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(ColorInt))
                                {
                                    str = str.TrimStart(new char[]
                                    {
                                        '(',
                                        'R',
                                        'G',
                                        'B',
                                        'A'
                                    });
                                    str = str.TrimEnd(new char[]
                                    {
                                        ')'
                                    });
                                    string[] array3 = str.Split(new char[]
                                    {
                                        ','
                                    });
                                    ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                                    colorInt.r = (int)ParseHelper.FromString(array3[0], typeof(int));
                                    colorInt.g = (int)ParseHelper.FromString(array3[1], typeof(int));
                                    colorInt.b = (int)ParseHelper.FromString(array3[2], typeof(int));
                                    if (array3.Length == 4)
                                    {
                                        colorInt.a = (int)ParseHelper.FromString(array3[3], typeof(int));
                                    }
                                    else
                                    {
                                        colorInt.a = 255;
                                    }
                                    result = colorInt;
                                    return(result);
                                }
                            }
                            throw new ArgumentException(string.Concat(new string[]
                            {
                                "Trying to parse to unknown data type ",
                                itemType.Name,
                                ". Content is '",
                                str,
                                "'."
                            }));
                        }
                        result = CurvePoint.FromString(str);
                    }
                }
            }
            catch (Exception innerException2)
            {
                ArgumentException ex2 = new ArgumentException(string.Concat(new object[]
                {
                    "Exception parsing ",
                    itemType,
                    " from \"",
                    str,
                    "\""
                }), innerException2);
                throw ex2;
            }
            return(result);
        }
예제 #29
0
 public static object FromString(string str, Type itemType)
 {
     try
     {
         itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
         if (itemType == typeof(string))
         {
             str = str.Replace("\\n", "\n");
             return(str);
         }
         if (itemType == typeof(int))
         {
             return(ParseIntPermissive(str));
         }
         if (itemType == typeof(float))
         {
             return(float.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(bool))
         {
             return(bool.Parse(str));
         }
         if (itemType == typeof(long))
         {
             return(long.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(double))
         {
             return(double.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(sbyte))
         {
             return(sbyte.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType.IsEnum)
         {
             try
             {
                 object obj = BackCompatibility.BackCompatibleEnum(itemType, str);
                 if (obj != null)
                 {
                     return(obj);
                 }
                 return(Enum.Parse(itemType, str));
             }
             catch (ArgumentException innerException)
             {
                 string str2 = "'" + str + "' is not a valid value for " + itemType + ". Valid values are: \n";
                 str2 += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                 ArgumentException ex = new ArgumentException(str2, innerException);
                 throw ex;
             }
         }
         if (itemType == typeof(Type))
         {
             if (str == "null" || str == "Null")
             {
                 return(null);
             }
             Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
             if (typeInAnyAssembly == null)
             {
                 Log.Error("Could not find a type named " + str);
             }
             return(typeInAnyAssembly);
         }
         if (itemType == typeof(Action))
         {
             string[] array      = str.Split('.');
             string   methodName = array[array.Length - 1];
             string   empty      = string.Empty;
             empty = ((array.Length != 3) ? array[0] : (array[0] + "." + array[1]));
             Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(empty);
             MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
             return((Action)Delegate.CreateDelegate(typeof(Action), method));
         }
         if (itemType == typeof(Vector3))
         {
             return(FromStringVector3(str));
         }
         if (itemType == typeof(Vector2))
         {
             return(FromStringVector2(str));
         }
         if (itemType == typeof(Rect))
         {
             return(FromStringRect(str));
         }
         if (itemType == typeof(Color))
         {
             str = str.TrimStart('(', 'R', 'G', 'B', 'A');
             str = str.TrimEnd(')');
             string[] array2 = str.Split(',');
             float    num    = (float)FromString(array2[0], typeof(float));
             float    num2   = (float)FromString(array2[1], typeof(float));
             float    num3   = (float)FromString(array2[2], typeof(float));
             bool     flag   = num > 1f || num3 > 1f || num2 > 1f;
             float    num4   = (float)((!flag) ? 1 : 255);
             if (array2.Length == 4)
             {
                 num4 = (float)FromString(array2[3], typeof(float));
             }
             Color color = default(Color);
             if (!flag)
             {
                 color.r = num;
                 color.g = num2;
                 color.b = num3;
                 color.a = num4;
             }
             else
             {
                 color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
             }
             return(color);
         }
         if (itemType == typeof(PublishedFileId_t))
         {
             return(new PublishedFileId_t(ulong.Parse(str)));
         }
         if (itemType == typeof(IntVec2))
         {
             return(IntVec2.FromString(str));
         }
         if (itemType == typeof(IntVec3))
         {
             return(IntVec3.FromString(str));
         }
         if (itemType == typeof(Rot4))
         {
             return(Rot4.FromString(str));
         }
         if (itemType == typeof(CellRect))
         {
             return(CellRect.FromString(str));
         }
         if (itemType != typeof(CurvePoint))
         {
             if (itemType == typeof(NameTriple))
             {
                 NameTriple nameTriple = NameTriple.FromString(str);
                 nameTriple.ResolveMissingPieces();
             }
             else
             {
                 if (itemType == typeof(FloatRange))
                 {
                     return(FloatRange.FromString(str));
                 }
                 if (itemType == typeof(IntRange))
                 {
                     return(IntRange.FromString(str));
                 }
                 if (itemType == typeof(QualityRange))
                 {
                     return(QualityRange.FromString(str));
                 }
                 if (itemType == typeof(ColorInt))
                 {
                     str = str.TrimStart('(', 'R', 'G', 'B', 'A');
                     str = str.TrimEnd(')');
                     string[] array3   = str.Split(',');
                     ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                     colorInt.r = (int)FromString(array3[0], typeof(int));
                     colorInt.g = (int)FromString(array3[1], typeof(int));
                     colorInt.b = (int)FromString(array3[2], typeof(int));
                     if (array3.Length == 4)
                     {
                         colorInt.a = (int)FromString(array3[3], typeof(int));
                     }
                     else
                     {
                         colorInt.a = 255;
                     }
                     return(colorInt);
                 }
             }
             throw new ArgumentException("Trying to parse to unknown data type " + itemType.Name + ". Content is '" + str + "'.");
         }
         return(CurvePoint.FromString(str));
     }
     catch (Exception innerException2)
     {
         ArgumentException ex2 = new ArgumentException("Exception parsing " + itemType + " from \"" + str + "\"", innerException2);
         throw ex2;
     }
 }
예제 #30
0
        public static Vector3 TrueCenter(IntVec3 loc, Rot4 rotation, IntVec2 thingSize, float altitude)
        {
            Vector3 result = loc.ToVector3ShiftedWithAltitude(altitude);

            if (thingSize.x != 1 || thingSize.z != 1)
            {
                if (rotation.IsHorizontal)
                {
                    int x = thingSize.x;
                    thingSize.x = thingSize.z;
                    thingSize.z = x;
                }
                switch (rotation.AsInt)
                {
                case 0:
                    if (thingSize.x % 2 == 0)
                    {
                        result.x += 0.5f;
                    }
                    if (thingSize.z % 2 == 0)
                    {
                        result.z += 0.5f;
                    }
                    break;

                case 1:
                    if (thingSize.x % 2 == 0)
                    {
                        result.x += 0.5f;
                    }
                    if (thingSize.z % 2 == 0)
                    {
                        result.z -= 0.5f;
                    }
                    break;

                case 2:
                    if (thingSize.x % 2 == 0)
                    {
                        result.x -= 0.5f;
                    }
                    if (thingSize.z % 2 == 0)
                    {
                        result.z -= 0.5f;
                    }
                    break;

                case 3:
                    if (thingSize.x % 2 == 0)
                    {
                        result.x -= 0.5f;
                    }
                    if (thingSize.z % 2 == 0)
                    {
                        result.z += 0.5f;
                    }
                    break;
                }
            }
            return(result);
        }