55 {$I WaspLib/optional/handlers/house/houseloader.simba}
66{$ENDIF}
77
8+ {.DEFINE DEBUG_LAYOUT_FINDER}
9+
810type
911 TPoHLayoutFinder = record(TSRLBaseRecord)
1012 IMAGES_PATH: String;
4042 p := matrix.ArgMax();
4143 if matrix[p.y][p.x] < matchThreshold then
4244 begin
45+ {$IFDEF DEBUG_LAYOUT_FINDER}
4346 WriteLn('Best match was ', matrix[p.y][p.x], ', but threshold was ', matchThreshold);
47+ {$ENDIF}
4448 Exit;
4549 end;
4650 bestValue := matrix[p.y][p.x];
7377 Self.RoomImages[room][i].Free();
7478end;
7579
76- procedure TPoHLayoutFinder.setup ();
80+ procedure TPoHLayoutFinder.Setup ();
7781begin
7882 Self.IMAGES_PATH := {$macro CURRENT_DIRECTORY} + 'images/';
7983 ForceDirectories(Self.IMAGES_PATH);
@@ -87,7 +91,7 @@ function TPoHLayoutFinder.GetRoomImages(room: EHouseRoom): TMufasaBitmapArray;
8791const
8892 ROTATIONS: TStringArray := ['.png', '_90.png', '_180.png', '_270.png'];
8993var
90- fileName, size : String;
94+ fileName: String;
9195 roomImage: TMufasaBitmap;
9296 rotation: String;
9397begin
97101 for rotation in ROTATIONS do
98102 begin
99103 fileName := ExpandFileName(Self.IMAGES_PATH + LowerCase(ToStr(room)) + rotation);
100- self.DebugLn(Format('reading image: %s', [fileName]));
104+ {$IFDEF DEBUG_LAYOUT_FINDER}
105+ Self.DebugLn(Format('reading image: %s', [fileName]));
106+ {$ENDIF}
101107 roomImage.Init(Client.GetMBitmaps());
102108 roomImage.LoadFromFile(fileName);
103109 roomImage.SetName(ToStr(room));
122128
123129function TPoHLayoutFinder.FindAll(rooms: array of EHouseRoom): TPoHLayoutFinderMatchArray;
124130var
125- i, j, x1, y1, x2, y2: Int32;
126- b: TBox;
131+ i, j: Int32;
127132 roomBitmaps: array of TMufasaBitmapArray;
128133 clientImage: TMufasaBitmap;
129134 layoutPoint: TPoint;
@@ -173,24 +178,28 @@ begin
173178 SRL.FindAllTemplatesIn(self.GetRoomImages(r)[0], clientImage, 0.95, matches);
174179end;
175180
176- function TPoHLayoutFinder.Run(): TPoHLayoutFinderMatchArray;
181+ function TPoHLayoutFinder.Run(out topLeft, bottomRight: TPoint ): TPoHLayoutFinderMatchArray;
177182var
178183 matches: TPoHLayoutFinderMatchArray;
179184 match: TPoHLayoutFinderMatch;
180185 bs: TBoxArray;
181- houseRoom: THouseRoom;
182186 r: EHouseRoom;
183187begin
188+ topLeft := [$FFFFFF, $FFFFFF];
189+
184190 for r in EHouseRoom do
185191 begin
186- if r = EHouseRoom.UNKNOWN then
187- continue;
188- if r = EHouseRoom.MENAGERIE_INDOORS then // couldnt get a picture for this room
189- continue;
192+ if r = EHouseRoom.UNKNOWN then Continue;
193+ if r = EHouseRoom.MENAGERIE_INDOORS then Continue; //couldnt get a picture for this room
190194
191- self .Find([r], matches);
195+ Self .Find([r], matches);
192196 for match in matches do
193197 begin
198+ topLeft.X := Min(topLeft.X, match.LayoutPoint.X);
199+ topLeft.Y := Min(topLeft.Y, match.LayoutPoint.Y);
200+ bottomRight.X := Max(bottomRight.X, match.LayoutPoint.X);
201+ bottomRight.Y := Max(bottomRight.Y, match.LayoutPoint.Y);
202+
194203 bs += match.Box;
195204 Result += match;
196205 end;
201210var
202211 LayoutFinder: TPoHLayoutFinder;
203212begin
204- LayoutFinder.setup ();
213+ LayoutFinder.Setup ();
205214end;
0 commit comments