Ejemplo n.º 1
0
        public NodeData(NodeData node, bool keepId = false)
        {
            m_name             = node.m_name;
            m_x                = node.m_x;
            m_y                = node.m_y;
            m_nodeNeedsRevisit = false;
            m_inputPoints      = new List <ConnectionPointData>();
            m_outputPoints     = new List <ConnectionPointData>();

            if (keepId)
            {
                m_id = node.m_id;

                node.InputPoints.ForEach(p => m_inputPoints.Add(new ConnectionPointData(p)));
                node.OutputPoints.ForEach(p => m_outputPoints.Add(new ConnectionPointData(p)));

                m_nodeInstance = new NodeInstance(node.m_nodeInstance);
            }
            else
            {
                m_id = Guid.NewGuid().ToString();

                Node n = node.m_nodeInstance.Object.Clone(this);
                m_nodeInstance = new NodeInstance(n);
            }
        }
Ejemplo n.º 2
0
        public NodeData(V1.NodeData v1)
        {
            //TODO:
            m_id               = v1.Id;
            m_name             = v1.Name;
            m_x                = v1.X;
            m_y                = v1.Y;
            m_nodeNeedsRevisit = false;

            m_inputPoints  = new List <ConnectionPointData>();
            m_outputPoints = new List <ConnectionPointData>();

            foreach (var input in v1.InputPoints)
            {
                m_inputPoints.Add(new ConnectionPointData(input));
            }

            foreach (var output in v1.OutputPoints)
            {
                m_outputPoints.Add(new ConnectionPointData(output));
            }

            Node n = CreateNodeFromV1NodeData(v1, this);

            m_nodeInstance = new NodeInstance(n);
        }
Ejemplo n.º 3
0
        private bool?CanUnlockTechTreeNodePath(BasePlayer player, NodeInstance node, TechTreeData techTree)
        {
            if (HasPermissionToUnlockAny(player, techTree))
            {
                return(true);
            }

            var blueprintRuleset = _pluginConfig.GetPlayerBlueprintRuleset(player.UserIDString);

            if (blueprintRuleset == null)
            {
                return(null);
            }

            if (node.itemDef != null && !blueprintRuleset.HasPrerequisites(node.itemDef))
            {
                return(true);
            }

            if (HasUnlockPath(player, node, techTree, blueprintRuleset))
            {
                return(true);
            }

            return(null);
        }
Ejemplo n.º 4
0
        public Task LoadDriverFactory(NodeInstance nodeInstance, IDriverFactory factory, IDriverContext context)
        {
            var driver = factory.CreateDriver(context);

            nodeInstance.State = NodeInstanceState.Loaded;
            if (driver.BeforeInit())
            {
                _driverStore.Add(driver.Id, driver);
                nodeInstance.State = NodeInstanceState.Initialized;
                driver.Configure();
            }
            else
            {
                nodeInstance.State = NodeInstanceState.UnknownError;
            }

            _driverNodeStore.Add(driver.Id, driver);
            for (int i = 0; i <= driver.ChildrensCreated; ++i)
            {
                _licenseContract.IncrementDriverCount();
            }


            AddDriverRecursive(driver);
            return(Task.CompletedTask);
        }
Ejemplo n.º 5
0
 public void Add(Trending value, NodeInstance nodeInstance)
 {
     using var context = new AutomaticaContext(_config);
     _logger.LogInformation($"Save trend for {nodeInstance.Name} ({nodeInstance.ObjId}) with value {value.Value}...");
     context.Add(value);
     context.SaveChanges();
 }
Ejemplo n.º 6
0
        private GraphicInstance CreateGraphicVisualizedInstance(Type type, LogicalInstance logicalInstance, DragEventArgs args)
        {
            Point           position        = args.GetPosition(this);
            double          width           = (double)type.GetProperty("Width").GetValue(Activator.CreateInstance(type), null);
            double          height          = (double)type.GetProperty("Height").GetValue(Activator.CreateInstance(type), null);
            GraphicInstance graphicInstance = null;

            if (type.IsSubclassOf(typeof(NodeType)))
            {
                ParentableInstance parent = (this.Content as CanvasItemsControl).FindParent(position, graphicInstance);
                graphicInstance = new NodeInstance
                {
                    X               = position.X,
                    Y               = position.Y,
                    Width           = (width != 0 && !double.IsNaN(width)) ? width : 200,
                    Height          = (height != 0 && !double.IsNaN(height)) ? height : 200,
                    LogicalInstance = logicalInstance,
                    Parent          = parent
                };
            }
            else
            {
                graphicInstance = new EdgeInstance
                {
                    X               = position.X,
                    Y               = position.Y,
                    Width           = (width != 0 && !double.IsNaN(width)) ? width : 200,
                    Height          = (height != 0 && !double.IsNaN(height)) ? height : 200,
                    LogicalInstance = logicalInstance,
                    Parent          = InstancesManager.Instance.CanvasRootElement
                };
            }
            return(graphicInstance);
        }
Ejemplo n.º 7
0
        public Task <IDriver> LoadDriverFactory(NodeInstance nodeInstance, IDriverFactory factory, IDriverContext context)
        {
            var driver = factory.CreateDriver(context);

            nodeInstance.State = NodeInstanceState.Loaded;
            try
            {
                if (driver.BeforeInit())
                {
                    _driverStore.Add(driver.Id, driver);
                    nodeInstance.State = NodeInstanceState.Initialized;
                    driver.Configure();
                }
                else
                {
                    nodeInstance.State = NodeInstanceState.UnknownError;
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error initialize driver {factory.DriverName}");
                nodeInstance.State = NodeInstanceState.UnknownError;
            }

            _driverNodeStore.AddChild(driver, driver);
            for (int i = 0; i <= driver.ChildrensCreated; ++i)
            {
                _licenseContract.IncrementDriverCount();
            }


            AddDriverRecursive(driver, driver);
            return(Task.FromResult(driver));
        }
Ejemplo n.º 8
0
        public static async Task <DriverNodeMock> CreateNodeMock(Guid guid, string name, IDispatcher dispatcher, INodeInstanceCache cache = null, IDriverNodesStore store = null)
        {
            var mockNode = new NodeInstance
            {
                ObjId = Guid.NewGuid(),
                Name  = name + "Parent"
            };
            var mockNodeChild = new NodeInstance
            {
                ObjId = guid,
                Name  = name
            };

            cache?.Add(mockNode.ObjId, mockNode);
            cache?.Add(mockNodeChild.ObjId, mockNodeChild);

            mockNode.InverseThis2ParentNodeInstanceNavigation.Add(mockNodeChild);
            var mock = new DriverNodeMock(new DriverContextMock(mockNode, new NodeTemplateFactoryMock(), dispatcher));

            mock.Configure();
            await mock.Start();

            store?.Add(mock.Id, mock);
            store?.Add(mock.Children[0].Id, mock.Children[0]);

            return(mock);
        }
Ejemplo n.º 9
0
        public Node CreateNode(T cargo)
        {
            Node node = new NodeInstance(cargo, this);

            this.nodes.Add(node);
            return(node);
        }
Ejemplo n.º 10
0
        private async Task StartInstance(string clientId, IDriverFactory factory, NodeInstance nodeInstance)
        {
            try
            {
                var actionRequests = new List <ActionRequest>();
                _logger.LogDebug($"Publish to slave/{clientId}/actions (Start {factory.ImageName}:{factory.Tag})");

                var actionRequest = new ActionRequest
                {
                    Action      = SlaveAction.Start,
                    ImageSource = factory.ImageSource,
                    ImageName   = factory.ImageName,
                    Tag         = factory.Tag,
                    Id          = nodeInstance.ObjId
                };

                actionRequests.Add(actionRequest);

                await SendAction(clientId, actionRequest);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Could not send start instances message...");
            }
        }
Ejemplo n.º 11
0
 public DriverContextMock(NodeInstance nodeInstance, INodeTemplateFactory nodeTemplateFactory)
 {
     NodeInstance        = nodeInstance;
     NodeTemplateFactory = nodeTemplateFactory;
     TelegramMonitor     = new TelegramMonitorMock();
     LicenseState        = new LicenseStateMock();
 }
Ejemplo n.º 12
0
        public async Task <NodeInstance> AddNode([FromBody] NodeInstance node)
        {
            var transaction = DbContext.Database.BeginTransaction();

            try
            {
                var entityState = await AddOrUpdateNodeInstance(node);

                await DbContext.SaveChangesAsync();

                await transaction.CommitAsync();

                _nodeInstanceCache.Clear();

                await ReloadDriver(node, entityState);

                return(_nodeInstanceCache.Get(node.ObjId));
            }
            catch (Exception e)
            {
                transaction.Rollback();
                SystemLogger.Instance.LogError(e, $"Could not {nameof(AddNode)} {nameof(NodeInstance)}", e);
                throw;
            }
        }
Ejemplo n.º 13
0
 private async Task ReloadDriver(NodeInstance node, EntityState entityState)
 {
     if (!node.This2ParentNodeInstance.HasValue)
     {
         return;
     }
     try
     {
         var nodeInstance = _nodeInstanceCache.Get(node.ObjId);
         if (entityState == EntityState.Added)
         {
             var nodeTemplate = _templateCache.Get(nodeInstance.This2NodeTemplate.Value);
             if (nodeTemplate.ProvidesInterface2InterfaceTypeNavigation.IsDriverInterface)
             {
                 await _coreServer.InitializeAndStartDriver(nodeInstance, nodeTemplate);
             }
             else
             {
                 await StopStartDriver(nodeInstance);
             }
         }
         else if (entityState == EntityState.Modified)
         {
             await StopStartDriver(nodeInstance);
         }
     }
     catch (Exception e)
     {
         SystemLogger.Instance.LogError(e, "Error hot-load driver..");
     }
 }
Ejemplo n.º 14
0
        // TODO: As per other comments, we need an actual model separate from the view!
        /// <summary>
        /// Recursively try to find where the symbol is defined in the tree.
        /// </summary>
        protected Symbol FindSymbolInTree(string symbol, TreeNodeCollection nodes)
        {
            Symbol ret = null;

            foreach (System.Windows.Forms.TreeNode node in nodes)
            {
                if (node.Text.LeftOf(':').Trim() == symbol)
                {
                    NodeInstance inst = (NodeInstance)node.Tag;
                    ret = (Symbol)inst.Instance.Item;
                    break;
                }
                else
                {
                    ret = FindSymbolInTree(symbol, node.Nodes);

                    if (ret != null)
                    {
                        break;
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Recursively copy the tree at src into dest.
        /// </summary>
        protected void CopyNodes(TreeNode dest, TreeNode src)
        {
            foreach (TreeNode childSrcNode in src.Nodes)
            {
                NodeInstance childInst       = (NodeInstance)childSrcNode.Tag;
                Symbol       childInstSymbol = (Symbol)childInst.Instance.Item;

                // Create a new controller.
                IXtreeNode controller = (IXtreeNode)Activator.CreateInstance(Type.GetType(childInst.NodeDef.TypeName), new object[] { false });
                // Create a new symbol.
                Symbol item = new Symbol()
                {
                    Name = childInstSymbol.Name, Structure = childInstSymbol.Structure
                };
                controller.Item = item;

                // Add the new symbol to the destination symbol collection.
                ((Symbol)((NodeInstance)dest.Tag).Instance.Item).Symbols.Add(item);

                TreeNode childDestNode = View.AddNode(controller, dest);

                // TODO: Yuck.  Clean this up so the model is king, and drives any controller, and remove the inc/dec from the respective view!
                ApplicationController.SymbolListController.IfNotNull(ctrl => ctrl.AddSymbol(item.Name)).Else(() => ApplicationModel.IncrementSymbolReference(item.Name));
                ApplicationController.StructureListController.IfNotNull(ctrl => ctrl.AddStructure(item.Structure)).Else(() => ApplicationModel.IncrementStructureReference(item.Structure));

                // Recurse.
                CopyNodes(childDestNode, childSrcNode);
            }
        }
Ejemplo n.º 16
0
 public void Disconnect()
 {
     if (to != null) {
         to.links[link.backLink].to = null;
         to = null;
     }
 }
Ejemplo n.º 17
0
        public static NodeInstance CreateNodeInstanceFromTemplate(NodeTemplate template)
        {
            var instance = new NodeInstance
            {
                ObjId       = Guid.NewGuid(),
                Name        = template.Name,
                Description = template.Description,
                This2NodeTemplateNavigation = template,
                This2NodeTemplate           = template.ObjId,
                IsWriteable = template.IsWriteable,
                IsReadable  = template.IsReadable
            };

            foreach (var prop in template.PropertyTemplate)
            {
                var propertyInstance = new PropertyInstance
                {
                    ObjId = Guid.NewGuid(),
                    This2NodeInstanceNavigation     = instance,
                    This2PropertyTemplateNavigation = prop,
                    This2PropertyTemplate           = prop.ObjId,
                    Value = prop.DefaultValue
                };
                instance.PropertyInstance.Add(propertyInstance);
            }

            return(instance);
        }
Ejemplo n.º 18
0
        private static bool HasUnlockPath(BasePlayer player, NodeInstance node, TechTreeData techTree, BlueprintRuleset blueprintRuleset)
        {
            if (node.inputs.Count == 0)
            {
                return(true);
            }

            var hasUnlockPath = false;

            foreach (var inputNodeId in node.inputs)
            {
                var inputNode = techTree.GetByID(inputNodeId);
                if (inputNode.itemDef == null)
                {
                    // This input node appears to be an entry node, so consider it unlocked.
                    return(true);
                }

                if (!techTree.HasPlayerUnlocked(player, inputNode) && !blueprintRuleset.IsOptional(inputNode.itemDef))
                {
                    // This input node does not provide an unlock path.
                    // Continue iterating the other input nodes in case they provide an unlock path.
                    continue;
                }

                if (HasUnlockPath(player, inputNode, techTree, blueprintRuleset))
                {
                    hasUnlockPath = true;
                }
            }

            return(hasUnlockPath);
        }
Ejemplo n.º 19
0
        protected IDriver CreateDriver(NodeInstance node)
        {
            var driverContext = new DriverContextMock(node, Factory, Dispatcher);
            var driver        = DriverFactory.CreateDriver(driverContext);

            driver.Configure();
            return(driver);
        }
Ejemplo n.º 20
0
 void Awake()
 {
     if (current == null) {
         current = Overlapper.FindClosestNode(unit);
         Debug.LogFormat("Current was null. Changed to closest node: {0}", current);
     }
     Init();
 }
Ejemplo n.º 21
0
        public async Task <ResultState> Read([FromBody] NodeInstance instance)
        {
            var result = await _notifyDriver.Read(instance);

            return(new ResultState
            {
                Result = result
            });
        }
Ejemplo n.º 22
0
 private void GetFullName(NodeInstance node, List <string> names)
 {
     if (node.This2ParentNodeInstanceNavigation == null)
     {
         return;
     }
     names.Add(node.This2ParentNodeInstanceNavigation.Name);
     GetFullName(node.This2ParentNodeInstanceNavigation, names);
 }
Ejemplo n.º 23
0
        public void TestPropertyNotFound()
        {
            var node = new NodeInstance
            {
            };

            Assert.Equal(nameof(NodeInstance), node.TypeInfo);
            Assert.Throws <PropertyNotFoundException>(() => node.GetProperty("asdf"));
        }
Ejemplo n.º 24
0
        private string GetFullName(NodeInstance node)
        {
            var list = new List <string>();

            list.Add(node.Name);
            GetFullName(node, list);
            list.Reverse();
            return(String.Join("-", list));
        }
Ejemplo n.º 25
0
 public void CreateLink()
 {
     var linkObject = GameObject.Instantiate(SampleManager.instance.spaceLink);
     linkObject.transform.SetParent(GetComponentInParent<Node>().linkParent);
     link = linkObject.GetComponent<Link>();
     link.name = name;
     link.to = to.node;
     to = null;
 }
Ejemplo n.º 26
0
        public RestartOnChangePatternsForm(NodeInstance i)
        {
            InitializeComponent();

            _nodeInstance = i;

            //
            patternsTextBox.Text = _nodeInstance.restartOnFileChangePatternsString;
        }
Ejemplo n.º 27
0
    internal OwlTreeNode AddNode(NodeInstance graphNode)
    {
        TreeNode <OwlTreeNode> treePtr = m_tree;

        int depth = 0;

        string fullName = "";

        foreach (string pathSegment in graphNode.m_pathSegments)
        {
            depth++;
            bool found = false;
            TreeNode <OwlTreeNode> newPtr = null;

            fullName += pathSegment + " ";

            foreach (var kid in treePtr.Children)
            {
                OwlTreeNode kidElem = kid.Value;

                found = kidElem.matchesString(pathSegment);

                if (found)
                {
                    newPtr = kid;
                    break;
                }
            }

            if (!found)
            {
                newPtr = treePtr.AddChild(
                    new OwlTreeNode(pathSegment, depth, treePtr.Value.mNumKids++));
                if (GraphManager.m_debug)
                {
                    newPtr.Value.mFullName = '<' + fullName + '>';
                }
            }

            treePtr = newPtr;
        }

        if (treePtr.Value.mNodeInstance != null)
        {
            Debug.Log("dupe node: " + treePtr.Value);
        }

        treePtr.Value.mNodeInstance = graphNode;

        if (graphNode.m_owlNode != null) // && GraphManager.m_debug)
        {
            treePtr.Value.mFullName += "(" + graphNode.m_owlNode.ID + ')';
        }

        return(treePtr.Value);
    }
Ejemplo n.º 28
0
        public NodeInstanceTerminal()
        {
            InitializeComponent();

            _nodeInstance  = null;
            _stdin         = new List <string>();
            _curCompletion = 0;

            outTextBox.Focus();
        }
Ejemplo n.º 29
0
 Transform LinkFolder(NodeInstance node)
 {
     var linksFolder = node.transform.Find("Links");
     if (linksFolder == null) {
         linksFolder = new GameObject("Links").transform;
         linksFolder.SetParent(node.transform);
         linksFolder.transform.Reset();
     }
     return linksFolder;
 }
Ejemplo n.º 30
0
        public override Task <IList <NodeInstance> > Scan()
        {
            var devices = Driver.LoadDevices();
            IList <NodeInstance> ret = new List <NodeInstance>();

            foreach (var device in devices)
            {
                if (Devices.Any(a => a.Container.DeviceId == device.Id))
                {
                    continue;
                }

                NodeInstance node = null;
                switch (device.ApplicationType)
                {
                case DeviceType.Remote:
                    break;

                case DeviceType.Unknown:
                    break;

                case DeviceType.Light:
                    node = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightContainerGuid);

                    var lightNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(lightNode);

                    var lighColorNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightColorGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(lighColorNode);

                    var lightDimmerNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightDimmerGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(lightDimmerNode);
                    break;

                case DeviceType.PowerOutlet:
                    node = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.RelayContainerGuid);

                    var stateNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.RelayGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(stateNode);
                    break;
                }

                if (node != null)
                {
                    var idProp = node.GetProperty(IkeaTradfriFactory.DeviceIdPropertyKey);
                    idProp.Value = device.Id;
                    node.Name    = device.Name;

                    ret.Add(node);
                }
            }

            return(Task.FromResult(ret));
        }
Ejemplo n.º 31
0
        private async Task <EntityState> AddOrUpdateNodeInstance(NodeInstance node)
        {
            var childs = node.InverseThis2ParentNodeInstanceNavigation;
            var props  = node.PropertyInstance;

            node.InverseThis2ParentNodeInstanceNavigation = null;
            node.PropertyInstance = null;
            node.IsDeleted        = false;

            if (node.Description == null)
            {
                node.Description = "";
            }

            var entityState = EntityState.Unchanged;
            var entity      = DbContext.NodeInstances.AsNoTracking().SingleOrDefault(a => a.ObjId == node.ObjId);

            if (entity != null)
            {
                DbContext.Entry(entity).State = EntityState.Detached;
                DbContext.Entry(node).State   = EntityState.Modified;

                DbContext.Update(node);
                entityState = EntityState.Modified;
            }
            else
            {
                DbContext.Entry(node).State = EntityState.Added;
                await DbContext.AddAsync(node);

                entityState = EntityState.Added;
            }

            foreach (var prop in props)
            {
                prop.This2NodeInstanceNavigation     = node;
                prop.This2PropertyTemplateNavigation = null;
                if (entityState == EntityState.Modified)
                {
                    DbContext.Update(prop);
                }
                else
                {
                    await DbContext.AddAsync(prop);
                }
            }

            foreach (var child in childs)
            {
                await AddOrUpdateNodeInstance(child);
            }

            return(entityState);
        }
Ejemplo n.º 32
0
 private void CreateLink(NodeInstance node, NodeInstance other)
 {
     Debug.LogFormat("CreateLink from {0} to {1}", node, other);
     var linksFolder = LinkFolder(node);
     var link = new GameObject(GenerateLinkName(node, other));
     link.transform.SetParent(other.transform);
     link.transform.Reset();
     link.transform.SetParent(linksFolder, worldPositionStays: true);
     var linkScript = link.AddComponent<LinkScript>();
     linkScript.to = other;
 }
Ejemplo n.º 33
0
        public override async Task OnSave(NodeInstance instance)
        {
            var json = JsonConvert.SerializeObject(instance.InverseThis2ParentNodeInstanceNavigation);
            var post = await Client.PostAsync($"http://{RemoteIpAddress}:{RemotePort}/webapi/nodeInstances",
                                              new StringContent(json, Encoding.UTF8, "application/json"));

            if (!post.IsSuccessStatusCode)
            {
                DriverContext.Logger.LogError("Could not save data for remote node");
            }
        }
Ejemplo n.º 34
0
        public T2 CreateDriver <T2>(NodeInstance node, params Guid[] childNodeGuid)
        {
            foreach (var gu in childNodeGuid)
            {
                var childNode = CreateNodeInstance(gu);
                childNode.ObjId = Guid.NewGuid();
                node.InverseThis2ParentNodeInstanceNavigation.Add(childNode);
            }

            return(CreateDriver <T2>(node));
        }
Ejemplo n.º 35
0
    //private IOwlEdge mOwlEdge;

    public EdgeInstance(/*IOwlEdge edge,*/ NodeInstance childNode,
                        NodeInstance parentNode, GameObject goEdge)
    {
        mChildNode  = childNode;
        mParentNode = parentNode;
        mGoEdge     = goEdge;
        //mOwlEdge = edge;

        childNode.addParentEdge(this);
        parentNode.addChildEdge(this);
    }
Ejemplo n.º 36
0
 static void CheckOverlapNode(NodeInstance node, float reduction)
 {
     //Debug.LogFormat(
     //    "Physics.OverlapBoxNonAlloc({0}, {1}, {2}, {3}, {4}, {5})",
     //    newNode.bounds.transform.TransformPoint(newNode.bounds.center),
     //    reduction * newNode.bounds.size / 2,
     //    overlapResults,
     //    newNode.bounds.transform.rotation,
     //    nodeMask,
     //    QueryTriggerInteraction.Collide
     //);
     overlapCount = Physics.OverlapBoxNonAlloc(
         node.bounds.transform.TransformPoint(node.bounds.center),
         reduction * node.bounds.size / 2,
         overlapResults,
         node.bounds.transform.rotation,
         nodeMask,
         QueryTriggerInteraction.Collide
     );
 }
Ejemplo n.º 37
0
 string GenerateLinkName(NodeInstance node, NodeInstance other)
 {
     var linkName = new List<string>();
     var delta = other.transform.position - node.transform.position;
     if (delta.x > 0.1) {
         linkName.Add("Right");
     }
     if (delta.x < -0.1) {
         linkName.Add("Left");
     }
     if (delta.y > 0.1) {
         linkName.Add("Up");
     }
     if (delta.y < -0.1) {
         linkName.Add("Down");
     }
     if (delta.z > 0.1) {
         linkName.Add("Far");
     }
     if (delta.z < -0.1) {
         linkName.Add("Near");
     }
     return string.Join(" ", linkName.ToArray());
 }
Ejemplo n.º 38
0
			public NodeInstance NewNode()
			{
				var instance = new NodeInstance(this);
				this.FInstances.Add(instance);
				return instance;
			}
Ejemplo n.º 39
0
    void FollowLink(Queue<NodeInstance> queue, NodeInstance from, LinkScript link)
    {
        var debug = false;
        //debug = from.name == "Node 8 (4) #2" && link.name == "Up";
        if (debug) {
            Debug.LogFormat("debug link: {0}", link.transform.Path());
        }

        if (bfsNodeCount >= MAX_NODES) {
            Debug.LogWarning("cnt >= MAX_NODES");
            return;
        }

        NodeInstance overlapNode = null;
        overlapNode = Overlapper.OverlapPoint(link.transform.position);
        if (overlapNode != null) {
            HandleOverlap(from, overlapNode, link);
            if (debug) {
                Debug.LogFormat("link {0}: overlapped by point with node {1}", link.transform.Path(), overlapNode);
            }
            return;
        }

        NodeInstance node = null;
        var oldNode = link.to;

        if (oldNode != null) {
            if (oldNode.IsOn()) {
                if (debug) {
                    Debug.LogFormat("link {0}: oldNode is on", link.transform.Path());
                }
                //link.AssertAcceptable();
                return;
            } else {
                node = oldNode;
            }
        } else {
            node = CreateNewNode(link);
            node.Off();
        }

        overlapNode = Overlapper.OverlapNode(node, reduction: 0.99f);
        if (overlapNode != null) {
            if (debug) {
                Debug.LogFormat("link {0}: overlapped with node: {1}", link.transform.Path(), overlapNode);
            }
            node.Disconnect();
            node.ReturnToPoolLight();
            HandleOverlap(from, overlapNode, link);
        } else {
            if (debug) {
                Debug.LogFormat("link {0}: set new node: {1}", link.transform.Path(), node);
            }
            node.On();
            node.distance = from.distance + 1;
            link.to = node;
            var nodeLinks = node.links;
            var backLinkSignature = link.link.backLink;
            var backLink = nodeLinks[backLinkSignature];
            backLink.to = from;
            //if (!link.AssertAcceptable()) {
            //    Debug.LogFormat("oldnode = {0}", oldNodeUsed);
            //}
            //backLink.AssertAcceptable();
            nodes.Add(node);
            queue.Enqueue(node);
            bfsNodeCount++;
        }
    }
Ejemplo n.º 40
0
 void HandleOverlap(NodeInstance from, NodeInstance overlap, LinkScript link)
 {
     var overlappedNode = overlap;
     if (Acceptable(overlappedNode, link)) {
         link.to = overlappedNode;
         overlappedNode.links[link.link.backLink].to = from;
     }
 }
Ejemplo n.º 41
0
    void Start()
    {
        if (current == null) {
            return;
        }
        current = current.node.NewNodeInstance();
        current.On();
        current.transform.SetParent(current.node.transform);
        current.transform.Reset();
        current.transform.SetParent(world, worldPositionStays: true);
        nodes.Clear();
        Bfs();

        FindObjectsOfType<NodeInstance>().Where(ni => ni.links == null).ToList().ForEach(ni => {
            Debug.LogFormat("links == null for {0}", ni);
        });
    }
Ejemplo n.º 42
0
    private void SwitchNode(NodeInstance node)
    {
        current = node;
        if (DebugManager.debug) {
            Debug.LogFormat("current = {0}", node);
        }
        Bfs();

        #if UNITY_EDITOR
        FindObjectsOfType<LinkScript>().ToList().ForEach(link => {
            if (link.to != null) {
                link.AssertAcceptable();
            }
        });
        #endif
    }
Ejemplo n.º 43
0
 bool TooFar(NodeInstance node)
 {
     return node.distance == distanceLimit;
 }
Ejemplo n.º 44
0
 public static bool Acceptable(NodeInstance node, LinkScript link)
 {
     var closeTranform = Extensions.Close(node.transform, link.transform);
     return node.node == link.Node && closeTranform;
 }
Ejemplo n.º 45
0
 void CancelNode(NodeInstance node)
 {
 }
Ejemplo n.º 46
0
 bool AcceptableEditor(NodeInstance node, LinkScript link)
 {
     return node == link.to && Extensions.Close(node.transform, link.transform);
 }
Ejemplo n.º 47
0
 public static List<NodeInstance> AllOverlapNodes(NodeInstance node, float reduction)
 {
     CheckOverlapNode(node, reduction);
     List<NodeInstance> result = new List<NodeInstance>();
                 for (int i = 0; i < overlapCount; i++) {
             var overlap = overlapResults[i];
             var other = overlap.GetComponentInParent<NodeInstance>();
             if (other != null) {
                 result.Add(other);
             }
         }
     return result;
 }
Ejemplo n.º 48
0
 public static NodeInstance OverlapNode(NodeInstance newNode, float reduction = 0.99f)
 {
     InitSearching();
     CheckOverlapNode(newNode, reduction);
     return FirstOnNode();
 }