예제 #1
0
        public override void Initialize()
        {
            if (Instance != null)
            {
                Log("Warning: " + GetType().Name + " is a singleton. Trying to create more than one may cause issues!");
                return;
            }

            Instance = this;
            comms    = new CommunicationNode();
            comms.EnableNode(this);

            Log("Mod Common initializing!");

            SetupDefaulSettings();

            RegisterCallbacks();

            DevLog.Logger.Hide();

            // Setup and prepare the CanvasUtil fonts so that other mods can use them.
            CanvasUtil.CreateFonts();

            Log("Mod Common is done initializing!");
        }
예제 #2
0
        protected static void AddNode(CommunicationNode node)
        {
            //if the node has non-null connections, clear them by removing it before we process the insertion
            if (node.next != null || node.prev != null)
            {
                RemoveNode(node);
            }

            if (root == null)
            {
                root      = node;
                root.next = root;
                root.prev = root;
            }

            //add new nodes to the root
            CommunicationNode prev = root;
            CommunicationNode next = root.next;

            node.next = next;
            node.prev = prev;

            next.prev = node;
            prev.next = node;
        }
예제 #3
0
        protected static void RemoveNode(CommunicationNode node)
        {
            if (node.next != null)
            {
                node.next.prev = node.prev;
            }
            if (node.prev != null)
            {
                node.prev.next = node.next;
            }

            node.next = null;
            node.prev = null;

            if (root != null && root.next == null && root.prev == null)
            {
                root = null;
            }
        }
예제 #4
0
        protected static void DefaultPublish(object data, object publisher)
        {
            CommunicationNode current = root;

            List <CommunicationNode> orphanList = null;

            if (current != null)
            {
                do
                {
                    //keep track of orphaned nodes
                    if (current.NodeOwner == null)
                    {
                        if (orphanList == null)
                        {
                            orphanList = new List <CommunicationNode>();
                        }

                        orphanList.Add(current);
                        continue;
                    }

                    //prevent sources from publishing to themselves
                    if (current.NodeOwner != publisher)
                    {
                        current.InvokeMatchingCallback(data, publisher);
                    }

                    current = current.next;
                } while(current != root);
            }

            if (orphanList != null)
            {
                //remove/clean up orphaned nodes
                for (int i = 0; i < orphanList.Count; ++i)
                {
                    RemoveNode(orphanList[i]);
                }
            }
        }
예제 #5
0
        public virtual void EnableNode(object nodeOwner)
        {
            if (nodeOwner.GetType() == this.GetType())
            {
                //error: nodes themselves cannot be owners
                //TODO: throw assert
                DisableNode();
                return;
            }

            if (nodeOwner == null)
            {
                DisableNode();
                return;
            }

            this.NodeOwner = nodeOwner;

            CommunicationNode.AddNode(this);
            RefreshCallbackBindings();
        }
예제 #6
0
 public virtual void DisableNode()
 {
     CommunicationNode.RemoveNode(this);
     NodeOwner = null;
 }