void SelectElement(IActiveElement element) { if (element != null) { TextArea.Selection = new SimpleSelection(element.Segment); TextArea.Caret.Offset = element.Segment.EndOffset; } }
void SelectElement(IActiveElement element) { if (element != null) { TextArea.Selection = Selection.Create(TextArea, element.Segment); TextArea.Caret.Offset = element.Segment.EndOffset; } }
public ISegment GetBeforeReplaceableActiveElement(bool stopWhenReachOut = true) { if (Context != null && IsSnippetActivated) { ReplaceableActiveElement beforeElement = null; foreach (IActiveElement element in Context.ActiveElements) { ReplaceableActiveElement re = element as ReplaceableActiveElement; if (re != null) { if (_activeElement.Equals(re)) { if (beforeElement == null)//이번 것이 첫 snippet이고, 이전에 선택된 것과 같을 경우.. { if (stopWhenReachOut) { return(re.Segment); //더이상 움직이지 않는다. } else//끝낸다. { IsSnippetActivated = false; _activeElement = null; return(null); } } else { _activeElement = beforeElement; IsSnippetActivated = true; return(beforeElement.Segment); } } else { beforeElement = re;//계속 저장하면서 나간다. } } } if (beforeElement != null)//제일 마지막까지 왔다면 뒤에서부터 처음 시작했다는 의미이다. { _activeElement = beforeElement; IsSnippetActivated = true; return(beforeElement.Segment); } } return(null);//제일 마지막까지 갔는데 없다면 ActiveSnippet이 하나도 없는 것이다. }
void Connect(int x, int y, int dx, int dy, Color pixel) { if (pixel == Color.white) { return; } IActiveElement otherBlock = null; IActiveElement thisBlock = null; bool willConnect = _elements.TryGetValue(new Vector2(x + dx, y + dy), out otherBlock); willConnect = willConnect && _elements.TryGetValue(new Vector2(x, y), out thisBlock); if (willConnect) { thisBlock.AddBlock(otherBlock); } }
/// <summary> /// Registers an active element. Elements should be registered during insertion and will be called back /// when insertion has completed. /// </summary> /// <param name="owner">The snippet element that created the active element.</param> /// <param name="element">The active element.</param> public void RegisterActiveElement(SnippetElement owner, IActiveElement element) { if (owner == null) { throw new ArgumentNullException("owner"); } if (element == null) { throw new ArgumentNullException("element"); } if (currentStatus != Status.Insertion) { throw new InvalidOperationException(); } elementMap.Add(owner, element); registeredElements.Add(element); }
public ISegment GetNextReplaceableActiveElement(bool stopWhenReachOut = true) { if (Context != null && IsSnippetActivated) { bool isCurrent = false; foreach (IActiveElement element in Context.ActiveElements) { ReplaceableActiveElement re = element as ReplaceableActiveElement; if (re != null) { if (_activeElement == null) { _activeElement = re; IsSnippetActivated = true; return(re.Segment); } else { if (_activeElement.Equals(re)) { isCurrent = true; } else if (isCurrent) { _activeElement = re; IsSnippetActivated = true; return(re.Segment); } } } } } if (stopWhenReachOut) { return(_activeElement.Segment); } else { _activeElement = null; IsSnippetActivated = false; return(null);//제일 마지막까지 갔는데 없다면 모든 Active snippet을 돈 것이다. } }
public void AddBlock(IActiveElement element) { neighbouringElements.Add(element); }
public void Activate(IActiveElement element) { activationEnergy++; }
public void Activate(IActiveElement element) { IsActiveInNextTick = true; activationSource = element; }
public void Activate(IActiveElement element) { IsActiveInNextTick = true; }
/// <summary> /// Registers an active element. Elements should be registered during insertion and will be called back /// when insertion has completed. /// </summary> /// <param name="owner">The snippet element that created the active element.</param> /// <param name="element">The active element.</param> public void RegisterActiveElement(SnippetElement owner, IActiveElement element) { if (owner == null) throw new ArgumentNullException("owner"); if (element == null) throw new ArgumentNullException("element"); if (currentStatus != Status.Insertion) throw new InvalidOperationException(); elementMap.Add(owner, element); registeredElements.Add(element); }
public void RegisterBlock(IActiveElement block) { AllBlocks.Add(block); }
void ConnectLogic(int x, int y) { var x2 = x; var y2 = y; var pixel = Map.GetPixel(x + 1, y); if (pixel != Color.white) { x2++; } pixel = Map.GetPixel(x, y + 1); if (pixel != Color.white) { y2++; } pixel = Map.GetPixel(x - 1, y); if (pixel != Color.white) { x2--; } pixel = Map.GetPixel(x, y - 1); if (pixel != Color.white) { y2--; } IActiveElement otherBlock = null; IActiveElement thisBlock = null; bool willConnect = _elements.TryGetValue(new Vector2(x2, y2), out otherBlock); willConnect = willConnect && _elements.TryGetValue(new Vector2(x, y), out thisBlock); if (willConnect) { thisBlock.AddBlock(otherBlock); } // Connect inputs if (x2 > x) { if (_elements.TryGetValue(new Vector2(x, y), out otherBlock) && _elements.TryGetValue(new Vector2(x - 1, y + 1), out thisBlock)) { thisBlock.AddBlock(otherBlock); } if (_elements.TryGetValue(new Vector2(x, y), out otherBlock) && _elements.TryGetValue(new Vector2(x - 1, y - 1), out thisBlock)) { thisBlock.AddBlock(otherBlock); } } else if (x2 < x) { if (_elements.TryGetValue(new Vector2(x, y), out otherBlock) && _elements.TryGetValue(new Vector2(x + 1, y + 1), out thisBlock)) { thisBlock.AddBlock(otherBlock); } if (_elements.TryGetValue(new Vector2(x + 1, y - 1), out thisBlock)) { thisBlock.AddBlock(otherBlock); } } }
void CreateLevel() { for (var x = 1; x < Map.width - 1; ++x) { for (var y = 1; y < Map.height - 1; ++y) { { var pixel = Map.GetPixel(x, y); if (pixel == Color.white) { continue; } foreach (var cMap in ColorMappings) { if (cMap.color != pixel) { continue; } var go = Instantiate( cMap.prefab, scaleFactor * (new Vector2(x, y) + scaleOffset), Quaternion.identity, Board); IActiveElement el = null; switch (cMap.Type) { case ActiveElement.ElementType.And: { el = go.GetComponent <LogicAnd>(); break; } case ActiveElement.ElementType.Or: { el = go.GetComponent <LogicOr>(); break; } case ActiveElement.ElementType.Input: { el = go.GetComponent <Input>(); break; } case ActiveElement.ElementType.Output: { el = go.GetComponent <Output>(); break; } case ActiveElement.ElementType.Wire: { el = go.GetComponent <Wire>(); break; } } if (el != null) { _elements.Add(new Vector2(x, y), el); } } } } } }
public void AddBlock(IActiveElement element) { }