Skip to content

Commit

Permalink
Merge pull request #237 from KeepBotting/master
Browse files Browse the repository at this point in the history
Adding getUpText() and isUpText()
  • Loading branch information
slackydev committed Feb 28, 2016
2 parents c1adb70 + 5979837 commit b5eb3b3
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions lib/core/text.simba
Expand Up @@ -9,8 +9,18 @@ The source for this file can be found `here <https://github.com/SRL/SRL-6/blob/m

*)

{$loadlib SimpleOCR}

{$f-}

(*
var ocr
~~~~~~~~~
An instance of SimpleOCR.
*)
var
ocr: TSimpleOCR;

(*
findText
~~~~~~~~
Expand Down Expand Up @@ -696,5 +706,112 @@ begin

end;

(*
getUpText
~~~~~~~~~~~~~~~~

.. code-block:: pascal

function getUpText(): string;

Returns the current UpText (the text in the top-left corner of the screen).

.. note::

- by slacky & KeepBotting
- Last Modified: 27 February 2016 by KeepBotting

Example:

.. code-block:: pascal

writeLn(getUpText());
*)
function getUpText(): string;
var
box: TBox := intToBox(4, 5, 500, 25);
filter: TCompareRules := [-1, 85, true, 60];
begin
ocr.clientID := exportImageTarget();
exit(ocr.recognize(box, filter));
end;

(*
isUpText
~~~~~~~~~~~~~~~

.. code-block:: pascal

function isUpText(txt: string; waitTime: integer = 100): boolean;

Returns true if the string 'txt' is found in the current UpText.
Will wait up to 'waitTime' to find the text before exiting the function.

.. note::

- by KeepBotting
- Last Modified: 27 February 2016 by KeepBotting

Example:

.. code-block:: pascal

if isUpText('Banker') then writeLn('Found the bank!');
*)
function isUpText(txt: string; waitTime: integer = 100): boolean;
var
t: TTimeMarker;
begin
t.start();

repeat
if (pos(txt, getUpText()) > 0) then exit(true);
wait(20);
until (t.getTime() > waitTime);
end;

(*
isUpText
~~~~~~~~~~~~~~~

.. code-block:: pascal

function isUpText(txt: TStringArray; waitTime: integer = 100): boolean; overload;

Overloaded function. Takes a TStringArray instead of a string.

Returns true if any one of the indicies in 'txt' is found in the current UpText.
Will wait up to 'waitTime' to find the text before exiting the function.

.. note::

- by KeepBotting
- Last Modified: 27 February 2016 by KeepBotting

Example:

.. code-block:: pascal

if isUpText(['Bank', 'Banker', 'Booth']) then writeLn('Found the bank!');
*)
function isUpText(txt: TStringArray; waitTime: integer = 100): boolean; overload;
var
i: integer;
t: TTimeMarker;
begin
t.start();

repeat
for i := 0 to high(txt) do
if (pos(txt[i], getUpText()) > 0) then exit(true);
wait(20);
until (t.getTime() > waitTime);
end;

begin
ocr.init(FontPath + 'UpCharsEx');
ocr.fontData.spaceWidth := 5;
end;

{$f+}

0 comments on commit b5eb3b3

Please sign in to comment.