public bool Contains(T node) { Insist.IsNotNull(node, "node cannot be null"); Insist.IsFalse(node.QueueIndex < 0 || node.QueueIndex >= _nodes.Length, "node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); return(_nodes[node.QueueIndex] == node); }
/// <summary> /// Sets the selected text /// </summary> /// <param name="selectionStart">Selection start.</param> /// <param name="selectionEnd">Selection end.</param> public TextField SetSelection(int selectionStart, int selectionEnd) { Insist.IsFalse(selectionStart < 0, "selectionStart must be >= 0"); Insist.IsFalse(selectionEnd < 0, "selectionEnd must be >= 0"); selectionStart = Math.Min(text.Length, selectionStart); selectionEnd = Math.Min(text.Length, selectionEnd); if (selectionEnd == selectionStart) { ClearSelection(); return(this); } if (selectionEnd < selectionStart) { int temp = selectionEnd; selectionEnd = selectionStart; selectionStart = temp; } hasSelection = true; this.selectionStart = selectionStart; cursor = selectionEnd; return(this); }
/// <summary> /// Sets the cursor position and clears any selection /// </summary> /// <param name="cursorPosition">Cursor position.</param> public TextField SetCursorPosition(int cursorPosition) { Insist.IsFalse(cursorPosition < 0, "cursorPosition must be >= 0"); ClearSelection(); cursor = Math.Min(cursorPosition, text.Length); return(this); }
public void UpdatePriority(T node, int priority) { Insist.IsNotNull(node, "node cannot be null"); Insist.IsFalse(Contains(node), "Cannot call UpdatePriority() on a node which is not enqueued: " + node); node.Priority = priority; OnNodeUpdated(node); }
public FSCollisionEllipse(float xRadius, float yRadius, int edgeCount) { Insist.IsFalse(edgeCount > Settings.MaxPolygonVertices, "edgeCount must be less than Settings.maxPolygonVertices"); _xRadius = xRadius; _yRadius = yRadius; _edgeCount = edgeCount; _verts = PolygonTools.CreateEllipse(_xRadius * FSConvert.DisplayToSim, _yRadius * FSConvert.DisplayToSim, _edgeCount); }
public FSCollisionEllipse SetEdgeCount(int edgeCount) { Insist.IsFalse(edgeCount > Settings.MaxPolygonVertices, "edgeCount must be less than Settings.maxPolygonVertices"); _edgeCount = edgeCount; _verts = PolygonTools.CreateEllipse(_xRadius * FSConvert.DisplayToSim, _yRadius * FSConvert.DisplayToSim, _edgeCount); RecreateFixture(); return(this); }
/// <summary> /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it. /// If queue is empty, result is undefined /// O(log n) /// </summary> public T Dequeue() { Insist.IsFalse(_numNodes <= 0, "Cannot call Dequeue() on an empty queue"); Insist.IsTrue(IsValidQueue(), "Queue has been corrupted (Did you update a node priority manually instead of calling UpdatePriority()?" + "Or add the same node to two different queues?)"); T returnMe = _nodes[1]; Remove(returnMe); return(returnMe); }
public void IsFalse_2_Null_Or_Empty_User_Message_Uses_Default_Message(string userMessage) { string message = null; try { Insist.IsFalse(true, ARGUMENT_NAME, userMessage); } catch (ArgumentException e) { message = e.Message; } Assert.IsNotNullOrEmpty(message); }
public Subtexture CreateRegion(string name, int x, int y, int width, int height, float pivotX = 0.5f, float pivotY = 0.5f) { Insist.IsFalse(_subtextureMap.ContainsKey(name), "Region {0} already exists in the texture atlas", name); var region = new Subtexture(Texture, new Rectangle(x, y, width, height), new Vector2(pivotX * width, pivotY * height)); var index = Subtextures.Count; Subtextures.Add(region); _subtextureMap.Add(name, index); return(region); }
public void Enqueue(T node, double priority) { Insist.IsNotNull(node, "node cannot be null"); Insist.IsFalse(_numNodes >= _nodes.Length - 1, "Queue is full - node cannot be added: " + node); Insist.IsFalse(Contains(node), "Node is already enqueued: " + node); node.Priority = priority; _numNodes++; _nodes[_numNodes] = node; node.QueueIndex = _numNodes; node.InsertionIndex = _numNodesEverEnqueued++; CascadeUp(_nodes[_numNodes]); }
public void AddObserver(T eventType, Action handler) { List <Action> list = null; if (!_messageTable.TryGetValue(eventType, out list)) { list = new List <Action>(); _messageTable.Add(eventType, list); } Insist.IsFalse(list.Contains(handler), "You are trying to add the same observer twice"); list.Add(handler); }
/// <summary> /// Resize the queue so it can accept more nodes. All currently enqueued nodes are remain. /// Attempting to decrease the queue size to a size too small to hold the existing nodes results in undefined behavior /// O(n) /// </summary> public void Resize(int maxNodes) { Insist.IsFalse(maxNodes <= 0, "Queue size cannot be smaller than 1"); Insist.IsFalse(maxNodes < _numNodes, "Called Resize(" + maxNodes + "), but current queue contains " + _numNodes + " nodes"); T[] newArray = new T[maxNodes + 1]; int highestIndexToCopy = Math.Min(maxNodes, _numNodes); for (int i = 1; i <= highestIndexToCopy; i++) { newArray[i] = _nodes[i]; } _nodes = newArray; }
/// <summary> /// Sets the selection to only the selected index /// </summary> /// <param name="index">Index.</param> public ListBox <T> SetSelectedIndex(int index) { Insist.IsFalse(index < -1 || index >= _items.Count, "index must be >= -1 and < " + _items.Count + ": " + index); if (index == -1) { _selection.Clear(); } else { _selection.Set(_items[index]); } return(this); }
public Subtexture GetSubtexture(int index) { Insist.IsFalse(index < 0 || index >= Subtextures.Count, "index out of range"); return(Subtextures[index]); }
public BehaviorTreeBuilder <T> LogAction(string text) { Insist.IsFalse(_parentNodeStack.Count == 0, "Can't create an unnested Action node. It must be a leaf node."); return(SetChildOnParent(new LogAction <T>(text))); }
public BehaviorTreeBuilder <T> WaitAction(float waitTime) { Insist.IsFalse(_parentNodeStack.Count == 0, "Can't create an unnested Action node. It must be a leaf node."); return(SetChildOnParent(new WaitAction <T>(waitTime))); }
public void IsFalse_2_False_Throws_Exception() { Insist.IsFalse(true, ARGUMENT_NAME, MESSAGE); }
public void IsFalse_2_True_Does_Not_Throw_Exception() { Assert.DoesNotThrow(() => { Insist.IsFalse(false, ARGUMENT_NAME, MESSAGE); }); }
public void IsFalse_2_Null_Or_Empty_Argument_Name_Throws_Exception(string argName) { Insist.IsFalse(false, argName, MESSAGE); }
/// <summary> /// Splice a sub tree into the parent tree. /// </summary> public BehaviorTreeBuilder <T> SubTree(BehaviorTree <T> subTree) { Insist.IsFalse(_parentNodeStack.Count == 0, "Can't splice an unnested sub tree, there must be a parent tree."); return(SetChildOnParent(new BehaviorTreeReference <T>(subTree))); }
public BehaviorTreeBuilder <T> Conditional(Func <T, TaskStatus> func) { Insist.IsFalse(_parentNodeStack.Count == 0, "Can't create an unnested Conditional node. It must be a leaf node."); return(SetChildOnParent(new ExecuteActionConditional <T>(func))); }