public void WriteBinary(BinaryWriter binaryWriter) { binaryWriter.Write(Offset.X); binaryWriter.Write(Offset.y); binaryWriter.Write(BuildingDef.PrefabID); binaryWriter.Write(SelectedElements.Count); SelectedElements.ForEach(selectedElement => binaryWriter.Write(selectedElement.GetHash())); binaryWriter.Write((int)Orientation); binaryWriter.Write(Flags); }
/// <summary> /// Writes the building config to the given JSON writer. /// Doesn't write unnecessary information to save space. /// </summary> /// <param name="jsonWriter">The <see cref="JsonWriter"/> encsapsulating the stream to write to</param> public void WriteJSON(JsonWriter jsonWriter) { if (BuildingDef == null) { Debug.Log("Error when writing building config: No building definition."); return; } jsonWriter.WriteStartObject(); if (Offset.x != 0 || Offset.y != 0) { jsonWriter.WritePropertyName("offset"); jsonWriter.WriteStartObject(); if (Offset.x != 0) { jsonWriter.WritePropertyName("x"); jsonWriter.WriteValue(Offset.x); } if (Offset.y != 0) { jsonWriter.WritePropertyName("y"); jsonWriter.WriteValue(Offset.y); } jsonWriter.WriteEndObject(); } jsonWriter.WritePropertyName("buildingdef"); jsonWriter.WriteValue(BuildingDef.PrefabID); jsonWriter.WritePropertyName("selected_elements"); jsonWriter.WriteStartArray(); SelectedElements.ForEach(elementTag => jsonWriter.WriteValue(elementTag.GetHash())); jsonWriter.WriteEndArray(); if (Orientation != 0) { jsonWriter.WritePropertyName("orientation"); jsonWriter.WriteValue((int)Orientation); } if (Flags != 0) { jsonWriter.WritePropertyName("flags"); jsonWriter.WriteValue(Flags); } jsonWriter.WriteEndObject(); }
public void WriteBinary(BinaryWriter binaryWriter) { if (BuildingDef == null) { Debug.Log("Error when writing building config: No building definition."); return; } binaryWriter.Write(Offset.X); binaryWriter.Write(Offset.y); binaryWriter.Write(BuildingDef.PrefabID); binaryWriter.Write(SelectedElements.Count); SelectedElements.ForEach(selectedElement => binaryWriter.Write(selectedElement.GetHash())); binaryWriter.Write((int)Orientation); binaryWriter.Write(Flags); }
public void WriteJSON(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("offset"); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("x"); jsonWriter.WriteValue(Offset.x); jsonWriter.WritePropertyName("y"); jsonWriter.WriteValue(Offset.y); jsonWriter.WriteEndObject(); jsonWriter.WritePropertyName("buildingdef"); jsonWriter.WriteValue(BuildingDef.PrefabID); jsonWriter.WritePropertyName("selected_elements"); jsonWriter.WriteStartArray(); SelectedElements.ForEach(elementTag => jsonWriter.WriteValue(elementTag.GetHash())); jsonWriter.WriteEndArray(); jsonWriter.WritePropertyName("orientation"); jsonWriter.WriteValue((int)Orientation); jsonWriter.WritePropertyName("flags"); jsonWriter.WriteValue(Flags); jsonWriter.WriteEndObject(); }