private static List <string> GetMapBase(IntVec2 size) { List <string> mapBaseWIP = new List <string>(); string mapBaseRow = ""; for (int x = 0; x < size.x; x++) { mapBaseRow += "."; } for (int y = 0; y < size.z; y++) { mapBaseWIP.Add(mapBaseRow); } return(mapBaseWIP); }
private static void FillDataList(Fluffy_Blueprint source, ref List <string> buildingDataList, ref List <string> floorDataList, ref Dictionary <string, string> mappingBuildingRotation2LegendKey, ref Dictionary <string, string> mappingFloor2LegendKey) { IntVec2 offset = source.size / 2; if (source.size.x % 2 != 0) { offset.x += 1; } if (source.size.z % 2 != 0) { offset.z += 1; } foreach (Fluffy_BlueprintElement element in source.contents) { if (element.ThingDef != null) { // found building ( + stuff? ) + rotation IntVec2 pos = element.Position.ToIntVec2 + offset; string c = null; foreach (KeyValuePair <string, string> kv in mappingBuildingRotation2LegendKey) { if (kv.Key == element.ThingDef + element.Rotation) { c = kv.Value; break; } } if (c == null) { continue; } string rowData = buildingDataList[pos.z - 1]; string pre, post, old = ""; old = rowData.Substring(pos.x - 1, 1); if (old != ".") { continue; // Here is already something! Do not replace it (first entry remains)! } pre = rowData.Substring(0, pos.x - 1); post = rowData.Substring(pos.x); rowData = pre + c + post; buildingDataList[pos.z - 1] = rowData; } else if (element.TerrainDef != null) { // found floor IntVec2 pos = element.Position.ToIntVec2 + offset; string c = null; foreach (KeyValuePair <string, string> kv in mappingFloor2LegendKey) { if (kv.Key == element.TerrainDef) { c = kv.Value; break; } } if (c == null) { continue; } string rowData = floorDataList[pos.z - 1]; string pre, post, old = ""; old = rowData.Substring(pos.x - 1, 1); if (old != ".") { continue; // Here is already something! Do not replace it (first entry remains)! } pre = rowData.Substring(0, pos.x - 1); post = rowData.Substring(pos.x); rowData = pre + c + post; floorDataList[pos.z - 1] = rowData; } } }
public static object FromString(string str, Type itemType) { object result = ""; try { 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) { throw innerException; } } else if (itemType == typeof(Vector3)) { result = Helper_Parsing.FromStringVector3(str); } else if (itemType == typeof(Vector2)) { result = Helper_Parsing.FromStringVector2(str); } else if (itemType == typeof(Rect)) { result = Helper_Parsing.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)Helper_Parsing.FromString(array2[0], typeof(float)); float num2 = (float)Helper_Parsing.FromString(array2[1], typeof(float)); float num3 = (float)Helper_Parsing.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)Helper_Parsing.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 { // Nothing compatible found? Handle as if it is a string. str = str.Replace("\\n", "\n"); result = str; } //else //{ //if (itemType != typeof(CellRect)) //{ // 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)Helper_Parsing.FromString(array3[0], typeof(int)); // colorInt.g = (int)Helper_Parsing.FromString(array3[1], typeof(int)); // colorInt.b = (int)Helper_Parsing.FromString(array3[2], typeof(int)); // if (array3.Length == 4) // { // colorInt.a = (int)Helper_Parsing.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 = CellRect.FromString(str); //} } } catch (Exception innerException2) { ArgumentException ex2 = new ArgumentException(string.Concat(new object[] { "Exception parsing ", itemType, " from \"", str, "\"" }), innerException2); throw ex2; } return(result); }
public static Rot4 FromIntVec2(IntVec2 offset) { return(Rot4.FromIntVec3(offset.ToIntVec3)); }