Пример #1
0
        // FIXME: Revert here is just a mirrored copy if Apply.
        // We could make this less error prone by consolidating them into one thing?
        public void RevertTransaction(GateTransaction transaction)
        {
            if (transaction.RemoveComponent == false)
            {
                // Here we should revert a add transation, i.e. removing the component
                if (transaction.Gate.ID == 0)
                {
                    throw new InvalidOperationException("Cannot revert a transaction where the gates doesn't have a valid id! (Maybe you forgot to apply the transaction before?)");
                }

                if (LogLogic.RemoveComponent(Program.Backend, transaction.Gate.ID) == false)
                {
                    Console.WriteLine($"Warn: Rust said we couldn't remove this gate id: {transaction.Gate.ID}. ({transaction.Gate})");
                }

                if (Instances.Remove(transaction.Gate) == false)
                {
                    Console.WriteLine($"Warn: Removed non-existent gate! {transaction.Gate}");
                }
            }
            else
            {
                // Here we are reverting a delete, i.e. adding it back again
                transaction.Gate.ID = LogLogic.AddComponent(Program.Backend, transaction.Gate.Type);
                Instances.Add(transaction.Gate);
            }
        }
Пример #2
0
        public void ApplyTransaction(GateTransaction transaction)
        {
            if (transaction.RemoveComponent == false)
            {
                transaction.Gate.ID = LogLogic.AddComponent(Program.Backend, transaction.Gate.Type);

                Instances.Add(transaction.Gate);
            }
            else
            {
                if (transaction.Gate.ID == 0)
                {
                    throw new InvalidOperationException("Cannot delete a gate that doesn't have a valid id! (Maybe you forgot to apply the transaction before?)");
                }

                if (LogLogic.RemoveComponent(Program.Backend, transaction.Gate.ID) == false)
                {
                    Console.WriteLine($"RemoveComponent(Type: {transaction.Gate.ID}) -> false");
                    Console.WriteLine($"Warn: Rust said we couldn't remove this gate id: {transaction.Gate.ID}. ({transaction.Gate})");
                }
                else
                {
                    Console.WriteLine($"RemoveComponent(Type: {transaction.Gate.ID}) -> true");
                }

                if (Instances.Remove(transaction.Gate) == false)
                {
                    Console.WriteLine($"Warn: Removed non-existent gate! {transaction.Gate}");
                }
            }
        }
Пример #3
0
        public void RevertTransaction(GateTransaction transaction)
        {
            if (transaction.Created.ID == 0)
            {
                throw new InvalidOperationException("Cannot revert a transaction where the gates doesn't have a valid id! (Maybe you forgot to apply the transaction before?)");
            }

            if (Logic.RemoveComponent(Program.Backend, transaction.Created.ID) == false)
            {
                Console.WriteLine($"Warn: Rust said we couldn't remove this gate id: {transaction.Created.ID}. ({transaction.Created})");
            }

            if (Instances.Remove(transaction.Created) == false)
            {
                Console.WriteLine($"Warn: Removed non-existent gate! {transaction.Created}");
            }
        }
Пример #4
0
 public void ApplyTransaction(GateTransaction transaction)
 {
     transaction.Created.ID = Logic.AddComponent(Program.Backend, transaction.Created.Type);
     Instances.Add(transaction.Created);
 }