@@ -49,7 +49,7 @@ unless specified otherwise.
4949 Name: String;
5050 Slots: ^TRSSlotInterface;
5151 DiscoverOffset: TPoint;
52- CheckFunction: function (): Boolean of object ;
52+ PreConditionFunction: TInterfacePreConditionFunction ;
5353 end;
5454
5555(*
@@ -82,12 +82,17 @@ Bank.Slots.Setup('Bank.Slots', Bank.SlotBoxes, @Bank.FindItemBoundaries);
8282Bank.Items.Setup('Bank.Items', @Bank.Slots, [0, 1], @Bank.IsOpen);
8383```
8484*)
85- procedure TRSItemInterface.Setup(name: String; slots: ^TRSSlotInterface; discoverOffset: TPoint; checkFunc: function (): Boolean of object = nil);
85+ procedure TRSItemInterface.Setup(
86+ name: String;
87+ slots: ^TRSSlotInterface;
88+ discoverOffset: TPoint;
89+ checkFunc: TInterfacePreConditionFunction = nil
90+ );
8691begin
8792 Self.Name := name;
8893 Self.Slots := slots;
8994 Self.DiscoverOffset := discoverOffset;
90- Self.CheckFunction := @checkFunc;
95+ Self.PreConditionFunction := @checkFunc;
9196end;
9297
9398
@@ -110,7 +115,7 @@ function TRSItemInterface.IndexOf(items: TRSItemArray): Integer;
110115var
111116 match: TImageMatch;
112117begin
113- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
118+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
114119 Exit(-1);
115120 if ItemFinder.Find(items, Self.Slots^.Boxes(), match) then
116121 Exit(match.Index);
@@ -137,7 +142,7 @@ function TRSItemInterface.IndicesOf(items: TRSItemArray): TIntegerArray;
137142var
138143 match: TImageMatch;
139144begin
140- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
145+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
141146 Exit;
142147
143148 for match in ItemFinder.FindAll(items, Self.Slots^.Boxes()) do
@@ -170,7 +175,7 @@ function TRSItemInterface.FindAny(items: TRSItemArray; out slot: TBox): Boolean;
170175var
171176 match: TImageMatch;
172177begin
173- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
178+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
174179 Exit;
175180
176181 Result := ItemFinder.Find(items, Self.Slots^.Boxes(), match);
@@ -210,7 +215,7 @@ function TRSItemInterface.Find(items: TRSItemArray; out slot: Integer): Boolean;
210215var
211216 match: TImageMatch;
212217begin
213- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
218+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
214219 Exit;
215220
216221 Result := ItemFinder.Find(items, Self.Slots^.Boxes(), match);
@@ -254,7 +259,7 @@ function TRSItemInterface.FindAll(items: TRSItemArray): TBoxArray;
254259var
255260 match: TImageMatch;
256261begin
257- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
262+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
258263 Exit;
259264
260265 for match in ItemFinder.FindAll(items, Self.Slots^.Boxes()) do
267272 i: Integer;
268273begin
269274 slots := [];
270- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
275+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
271276 Exit;
272277
273278 Result := ItemFinder.FindAll(items, Self.Slots^.Boxes(), matches);
282287 i: Integer;
283288begin
284289 boxes := [];
285- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
290+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
286291 Exit;
287292
288293 Result := ItemFinder.FindAll(items, Self.Slots^.Boxes(), matches);
@@ -361,7 +366,7 @@ function TRSItemInterface.ContainsAll(items: TRSItemArray): Boolean;
361366var
362367 matches: TImageMatchArray;
363368begin
364- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
369+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
365370 Exit;
366371 Result := ItemFinder.FindAll(items, Self.Slots^.Boxes(), matches);
367372end;
409414
410415function TRSItemInterface.Discover(slot: Integer): TRSItemArray;
411416begin
412- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
417+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
413418 Exit;
414419
415420 Result := Self._Discover(slot);
@@ -419,7 +424,7 @@ function TRSItemInterface.DiscoverAllEx(): array of TRSItemArray;
419424var
420425 slot: Integer;
421426begin
422- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
427+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
423428 Exit;
424429
425430 for slot := Low(Self.Slots^.Boxes()) to High(Self.Slots^.Boxes()) do
431436 slot: Integer;
432437 items: TRSItemArray;
433438begin
434- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
439+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
435440 Exit;
436441
437442 for slot := Low(Self.Slots^.Boxes()) to High(Self.Slots^.Boxes()) do
693698 center: TPoint;
694699 dist, closest: Double;
695700begin
696- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
701+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
697702 Exit;
698703 slots := Self.Slots^.Boxes();
699704 if not ItemFinder.FindAll([item], slots, matches) then Exit;
@@ -753,7 +758,7 @@ function TRSItemInterface.Interact(slot: Integer; option: String = ''): Boolean;
753758var
754759 box: TBox;
755760begin
756- if (@Self.CheckFunction <> nil) and not Self.CheckFunction () then
761+ if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction () then
757762 Exit;
758763
759764 if not Self.Slots^.IsUsed(slot) then Exit;
0 commit comments