Beispiel #1
0
        public static PlaceBoardPacket BuildFromBoard(CircuitBoard board, Transform parent)
        {
            var netObj = board.GetComponent <NetObject>();

            if (netObj == null)
            {
                netObj       = board.gameObject.AddComponent <NetObject>();
                netObj.NetID = NetObject.GetNewID();
            }

            var packet = new PlaceBoardPacket
            {
                AuthorID      = NetworkClient.Instance.PlayerID,
                ParentBoardID = parent?.GetComponent <NetObject>()?.NetID ?? 0,
                Position      = board.transform.position,
                EulerAngles   = board.transform.eulerAngles
            };
            var savedObj = SavedObjectUtilities.CreateSavedObjectFrom(board.gameObject);

            using (var mem = new MemoryStream())
            {
                BinFormatter.Serialize(mem, savedObj);

                packet.SavedBoard = mem.ToArray();
            }

            return(packet);
        }
Beispiel #2
0
        public static void CheckObject(GameObject gameObject)
        {
            if (gameObject == null || gameObject.tag == "World" || gameObject.tag == "Wire" || gameObject.tag == "CircuitBoard")
            {
                return;
            }

            var savedObj = SavedObjectUtilities.CreateSavedObjectFrom(gameObject);
            var undoItem = new ComponentUndoItem
            {
                SavedObject = savedObj,
                Parent      = gameObject.transform.parent
            };

            foreach (var input in gameObject.GetComponentsInChildren <CircuitInput>())
            {
                undoItem.Wires.AddRange(input.IIConnections.Cast <Wire>());
                undoItem.Wires.AddRange(input.IOConnections.Cast <Wire>());
            }

            foreach (var input in gameObject.GetComponentsInChildren <CircuitOutput>())
            {
                undoItem.Wires.AddRange(input.GetIOConnections().Cast <Wire>());
            }

            UndoMod.UndoStack.Push(undoItem);
        }
    public static void SetMostRecentlyDeletedBoard(GameObject board)
    {
        if (!Directory.Exists(Application.persistentDataPath + "/backups"))
        {
            Directory.CreateDirectory(Application.persistentDataPath + "/backups");
        }
        if (!Directory.Exists(Application.persistentDataPath + "/backups/_____deletedboards"))
        {
            Directory.CreateDirectory(Application.persistentDataPath + "/backups/_____deletedboards");
        }

        // delete excess board backups
        string[] Backups = Directory.GetFiles(Application.persistentDataPath + "/backups/_____deletedboards");
        System.Array.Sort(Backups); // get it in alphabetical order, so oldest backups are at the start of the array
        int ExcessBackups = Backups.Length - MaxBoardBackups;

        for (int i = ExcessBackups - 2; i >= 0; i--)
        {
            File.Delete(Backups[i]);
        }

        SavedObjectV2 MostRecentlyDeletedBoard = SavedObjectUtilities.CreateSavedObjectFrom(board);              // only use the main thread for what's absolutely necessary

        LoadBoardMenu.Instance.StartCoroutineAsync(SaveMostRecentlyDeletedBoardAsync(MostRecentlyDeletedBoard)); // because it has to start on a monobehavior...
    }
Beispiel #4
0
        public static PlaceComponentPacket BuildFromLocalComponent(GameObject component)
        {
            var netObj = component.GetComponent<NetObject>();

            if (netObj == null)
            {
                netObj = component.AddComponent<NetObject>();
                netObj.NetID = NetObject.GetNewID();
                
                if (component.GetComponent<ObjectInfo>()?.ComponentType == ComponentType.Mount)
                {
                    var board = component.GetComponentInChildren<CircuitBoard>();
                    board.gameObject.AddComponent<NetObject>().NetID = NetObject.GetNewID();
                }
            }

            var objInfo = component.GetComponent<ObjectInfo>();

            int parentId = component.transform.parent?.GetComponent<NetObject>()?.NetID ?? 0;

            return new PlaceComponentPacket
            {
                NetID = netObj.NetID,
                SavedObject = SavedObjectUtilities.CreateSavedObjectFrom(objInfo),
                LocalPosition = component.transform.localPosition,
                EulerAngles = component.transform.localEulerAngles,
                ParentBoardID = parentId
            };
        }
Beispiel #5
0
    public void ConfirmSaveBoard()
    {
        if (BoardBeingSaved == null)
        {
            Done(); return;
        }

        SavedObjectV2 BoardSavedObject = SavedObjectUtilities.CreateSavedObjectFrom(BoardBeingSaved);

        FileUtilities.SaveToFile(Application.persistentDataPath + "/savedboards/", FileUtilities.ValidatedUniqueBoardName(BoardNameInput.text) + ".tungboard", BoardSavedObject);

        LoadBoardMenu.Instance.GenerateLoadBoardsMenu();
        Done();
    }
    public static List <SavedObjectV2> GetTopLevelObjects()
    {
        List <SavedObjectV2> TopLevelObjects = new List <SavedObjectV2>();

        foreach (ObjectInfo save in ActiveSaveObjects)
        {
            if (save.transform.parent == null)
            {
                TopLevelObjects.Add(SavedObjectUtilities.CreateSavedObjectFrom(save));
            }
        }

        return(TopLevelObjects);
    }