// Copy Constructor -- don't call this directly, unless we never // do ANY sub-classing. Instead use Clone(), which is more virtual. private Furniture(Furniture other) { Type = other.Type; Name = other.Name; typeTags = new HashSet <string>(other.typeTags); description = other.description; MovementCost = other.MovementCost; PathfindingModifier = other.PathfindingModifier; PathfindingWeight = other.PathfindingWeight; RoomEnclosure = other.RoomEnclosure; Width = other.Width; Height = other.Height; Tint = other.Tint; LinksToNeighbour = other.LinksToNeighbour; JobSpotOffset = other.JobSpotOffset; jobSpawnSpotOffset = other.jobSpawnSpotOffset; workshop = other.workshop; // don't need to clone here, as all are prototype things (not changing) furnParameters = new Parameter(other.furnParameters); jobs = new List <Job>(); pausedJobs = new List <Job>(); if (other.Animation != null) { Animation = other.Animation.Clone(); } if (other.EventActions != null) { EventActions = other.EventActions.Clone(); } if (other.contextMenuLuaActions != null) { contextMenuLuaActions = new List <ContextMenuLuaAction>(other.contextMenuLuaActions); } isEnterableAction = other.isEnterableAction; getSpriteNameAction = other.getSpriteNameAction; if (other.PowerConnection != null) { PowerConnection = other.PowerConnection.Clone() as Connection; World.Current.PowerNetwork.PlugIn(PowerConnection); PowerConnection.NewThresholdReached += OnNewThresholdReached; } if (other.funcPositionValidation != null) { funcPositionValidation = (Func <Tile, bool>)other.funcPositionValidation.Clone(); } tileTypeBuildPermissions = new HashSet <string>(other.tileTypeBuildPermissions); LocalizationCode = other.LocalizationCode; UnlocalizedDescription = other.UnlocalizedDescription; }
public void TestSerialization() { FurnitureWorkshop fi = new FurnitureWorkshop(); fi.PossibleProductions = new System.Collections.Generic.List <FurnitureWorkshop.ProductionChain>(); var chain1 = new FurnitureWorkshop.ProductionChain() { Name = "Iron smelting", ProcessingTime = 4.0f }; chain1.Input = new System.Collections.Generic.List <FurnitureWorkshop.Item>(); chain1.Input.Add(new FurnitureWorkshop.Item() { ObjectType = "Raw Iron", Amount = 3, SlotPosX = 0, SlotPosY = 0 }); chain1.Output = new System.Collections.Generic.List <FurnitureWorkshop.Item>(); chain1.Output.Add(new FurnitureWorkshop.Item() { ObjectType = "Steel Plate", Amount = 3, SlotPosX = 2, SlotPosY = 0 }); fi.PossibleProductions.Add(chain1); var chain2 = new FurnitureWorkshop.ProductionChain() { Name = "Copper smelting", ProcessingTime = 3.0f }; chain2.Input = new System.Collections.Generic.List <FurnitureWorkshop.Item>(); chain2.Input.Add(new FurnitureWorkshop.Item() { ObjectType = "Raw Copper", Amount = 3, SlotPosX = 0, SlotPosY = 0 }); chain2.Output = new System.Collections.Generic.List <FurnitureWorkshop.Item>(); chain2.Output.Add(new FurnitureWorkshop.Item() { ObjectType = "Copper Wire", Amount = 6, SlotPosX = 2, SlotPosY = 0 }); fi.PossibleProductions.Add(chain2); FileStream fs = new FileStream("Workshop.xml", FileMode.Create); TextWriter writer = new StreamWriter(fs, new UTF8Encoding()); XmlSerializer serializer = new XmlSerializer(typeof(FurnitureWorkshop)); serializer.Serialize(writer, fi); writer.Close(); FileStream fr = new FileStream("Workshop.xml", FileMode.Open); var dfi = (FurnitureWorkshop)serializer.Deserialize(fr); Assert.NotNull(dfi); Assert.AreEqual("Raw Iron", dfi.PossibleProductions[0].Input[0].ObjectType); }
/// <summary> /// Reads the prototype furniture from XML. /// </summary> /// <param name="readerParent">The XML reader to read from.</param> public void ReadXmlPrototype(XmlReader readerParent) { Type = readerParent.GetAttribute("type"); XmlReader reader = readerParent.ReadSubtree(); while (reader.Read()) { switch (reader.Name) { case "Name": reader.Read(); Name = reader.ReadContentAsString(); break; case "TypeTag": reader.Read(); typeTags.Add(reader.ReadContentAsString()); break; case "Description": reader.Read(); description = reader.ReadContentAsString(); break; case "MovementCost": reader.Read(); MovementCost = reader.ReadContentAsFloat(); break; case "PathfindingModifier": reader.Read(); PathfindingModifier = reader.ReadContentAsFloat(); break; case "PathfindingWeight": reader.Read(); PathfindingWeight = reader.ReadContentAsFloat(); break; case "Width": reader.Read(); Width = reader.ReadContentAsInt(); break; case "Height": reader.Read(); Height = reader.ReadContentAsInt(); break; case "LinksToNeighbours": reader.Read(); LinksToNeighbour = reader.ReadContentAsBoolean(); break; case "EnclosesRooms": reader.Read(); RoomEnclosure = reader.ReadContentAsBoolean(); break; case "CanReplaceFurniture": replaceableFurniture.Add(reader.GetAttribute("typeTag").ToString()); break; case "DragType": reader.Read(); DragType = reader.ReadContentAsString(); break; case "BuildingJob": float jobTime = float.Parse(reader.GetAttribute("jobTime")); List <Inventory> invs = new List <Inventory>(); XmlReader inventoryReader = reader.ReadSubtree(); while (inventoryReader.Read()) { if (inventoryReader.Name == "Inventory") { // Found an inventory requirement, so add it to the list! invs.Add(new Inventory( inventoryReader.GetAttribute("type"), int.Parse(inventoryReader.GetAttribute("amount")), 0)); } } Job j = new Job( null, Type, FunctionsManager.JobComplete_FurnitureBuilding, jobTime, invs.ToArray(), Job.JobPriority.High); j.JobDescription = "job_build_" + Type + "_desc"; PrototypeManager.FurnitureJob.Set(Type, j); break; case "CanBeBuiltOn": tileTypeBuildPermissions.Add(reader.GetAttribute("tileType")); break; case "Animations": XmlReader animationReader = reader.ReadSubtree(); ReadAnimationXml(animationReader); break; case "Action": XmlReader subtree = reader.ReadSubtree(); EventActions.ReadXml(subtree); subtree.Close(); break; case "ContextMenuAction": contextMenuLuaActions.Add(new ContextMenuLuaAction { LuaFunction = reader.GetAttribute("FunctionName"), Text = reader.GetAttribute("Text"), RequiereCharacterSelected = bool.Parse(reader.GetAttribute("RequiereCharacterSelected")), DevModeOnly = bool.Parse(reader.GetAttribute("DevModeOnly") ?? "false") }); break; case "IsEnterable": isEnterableAction = reader.GetAttribute("FunctionName"); break; case "GetSpriteName": getSpriteNameAction = reader.GetAttribute("FunctionName"); break; case "JobSpotOffset": JobSpotOffset = new Vector2( int.Parse(reader.GetAttribute("X")), int.Parse(reader.GetAttribute("Y"))); break; case "JobSpawnSpotOffset": jobSpawnSpotOffset = new Vector2( int.Parse(reader.GetAttribute("X")), int.Parse(reader.GetAttribute("Y"))); break; case "PowerConnection": PowerConnection = new Connection(); PowerConnection.ReadPrototype(reader); break; case "Params": ReadXmlParams(reader); // Read in the Param tag break; case "LocalizationCode": reader.Read(); LocalizationCode = reader.ReadContentAsString(); break; case "UnlocalizedDescription": reader.Read(); UnlocalizedDescription = reader.ReadContentAsString(); break; case "Workshop": workshop = FurnitureWorkshop.Deserialize(reader); workshop.SetParentFurniture(this); workshop.Initialize(); break; } } }