Skip to content

Commit 16eacc1

Browse files
committed
feat(Anvil): read notes
- Finished the anvil interface. - Rewrote item related colors that were "housed" under `RSColors` and now you have them in `TRSItem` or `ERSStack` e.g.: ```pascal WriteLn TRSItem.Border; WriteLn ERSStack.YELLOW.Color; ```
1 parent b18f733 commit 16eacc1

File tree

15 files changed

+502
-110
lines changed

15 files changed

+502
-110
lines changed

osrs/finders/itemfinder.simba

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,70 @@ type
2727
Unzipping, IsSetup: Boolean;
2828
end;
2929

30-
function TRSItemFinder.Align(image, template: TImage): Boolean;
30+
31+
function TRSItemFinder._AlignHelper(img: TImage; tBorder, border: TPointArray; out align: TPoint): Boolean;
3132
var
32-
borderA, borderB, tmp1, tmp2: TPointArray;
33-
bounds: TBox;
34-
align, p: TPoint;
33+
color: TColor;
34+
pt: TPoint;
3535
begin
36-
borderA := image.FindColor(RSColors.ITEM_BORDER, 0);
37-
tmp1 := borderA.ExcludeBox([0,0,image.Width,8]);
38-
borderA := tmp1;
39-
borderB := template.FindColor($000000, 1) + template.FindColor(RSColors.ITEM_BORDER_WHITE, 0);
40-
tmp2 := borderB.ExcludeBox([0,0,template.Width,8]);
41-
borderB := tmp2;
36+
if border = [] then Exit;
4237

43-
if (borderA.Length = 0) or (borderB.Length = 0) then Exit;
38+
align := tBorder.Last - border.Last;
39+
border := border.Offset(align);
4440

45-
align := borderA[High(borderA)] - borderB[High(borderB)];
46-
borderB := borderB.Offset(align);
41+
color := TRSItem.Border;
4742

48-
for p in borderB do
43+
for pt in border do
4944
begin
50-
if p.Y <= 8 then Continue;//stack number... Don't compare.
51-
52-
if not image.InImage(p.X, p.Y) then Exit;
53-
if (image.Pixel[p.X, p.Y] <> RSColors.ITEM_BORDER) then Exit;
45+
if pt.Y <= 8 then
46+
Continue; //stack number... Don't compare.
47+
if not img.InImage(pt.X, pt.Y) then
48+
Exit;
49+
if img.Pixel[pt.X, pt.Y] <> color then
50+
Exit;
5451
end;
5552

56-
bounds := borderA.Bounds;
53+
Result := True;
54+
end;
55+
56+
function TRSItemFinder.Align(image, template: TImage): Boolean;
57+
var
58+
tBorder, bBorder, wBorder: TPointArray;
59+
bounds: TBox;
60+
align: TPoint;
61+
begin
62+
tBorder := image.FindColor(TRSItem.Border, 0).ExcludeBox([0,0,image.Width,8]);
63+
bBorder := template.FindColor(TRSItem.Border, 0).ExcludeBox([0,0,template.Width,8]);
64+
wBorder := template.FindColor(TRSItem.BorderWhite, 0);
65+
66+
if tBorder = [] then
67+
Exit;
68+
69+
if not Self._AlignHelper(image, tBorder, bBorder, align) and
70+
not Self._AlignHelper(image, tBorder, wBorder, align) then
71+
Exit;
72+
73+
bounds := tBorder.Bounds;
5774
image.Crop(bounds);
5875
template.Crop(bounds.Offset([-align.X, -align.Y]));
5976
Result := True;
6077
end;
6178

6279
procedure TRSItemFinder.Clean(image, template: TImage);
6380
var
64-
color: TColor;
81+
stack: ERSStack;
6582
tpa: TPointArray;
6683
begin
6784
image.DrawColor := $0;
6885
template.DrawColor := $0;
6986

7087
template.DrawTPA(image.FindColor($0, 0));
7188

72-
tpa := image.FindColor(RSColors.ITEM_SHADOW, 0);
73-
for color in RSColors.STACK_COLORS do
74-
tpa += template.FindColor(color, 0);
89+
tpa := image.FindColor(TRSItem.Shadow, 0);
90+
for stack := Low(ERSStack) to High(ERSStack) do
91+
tpa += template.FindColor(stack.Color, 0);
7592

76-
tpa += template.FindColor(RSColors.ITEM_BORDER, 0);
93+
tpa += template.FindColor(TRSItem.Border, 0);
7794
image.DrawTPA(tpa);
7895
template.DrawTPA(tpa);
7996
end;
@@ -262,7 +279,7 @@ begin
262279
for i := 0 to High(boxes) do
263280
begin
264281
if skip[i] then Continue;
265-
if not RSColors.HasItem(boxes[i]) then
282+
if not TRSItem.InBounds(boxes[i]) then
266283
begin
267284
skip[i] := True;
268285
Continue;
@@ -303,7 +320,7 @@ begin
303320
for i := 0 to High(boxes) do
304321
begin
305322
if skip[i] then Continue;
306-
if not RSColors.HasItem(boxes[i]) then
323+
if not TRSItem.InBounds(boxes[i]) then
307324
begin
308325
skip[i] := True;
309326
Continue;
@@ -353,7 +370,7 @@ begin
353370
for i := 0 to High(boxes) do
354371
begin
355372
if skip[i] then Continue;
356-
if not RSColors.HasItem(boxes[i]) then
373+
if not TRSItem.InBounds(boxes[i]) then
357374
begin
358375
skip[i] := True;
359376
Continue;
@@ -398,7 +415,7 @@ var
398415
tpa: TPointArray;
399416
border: TImage;
400417
begin
401-
tpa := img.FindColor(RSColors.ITEM_BORDER, 0, [0, 9, 35, 31]);
418+
tpa := img.FindColor(TRSItem.Border, 0, [0, 9, 35, 31]);
402419
if tpa = [] then Exit;
403420
border := new TImage(36, 32);
404421
border.DrawColor := $FFFFFF;

osrs/interfaces/gametabs/achievements.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ Internal method used to count the available tabs on the {ref}`Achievements` game
378378
*)
379379
function TRSAchievements.CountTabs(): Integer;
380380
begin
381-
Result := Length(Target.FindColor(RSColors.ITEM_BORDER, 0, Self.TabsArea).Cluster(1.5));
381+
Result := Length(Target.FindColor(TRSItem.Border, 0, Self.TabsArea).Cluster(1.5));
382382
end;
383383

384384
(*

osrs/interfaces/gametabs/inventory.simba

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Internal method used to setup the {ref}`TRSInventory` coordinates.
4747

4848
This is automatically called for you on the {ref}`Inventory variable`.
4949
*)
50-
5150
function TRSInventory.Open(): Boolean; forward;
5251

5352
procedure TRSInventory.SetupGameTab();
@@ -127,7 +126,7 @@ WriteLn Inventory.IsSelected('Vial');
127126
function TRSInventory.IsSelected(slot: TBox): Boolean;
128127
begin
129128
slot.Y1 += 8;
130-
Result := Target.HasColor(RSColors.ITEM_BORDER_WHITE, 1, 1, slot);
129+
Result := Target.HasColor(TRSItem.BorderWhite, 1, 1, slot);
131130
end;
132131

133132
function TRSInventory.IsSelected(slot: Integer): Boolean; overload;

osrs/interfaces/gametabs/stats.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ begin
229229
if not Self.Open() then Exit(-1);
230230

231231
with Self.Skills[skill] do
232-
Result := OCR.RecognizeNumber([X1, Y2 - (Height div 2), X2, Y2], RSFonts.PLAIN_11, [RSColors.STACK_YELLOW], 0);
232+
Result := OCR.RecognizeNumber([X1, Y2 - (Height div 2), X2, Y2], RSFonts.PLAIN_11, [ERSStack.YELLOW.Color], 0);
233233

234234
if Result > 0 then
235235
Self.Levels[skill] := Result;

0 commit comments

Comments
 (0)