private void MoveSelectionOut(ParentedNode node) { var parent = node.Parent; if (parent == null) { return; } var next = parent.FindNextChild <BaseNode>(node); if (next != null) { node.IsSelected = false; next.IsSelected = true; return; } var previous = parent.FindPreviousChild <BaseNode>(node); if (previous != null) { node.IsSelected = false; previous.IsSelected = true; } else { node.IsSelected = false; parent.IsSelected = true; } }
public ParentedNode(ParentedNode parent,Vector2 node, float weight){ this.parent = parent; this.weight = weight; if(parent != null){ this.weight += parent.weight; } this.location = node; }
private void NavigateToNode(ParentedNode node) { var buildControl = GetBuildControl(); if (buildControl != null) { buildControl.SelectItem(node); } }
public ParentedNode(ParentedNode parent, Vector2 node, float weight) { this.parent = parent; this.weight = weight; if (parent != null) { this.weight += parent.weight; } this.location = node; }
private bool CanView(ParentedNode node) { return(node is AbstractDiagnostic || node is Project || (node is Target t && t.SourceFilePath != null && sourceFileResolver.HasFile(t.SourceFilePath)) || (node is Task task && task.Parent is Target parentTarget && sourceFileResolver.HasFile(parentTarget.SourceFilePath)) || (node is IHasSourceFile ihsf && ihsf.SourceFilePath != null && sourceFileResolver.HasFile(ihsf.SourceFilePath)) || (node is NameValueNode nvn && nvn.IsValueShortened) || (node is TextNode tn && tn.IsTextShortened)); }
private void SelectItem(ParentedNode item) { var parentChain = item.GetParentChain(); if (!parentChain.Any()) { return; } treeView.SelectContainerFromItem <object>(parentChain); }
public void SelectItem(ParentedNode item) { var parentChain = item.GetParentChainIncludingThis(); if (!parentChain.Any()) { return; } SelectTree(); treeView.SelectedItem = parentChain; }
public void SelectItem(ParentedNode item) { var parentChain = item.GetParentChainIncludingThis(); if (!parentChain.Any()) { return; } SelectTree(); treeView.SelectContainerFromItem <object>(parentChain); }
void laddercase(IVector2 currentpos, IVector2 dest, ParentedNode node, Vector2 v) { bool s = map.getForeground(currentpos) == TileSpecList.getTileSpec("Ladder"); bool f = map.getForeground(currentpos) == TileSpecList.getTileSpec("Ladder"); if (currentpos.x == dest.x) { ladderTile(currentpos); ladderTile(dest); } currentMovement.y = Mathf.Sign(v.y) * moveSpeed; }
/// <summary> /// Initializes a new instance of the <see cref="Route"/> class. /// </summary> /// <param name="p">The parented node to build the route from.</param> public Route(ParentedNode p){ length = 0; locations = new List<Vector3>(); nodes = new List<ParentedNode>(); ParentedNode n = p; while(n.parent != null){ locations.Insert(0,n.location); nodes.Insert(0,n); Debug.Log (n.type); n = n.parent; } length = locations.Count; }
//Add the specified nodes as leaves, ensuring that they are parented to current and not in branches or leaves. private void addToLeaves(ParentedNode current, Vector2[] positions, List <ParentedNode> branches, List <ParentedNode> leaves, Vector2 start, Vector2 end, int addedWeight, ParentedNode.Type t) { //Get the neighbors and add them to leaves, parented to the current node. foreach (Vector2 v in positions) { //Don't add it if its already in the leaves or branches. if (!ContainsNode(leaves, branches, v)) { ParentedNode p = new ParentedNode(current, v, hueristic(v, end) + addedWeight); p.type = t; leaves.Add(p); } } }
public void SelectItem(ParentedNode item) { var parentChain = item.GetParentChainExcludingThis(); foreach (var node in parentChain) { if (node is TreeNode treeNode) { treeNode.IsExpanded = true; } } SelectTree(); treeView.SelectedItem = item; }
//****************************************************************************// void walkcase(IVector2 currentpos, IVector2 dest, ParentedNode node, Vector2 v) { if ((v.y > .25f && Mathf.Abs(v.x) < .1f) || (map.getForeground(currentpos) == TileSpecList.getTileSpec(LADDERINDEX) && canLadder)) { laddercase(currentpos, dest, node, v); return; } currentState = movementState.WALKING; if (v.y > .25f && (Mathf.Abs(v.x) > .1f && cc.velocity.x == 0)) // || (lastPosition - currentpos).magnitude == 0){ { Debug.Log("Jumping"); jump(); currentState = movementState.JUMPING; } }
/// <summary> /// Initializes a new instance of the <see cref="Route"/> class. /// </summary> /// <param name="p">The parented node to build the route from.</param> public Route(ParentedNode p) { length = 0; locations = new List <Vector3>(); nodes = new List <ParentedNode>(); ParentedNode n = p; while (n.parent != null) { locations.Insert(0, n.location); nodes.Insert(0, n); Debug.Log(n.type); n = n.parent; } length = locations.Count; }
//Gets the smallest node in leaves private ParentedNode getSmallestLeaf(List <ParentedNode> leaves) { //Create a parented node ParentedNode current = new ParentedNode(null, Vector2.zero, float.MaxValue); current.weight = float.MaxValue; //Check to find the lowest weighted leaf foreach (ParentedNode p in leaves) { if (p.weight < current.weight) { current = p; } } return(current); }
//Coroutine which calculates the path to the destination. public IEnumerator getPath() { Vector2 lastDest = position; float waitTime = .1f; reset: while (true) { //This routine happens every second. yield return(new WaitForSeconds(waitTime)); //If the destination hasn't changed... if (lastDest == destination && !rePath) { pathing = false; waitTime = Mathf.Clamp(waitTime + .01f, .01f, .5f); //...Go back to start of the loop. goto reset; } pathing = true; rePath = false; if (!TileSpecList.getTileSpec(map.getByte(destination, Map.FOREGROUND_ID)).diggable) { lastDest = destination; path = new Route(); goto reset; } waitTime = .1f; Vector2 start = position; Vector2 end = new IVector2(destination.x, destination.y); //Create a list of leaves List <ParentedNode> leaves = new List <ParentedNode>(); //Create a list of branches (used leaves) List <ParentedNode> branches = new List <ParentedNode>(); //If the character has to dig Route digRoute = new Route(); //Add current position to the leaves leaves.Add(new ParentedNode(null, position, 0)); int count = 0; //While there are still leaves, and the destination hasn't changed. while (leaves.Count > 0) { ParentedNode current = getSmallestLeaf(leaves); leaves.Remove(current); branches.Add(current); //If it found the path... if (current.location == end) { //...Create a new route based on that last node. //ParentedNode p = new ParentedNode(current.parent,end,0); Route r = new Route(current); setPath(r); if (r.locations.Count > 0) { lastDest = new IVector2(r.locations[r.locations.Count - 1].x, r.locations[r.locations.Count - 1].y); } //Break out goto reset; } //Add new leaves, both open neighbors and ones where you dig. addToLeaves(current, current.GetNeighbors(), branches, leaves, start, end, 0, ParentedNode.Type.WALK); if (canMine) { addToLeaves(current, current.GetDigNeighbors(), branches, leaves, start, end, 1, ParentedNode.Type.DIG); } if (canLadder) { addToLeaves(current, current.GetLadderNeighbors(), branches, leaves, start, end, 3, ParentedNode.Type.LADDER); } count++; if (rePath) { goto reset; } //Only do 20 cycles per frame if (count % pathsPerFrame == 0) { yield return(new WaitForSeconds(1)); if (count > 10000) { destination = lastDest; goto reset; } } } //If it goes through and cant find anything, Debug.Log("Path not found"); waitTime += .01f; } }
private bool CanOpenFile(ParentedNode node) { return(node is Import i && sourceFileResolver.HasFile(i.ImportedProjectFilePath)); }
void laddercase(IVector2 currentpos,IVector2 dest,ParentedNode node,Vector2 v){ bool s = map.getForeground(currentpos) == TileSpecList.getTileSpec("Ladder"); bool f = map.getForeground(currentpos) == TileSpecList.getTileSpec("Ladder"); if(currentpos.x == dest.x){ ladderTile(currentpos); ladderTile(dest); } currentMovement.y = Mathf.Sign(v.y) * moveSpeed; }
void digcase(IVector2 currentpos,IVector2 dest,ParentedNode node,Vector2 v){ handleDigging(dest,v); }
//****************************************************************************// void walkcase(IVector2 currentpos,IVector2 dest,ParentedNode node,Vector2 v){ if((v.y > .25f && Mathf.Abs(v.x) < .1f) || (map.getForeground(currentpos) == TileSpecList.getTileSpec(LADDERINDEX) && canLadder)){ laddercase(currentpos,dest,node,v); return; } currentState = movementState.WALKING; if(v.y > .25f && (Mathf.Abs(v.x) > .1f && cc.velocity.x == 0)){// || (lastPosition - currentpos).magnitude == 0){ Debug.Log("Jumping"); jump (); currentState = movementState.JUMPING; } }
private void SelectItem(ParentedNode item) { var parentChain = item.GetParentChain(); if (!parentChain.Any()) { return; } treeView.SelectContainerFromItem<object>(parentChain); }
//Moves this character along its route. public virtual void move() { if (path != null && currentPathIndex < path.locations.Count) { moving = true; Vector2 currentpos = new Vector2(this.transform.position.x + size / 2, this.transform.position.y); Vector2 dest = path.locations[currentPathIndex]; ParentedNode node = path.nodes[currentPathIndex]; Vector2 v = dest - (Vector2)this.transform.position; if (v.magnitude > 1.5f) { rePath = true; } bool shouldDig = map.isForegroundSolid(dest); bool ladder = !shouldDig && map.ladderable(dest); switch (node.type) { case ParentedNode.Type.WALK: walkcase(currentpos, dest, node, v); break; case ParentedNode.Type.DIG: digcase(currentpos, dest, node, v); break; case ParentedNode.Type.LADDER: laddercase(currentpos, dest, node, v); break; } if (shouldDig) { Vector3 a = (Vector3)currentpos + new Vector3(0.2f, 0.7f, -5); Vector3 b = (Vector3)currentpos + new Vector3(0.2f, 0.3f, -5); Vector3 c = (Vector3)currentpos + new Vector3(-0.2f, 0.3f, -5); Vector3 d = (Vector3)currentpos + new Vector3(-0.2f, 0.7f, -5); Color col = Color.cyan; Debug.DrawLine(a, b, col); Debug.DrawLine(b, c, col); Debug.DrawLine(c, d, col); Debug.DrawLine(d, a, col); } currentMovement.x = ((Mathf.Abs(v.x) < .05)?0:Mathf.Sign(v.normalized.x) * moveSpeed); if (v.magnitude < .25f) { position = path.locations[currentPathIndex]; currentPathIndex++; } lastPosition = currentpos; //transform.Translate(v.normalized * moveSpeed* Time.deltaTime); } else { moving = false; currentMovement.x = 0; } applyGravity(); cc.Move(currentMovement * Time.fixedDeltaTime); }
void digcase(IVector2 currentpos, IVector2 dest, ParentedNode node, Vector2 v) { handleDigging(dest, v); }
//Gets the smallest node in leaves private ParentedNode getSmallestLeaf(List<ParentedNode> leaves){ //Create a parented node ParentedNode current = new ParentedNode(null,Vector2.zero,float.MaxValue); current.weight = float.MaxValue; //Check to find the lowest weighted leaf foreach(ParentedNode p in leaves){ if(p.weight < current.weight){ current = p; } } return current; }
//Add the specified nodes as leaves, ensuring that they are parented to current and not in branches or leaves. private void addToLeaves(ParentedNode current, Vector2[] positions, List<ParentedNode> branches, List<ParentedNode> leaves, Vector2 start, Vector2 end, int addedWeight, ParentedNode.Type t){ //Get the neighbors and add them to leaves, parented to the current node. foreach(Vector2 v in positions){ //Don't add it if its already in the leaves or branches. if(!ContainsNode(leaves,branches,v)){ ParentedNode p = new ParentedNode(current,v,hueristic(v,end) + addedWeight); p.type = t; leaves.Add(p); } } }
private bool Invoke(ParentedNode treeNode) { if (treeNode == null) { return(false); } try { switch (treeNode) { case AbstractDiagnostic diagnostic: var path = diagnostic.File; if (!DisplayFile(path, diagnostic.LineNumber) && path != null && !Path.IsPathRooted(path) && diagnostic.ProjectFile != null) { // path must be relative, try to normalize: path = Path.Combine(Path.GetDirectoryName(diagnostic.ProjectFile), path); return(DisplayFile(path, diagnostic.LineNumber, diagnostic.ColumnNumber)); } break; case Target target: return(DisplayTarget(target.SourceFilePath, target.Name)); case Task task: return(DisplayTask(task.SourceFilePath, task.Parent, task.Name)); case IHasSourceFile hasSourceFile when hasSourceFile.SourceFilePath != null: int line = 0; var hasLine = hasSourceFile as IHasLineNumber; if (hasLine != null) { line = hasLine.LineNumber ?? 0; } return(DisplayFile(hasSourceFile.SourceFilePath, line)); case SourceFileLine sourceFileLine when sourceFileLine.Parent is SourceFile sourceFile && sourceFile.SourceFilePath != null: return(DisplayFile(sourceFile.SourceFilePath, sourceFileLine.LineNumber)); case NameValueNode nameValueNode when nameValueNode.IsValueShortened: return(DisplayText(nameValueNode.Value, nameValueNode.Name)); case TextNode textNode when textNode.IsTextShortened: return(DisplayText(textNode.Text, textNode.Name ?? textNode.GetType().Name)); default: return(false); } } catch { // in case our guessing of file path goes awry } return(false); }
private void MoveSelectionOut(ParentedNode node) { var parent = node.Parent; if (parent == null) { return; } var next = parent.FindNextChild<BaseNode>(node); if (next != null) { node.IsSelected = false; next.IsSelected = true; return; } var previous = parent.FindPreviousChild<BaseNode>(node); if (previous != null) { node.IsSelected = false; previous.IsSelected = true; } else { node.IsSelected = false; parent.IsSelected = true; } }