public void TestDeconstructXmlSerialization()
    {
        Deconstruct deconstructOrder = new Deconstruct();

        deconstructOrder.JobTime   = 1;
        deconstructOrder.Inventory = new Dictionary <string, int>()
        {
            { "Steel Plate", 5 },
            { "Copper Plate", 2 }
        };

        // serialize
        StringWriter  writer     = new StringWriter();
        XmlSerializer serializer = new XmlSerializer(typeof(OrderAction), new Type[] { typeof(Deconstruct) });

        serializer.Serialize(writer, deconstructOrder);

        StringReader sr = new StringReader(writer.ToString());

        // if you want to dump file to disk for visual check, uncomment this
        ////File.WriteAllText("Deconstruct.xml", writer.ToString());

        // deserialize
        Deconstruct deserializedDeconstructOrder = (Deconstruct)serializer.Deserialize(sr);

        Assert.NotNull(deserializedDeconstructOrder);
        Assert.IsTrue(deserializedDeconstructOrder.Inventory.ContainsKey("Copper Plate"));
    }
    /// <summary>
    /// Sets the furniture to be deconstructed.
    /// </summary>
    public void SetDeconstructJob()
    {
        if (SettingsKeyHolder.DeveloperMode)
        {
            Deconstruct();
            return;
        }

        if (IsBeingDestroyed)
        {
            return; // Already being destroyed, don't do anything more
        }

        IsBeingDestroyed = true;
        Jobs.CancelAll();

        Deconstruct deconstructOrder = GetOrderAction <Deconstruct>();

        if (deconstructOrder != null)
        {
            Job job = deconstructOrder.CreateJob(Tile, Type);
            job.OnJobCompleted += (inJob) => Deconstruct();
            World.Current.jobQueue.Enqueue(job);
        }
    }
Exemple #3
0
    /// <summary>
    /// Deconstructs the utility.
    /// </summary>
    public void Deconstruct()
    {
        if (Tile.Utilities != null)
        {
            Jobs.CancelAll();
        }

        // Just unregister our grid, it will get reregistered if there are any other utilities on this grid
        World.Current.PowerNetwork.RemoveGrid(Grid);

        // We call lua to decostruct
        EventActions.Trigger("OnUninstall", this);
        Tile.UnplaceUtility(this);

        if (Removed != null)
        {
            Removed(this);
        }

        Deconstruct deconstructOrder = GetOrderAction <Deconstruct>();

        if (deconstructOrder != null)
        {
            foreach (KeyValuePair <string, int> inv in deconstructOrder.Inventory)
            {
                World.Current.InventoryManager.PlaceInventoryAround(Tile, new Inventory(inv.Key, inv.Value));
            }
        }

        // We should inform our neighbours that they have just lost a neighbour.
        // Just trigger their OnChangedCallback.
        foreach (Tile neighbor in Tile.GetNeighbours())
        {
            if (neighbor.Utilities != null && neighbor.Utilities.ContainsKey(this.Type))
            {
                Utility neighborUtility = neighbor.Utilities[this.Type];
                if (neighborUtility.Changed != null)
                {
                    neighborUtility.Changed(neighborUtility);
                }

                if (neighborUtility.Grid == this.Grid)
                {
                    neighborUtility.Grid = new UtilityGrid();
                }

                neighborUtility.UpdateGrid(neighborUtility);
                neighborUtility.Grid.Split();
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
Exemple #4
0
    public void TestDeconstructSerialization()
    {
        Deconstruct deconstructOrder = new Deconstruct();

        deconstructOrder.JobTime   = 1;
        deconstructOrder.Inventory = new Dictionary <string, int>()
        {
            { "Steel Plate", 5 },
            { "Copper Plate", 2 }
        };

        string      serialized   = JsonConvert.SerializeObject(deconstructOrder);
        Deconstruct deserialized = JsonConvert.DeserializeObject <Deconstruct>(serialized);

        Assert.NotNull(deserialized);
        Assert.IsTrue(deserialized.JobTime == deconstructOrder.JobTime);
        Assert.AreEqual(deserialized.Inventory["Steel Plate"], deconstructOrder.Inventory["Steel Plate"]);
        Assert.AreEqual(deserialized.Inventory["Copper Plate"], deconstructOrder.Inventory["Copper Plate"]);
    }
Exemple #5
0
    public void TestDeconstructXmlSerialization()
    {
        Deconstruct deconstructOrder = new Deconstruct();

        deconstructOrder.JobInfo = new OrderAction.JobInformation()
        {
            Time = 1
        };
        deconstructOrder.Inventory = new List <OrderAction.InventoryInfo>()
        {
            new OrderAction.InventoryInfo()
            {
                Type   = "Steel Plate",
                Amount = 5
            },
            new OrderAction.InventoryInfo()
            {
                Type   = "Copper Plate",
                Amount = 2
            }
        };

        // serialize
        StringWriter  writer     = new StringWriter();
        XmlSerializer serializer = new XmlSerializer(typeof(OrderAction), new Type[] { typeof(Deconstruct) });

        serializer.Serialize(writer, deconstructOrder);

        StringReader sr = new StringReader(writer.ToString());

        // if you want to dump file to disk for visual check, uncomment this
        ////File.WriteAllText("Deconstruct.xml", writer.ToString());

        // deserialize
        Deconstruct deserializedDeconstructOrder = (Deconstruct)serializer.Deserialize(sr);

        Assert.NotNull(deserializedDeconstructOrder);
        Assert.AreEqual("Copper Plate", deserializedDeconstructOrder.Inventory[1].Type);
    }
    /// <summary>
    /// Deconstructs the furniture.
    /// </summary>
    public void Uninstall()
    {
        int    x                = Tile.X;
        int    y                = Tile.Y;
        int    fwidth           = 1;
        int    fheight          = 1;
        string linksToNeighbour = string.Empty;

        if (Tile.Furniture != null)
        {
            Furniture furniture = Tile.Furniture;
            fwidth           = furniture.Width;
            fheight          = furniture.Height;
            linksToNeighbour = furniture.LinksToNeighbour;
            furniture.Jobs.CancelAll();
        }

        // We call lua to decostruct
        EventActions.Trigger("OnUninstall", this);

        // Let our workspot tile know it is no longer reserved for us
        World.Current.UnreserveTileAsWorkSpot(this);

        Tile.UnplaceFurniture();

        Deconstruct deconstructOrder = GetOrderAction <Deconstruct>();

        if (deconstructOrder != null)
        {
            World.Current.InventoryManager.PlaceInventoryAround(Tile, new Inventory(Type, 1));
        }

        if (Removed != null)
        {
            Removed(this);
        }

        // Do we need to recalculate our rooms?
        if (RoomEnclosure)
        {
            World.Current.RoomManager.DoRoomFloodFill(Tile, false);
        }

        ////World.current.InvalidateTileGraph();

        if (World.Current.tileGraph != null)
        {
            World.Current.tileGraph.RegenerateGraphAtTile(Tile);
        }

        // We should inform our neighbours that they have just lost a
        // neighbour regardless of type.
        // Just trigger their OnChangedCallback.
        if (linksToNeighbour != string.Empty)
        {
            for (int xpos = x - 1; xpos < x + fwidth + 1; xpos++)
            {
                for (int ypos = y - 1; ypos < y + fheight + 1; ypos++)
                {
                    Tile t = World.Current.GetTileAt(xpos, ypos, Tile.Z);
                    if (t != null && t.Furniture != null && t.Furniture.Changed != null)
                    {
                        t.Furniture.Changed(t.Furniture);
                    }
                }
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
Exemple #7
0
 public static Deconstruct Detach <T>(this Deconstruct deconstruct, out T value, out int length)
 {
     value = deconstruct.Detach <T>(out length);
     return(deconstruct);
 }
Exemple #8
0
 public static Deconstruct Detach <T>(this Deconstruct deconstruct, out T value)
 {
     return(deconstruct.Detach(out value, out _));
 }