private static List <Rectangle> GetRegionsFromMatches(FindState findState, Size sourceSize, Rectangle zone) { List <Rectangle> result = new List <Rectangle>(); Rectangle sourceBounds = new Rectangle(Point.Empty, sourceSize); if (findState == FindState.Initial) { result.Add(Rectangle.Intersect(sourceBounds, zone)); } else { foreach (Match match in LastMatches) { Point topLeft = new Point(); Point bottomRight = new Point(); topLeft.Y = (match.Zone.Top - 1) * 2; topLeft.X = (match.Zone.Left - 1) * 2; bottomRight.Y = (match.Zone.Bottom + 1) * 2; bottomRight.X = (match.Zone.Right + 1) * 2; Rectangle region = Rectangle.FromLTRB(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y); result.Add(Rectangle.Intersect(Rectangle.Intersect(region, sourceBounds), zone)); } } return(result); }
public bool SettingsEqual(FindState other) { return ((Options & OptionsEqualMask) == (other.Options & OptionsEqualMask) && FindWhat == other.FindWhat && ReplaceWith == other.ReplaceWith && LookIn == other.LookIn && LookInFileTypes == other.LookInFileTypes); }
private void ConstructBehaviourTree() { OrderGenerator orderGenerator = new OrderGenerator(gameM.stockItems, gameM.nbItemsOrdered, this); ArriveAtPosition arriveAtPosition = new ArriveAtPosition(this); IsQueueSpotAvailable queueSpotAvailable = new IsQueueSpotAvailable(spawnM.availableQueue, gameM.playerTransform, this); GoToQueueSpot goToQueueSpot = new GoToQueueSpot(agent, this); IsLootSpotAvailable lootSpotAvailable = new IsLootSpotAvailable(spawnM.availableLoot, gameM.playerTransform, this); GoToLootSpot goToLootSpot = new GoToLootSpot(agent, this); RandomStateNode randomStateNode = new RandomStateNode(spawnM); ClientStateNode clientStateNode = new ClientStateNode(spawnM.clientOnly, gameM.nbClient, agent.speed, this); ThiefStateNode thiefStateNode = new ThiefStateNode(spawnM.thiefOnly, gameM.nbThief, agent.speed, this); FindState findState = new FindState(this); Sequence orderSequence = new Sequence(new List <Node> { orderGenerator }); //Sequence goingToCounter = new Sequence(new List<Node> { goToQueueSpot, goToPosition); //Selector goToposition = new Selector(new List<Node> { orderSequence, goingToCounter }); repeatMovingToSpot = new Repeator(goToQueueSpot); Sequence goToQueueSpotSequence = new Sequence(new List <Node> { queueSpotAvailable, repeatMovingToSpot, orderSequence }); Sequence goToLootSpotSequence = new Sequence(new List <Node> { lootSpotAvailable, goToLootSpot }); Sequence thiefSequence = new Sequence(new List <Node> { thiefStateNode, goToLootSpotSequence }); Sequence clientSequence = new Sequence(new List <Node> { clientStateNode, goToQueueSpotSequence }); Selector GoToStateSelector = new Selector(new List <Node> { clientSequence, thiefSequence }); Sequence randomBoolSequence = new Sequence(new List <Node> { findState, GoToStateSelector }); Sequence randomSequence = new Sequence(new List <Node> { randomBoolSequence, randomStateNode }); topNode = new Selector(new List <Node> { randomSequence, clientSequence, thiefSequence }); //Debug.Log(findState.Evaluate()); //Debug.Log(clientSequence.Evaluate()); //Debug.Log(randomBoolSequence.Evaluate()); }
private IEnumerator <float> CheckContinueGame() { var apiInfo = GetPlayersInfo(); while (mFlag) { yield return(1f); Facade.Instance <TwManager>().SendAction("mahjongwm.checkContinueGame", apiInfo, data => { if (data == null) { mFindState = FindState.None; return; } int id = 0; string message = string.Empty; var dic = (Dictionary <string, object>)data; if (dic.ContainsKey("message")) { mFindState = FindState.Tip; message = dic["message"].ToString(); } if (dic.ContainsKey("roomId")) { mFindState = FindState.Success; id = (int)dic["roomId"]; } switch (mFindState) { case FindState.Tip: OnOpenTip(message); break; case FindState.Success: OnFindNewGame(id, message); mFlag = false; break; } }, true, null, false, null); } }
public FilesIterator(FindState findState, IServiceProvider serviceProvider) { if (!Directory.Exists(findState.LookIn)) { return; } Regex pattern = null; if (!String.IsNullOrEmpty(findState.LookInFileTypes)) { pattern = BuildPattern( findState.LookInFileTypes .Split(';') .Select(p => p.Trim()) .Where(p => p.Length > 0) .ToArray() ); } GetPaths(findState.LookIn, pattern, findState.Options.HasFlag(NiFindOptions.SubFolders)); }
private static FindState InnerFind(Int32 scaleDivider, Rectangle zone) { Rectangle scaledZone = new Rectangle(new Point(zone.X / scaleDivider - 1, zone.Y / scaleDivider - 1), new Size(zone.Width / scaleDivider + 2, zone.Height / scaleDivider + 2)); Size sourceSize = new Size(RawSourceImage.Width / scaleDivider, RawSourceImage.Height / scaleDivider); Size targetSize = new Size(RawTargetImage.Width / scaleDivider, RawTargetImage.Height / scaleDivider); if (targetSize.Width * targetSize.Height >= 100) { FindState findState = InnerFind(scaleDivider * 2, zone); if (findState != FindState.None) { DrawScaledImages(scaleDivider, sourceSize, targetSize); List <Rectangle> regions = GetRegionsFromMatches(findState, sourceSize, scaledZone); List <Match> matches = SearchForMatches(targetSize, regions, scaleDivider); if (matches.Count > 0) { FilterWorstMatches(matches, scaleDivider); } if (scaleDivider > 1) { MergeNearMatches(matches, scaleDivider); } if (scaleDivider == 1) { NormalizeMatches(matches); } LastMatches = matches; return(LastMatches.Count > 0 ? FindState.Sequent : FindState.None); } else { return(FindState.None); } } else { return(FindState.Initial); } }
public OpenDocumentIterator(FindState findState, IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; }
public ProjectIterator(FindState findState, IServiceProvider serviceProvider) { _findState = findState; _serviceProvider = serviceProvider; }
public void Execute(string path) { if (!Directory.Exists(path)) { throw new FireSpiderException(string.Format("Directory {0} not Exists", path)); } this.state = FindState.Started; try { if (provider != null) { provider.OnFileFinderStarted(); } if (this.background) { ThreadExecute(path); } else { CurrentExecute(path); if (provider != null) { provider.OnFileFinderComplete(); } } this.state = FindState.Stoped; } catch { this.state = FindState.Error; } }
private void PerformFindChecked(FindAction action) { SaveSettings(); var options = Options & (NiFindOptions.OptionsMask | NiFindOptions.SyntaxMark | NiFindOptions.TargetMask); options &= ~(NiFindOptions.ActionMask | NiFindOptions.Backwards); switch (action) { case FindAction.FindNext: options |= NiFindOptions.Find; break; case FindAction.FindPrevious: options |= NiFindOptions.Find | NiFindOptions.Backwards; break; case FindAction.Replace: options |= NiFindOptions.Replace; break; case FindAction.ReplaceAll: options |= NiFindOptions.ReplaceAll; break; case FindAction.FindAll: options |= NiFindOptions.FindAll; break; case FindAction.SkipFile: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException("action"); } var currentFindState = FindState.Create(this, options, FindTarget); if (_state == null || !_state.SettingsEqual(currentFindState)) { _state = currentFindState; _state.CreateIterator(_view); } _state.Options = options; switch (action) { case FindAction.FindNext: PerformFindSingle(); break; case FindAction.FindPrevious: PerformFindSingle(); break; case FindAction.Replace: PerformReplaceSingle(); break; case FindAction.ReplaceAll: PerformReplaceAll(); break; case FindAction.FindAll: PerformFindAll(); break; case FindAction.SkipFile: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException("action"); } }
public OpenDocumentIterator(FindState findState, IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; }
public FilesIterator(FindState findState, IServiceProvider serviceProvider) { if (!Directory.Exists(findState.LookIn)) return; Regex pattern = null; if (!String.IsNullOrEmpty(findState.LookInFileTypes)) { pattern = BuildPattern( findState.LookInFileTypes .Split(';') .Select(p => p.Trim()) .Where(p => p.Length > 0) .ToArray() ); } GetPaths(findState.LookIn, pattern, findState.Options.HasFlag(NiFindOptions.SubFolders)); }
public bool SettingsEqual(FindState other) { return (Options & OptionsEqualMask) == (other.Options & OptionsEqualMask) && FindWhat == other.FindWhat && ReplaceWith == other.ReplaceWith && LookIn == other.LookIn && LookInFileTypes == other.LookInFileTypes; }
private void PerformFindAll() { var corePackage = ((NiFinder)_view.GetService(typeof(INiFinder))).CorePackage; var toolWindow = (FindResultsWindow)corePackage.FindToolWindow(typeof(FindResultsWindow), true); ErrorUtil.ThrowOnFailure(toolWindow.Frame.Show()); toolWindow.ResetResults(); while (_state.Iterator.MoveNext()) { string content = _state.Iterator.AllText; List <int> lineOffsets = null; int offset = 0; while (true) { int found; int matchLength; string replacementText; bool isFound; ErrorUtil.ThrowOnFailure(_findHelper.FindInText( _state.FindWhat, null, _state.Options, content, offset, out found, out matchLength, out replacementText, out isFound )); if (!isFound) { break; } if (lineOffsets == null) { lineOffsets = GetLineOffsets(content); } int line = lineOffsets.Count; for (int i = 0; i < lineOffsets.Count; i++) { if (found <= lineOffsets[i]) { line = i; break; } } string lineContent; if (lineOffsets.Count == 0) { lineContent = content; } else if (line == 0) { lineContent = content.Substring(0, lineOffsets[0]); } else if (line == lineOffsets.Count) { lineContent = content.Substring(lineOffsets[lineOffsets.Count - 1]); } else { int lineOffset = lineOffsets[line - 1] + 1; lineContent = content.Substring(lineOffset, lineOffsets[line] - lineOffset); } toolWindow.AddResult( new FindResult(_state.Iterator.DocumentName, found, matchLength), line, lineContent.TrimEnd() ); offset = found + matchLength; } } // FindAll doesn't re-use state. _state = null; }
private void PerformFindChecked(FindAction action) { SaveSettings(); var options = Options & (NiFindOptions.OptionsMask | NiFindOptions.SyntaxMark | NiFindOptions.TargetMask); options &= ~(NiFindOptions.ActionMask | NiFindOptions.Backwards); switch (action) { case FindAction.FindNext: options |= NiFindOptions.Find; break; case FindAction.FindPrevious: options |= NiFindOptions.Find | NiFindOptions.Backwards; break; case FindAction.Replace: options |= NiFindOptions.Replace; break; case FindAction.ReplaceAll: options |= NiFindOptions.ReplaceAll; break; case FindAction.FindAll: options |= NiFindOptions.FindAll; break; case FindAction.SkipFile: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException("action"); } var currentFindState = FindState.Create(this, options, FindTarget); if (_state == null || !_state.SettingsEqual(currentFindState)) { _state = currentFindState; _state.CreateIterator(_view); } _state.Options = options; switch (action) { case FindAction.FindNext: PerformFindSingle(); break; case FindAction.FindPrevious: PerformFindSingle(); break; case FindAction.Replace: PerformReplaceSingle(); break; case FindAction.ReplaceAll: PerformReplaceAll(); break; case FindAction.FindAll: PerformFindAll(); break; case FindAction.SkipFile: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException("action"); } }
/// <summary> /// 重置游戏数据 /// </summary> private void ResetGameData() { mFindState = FindState.None; mTipOpening = false; mFlag = false; }
public ProjectIterator(FindState findState, IServiceProvider serviceProvider) { _findState = findState; _serviceProvider = serviceProvider; }
private void PerformFindAll() { var corePackage = ((NiFinder)_view.GetService(typeof(INiFinder))).CorePackage; var toolWindow = (FindResultsWindow)corePackage.FindToolWindow(typeof(FindResultsWindow), true); ErrorUtil.ThrowOnFailure(toolWindow.Frame.Show()); toolWindow.ResetResults(); while (_state.Iterator.MoveNext()) { string content = _state.Iterator.AllText; List<int> lineOffsets = null; int offset = 0; while (true) { int found; int matchLength; string replacementText; bool isFound; ErrorUtil.ThrowOnFailure(_findHelper.FindInText( _state.FindWhat, null, _state.Options, content, offset, out found, out matchLength, out replacementText, out isFound )); if (!isFound) break; if (lineOffsets == null) lineOffsets = GetLineOffsets(content); int line = lineOffsets.Count; for (int i = 0; i < lineOffsets.Count; i++) { if (found <= lineOffsets[i]) { line = i; break; } } string lineContent; if (lineOffsets.Count == 0) { lineContent = content; } else if (line == 0) { lineContent = content.Substring(0, lineOffsets[0]); } else if (line == lineOffsets.Count) { lineContent = content.Substring(lineOffsets[lineOffsets.Count - 1]); } else { int lineOffset = lineOffsets[line - 1] + 1; lineContent = content.Substring(lineOffset, lineOffsets[line] - lineOffset); } toolWindow.AddResult( new FindResult(_state.Iterator.DocumentName, found, matchLength), line, lineContent.TrimEnd() ); offset = found + matchLength; } } // FindAll doesn't re-use state. _state = null; }