Skip to content

Commit 25807d1

Browse files
committed
fix: read notes
- made skunks house layout reader less verbose unless you add `{$DEFINE DEBUG_LAYOUT_FINDER}` - made skunks layout reader results be offset to the center of the house layout
1 parent 0e2c8e1 commit 25807d1

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

optional/handlers/house/house.simba

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,15 +1395,26 @@ var
13951395
tmp: TMufasaBitmap;
13961396
parent: TControl;
13971397
imgbox: TSimbaImageBox;
1398+
topLeft, bottomRight, offset, center: TPoint;
13981399
begin
1400+
if not RSInterface.IsOpen(ERSInterfaceType.CLASSIC) then
1401+
begin
1402+
MessageDlg('LayoutFinder', 'You need to open the house viewer to read the layout!', mtWarning, [mbOk]);
1403+
Exit;
1404+
end;
1405+
13991406
parent := TComboBox(sender).getParent().getParent();
14001407
imgbox := parent.GetChild('poh_builder');
14011408

1402-
matches := LayoutFinder.Run();
1409+
matches := LayoutFinder.Run(topLeft, bottomRight);
1410+
1411+
center := [House.Loader.AMOUNT div 2, House.Loader.AMOUNT div 2];
1412+
offset := [Abs(bottomRight.X - topLeft.X - center.X), Abs(bottomRight.Y - topLeft.Y - center.Y)];
1413+
14031414
for match in matches do
14041415
begin
1405-
House.Loader.DrawMap(match.ToHouseRoom(), match.LayoutPoint);
1406-
House.Loader.WriteRoom(match.ToHouseRoom(), match.LayoutPoint);
1416+
House.Loader.DrawMap(match.ToHouseRoom(), match.LayoutPoint + offset + [1,1]);
1417+
House.Loader.WriteRoom(match.ToHouseRoom(), match.LayoutPoint + offset + [1,1]);
14071418
end;
14081419

14091420
tmp := House.Loader.Map.Copy();

optional/handlers/house/layout_finder.simba

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
{$I WaspLib/optional/handlers/house/houseloader.simba}
66
{$ENDIF}
77

8+
{.DEFINE DEBUG_LAYOUT_FINDER}
9+
810
type
911
TPoHLayoutFinder = record(TSRLBaseRecord)
1012
IMAGES_PATH: String;
@@ -40,7 +42,9 @@ begin
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];
@@ -73,7 +77,7 @@ begin
7377
Self.RoomImages[room][i].Free();
7478
end;
7579

76-
procedure TPoHLayoutFinder.setup();
80+
procedure TPoHLayoutFinder.Setup();
7781
begin
7882
Self.IMAGES_PATH := {$macro CURRENT_DIRECTORY} + 'images/';
7983
ForceDirectories(Self.IMAGES_PATH);
@@ -87,7 +91,7 @@ function TPoHLayoutFinder.GetRoomImages(room: EHouseRoom): TMufasaBitmapArray;
8791
const
8892
ROTATIONS: TStringArray := ['.png', '_90.png', '_180.png', '_270.png'];
8993
var
90-
fileName, size: String;
94+
fileName: String;
9195
roomImage: TMufasaBitmap;
9296
rotation: String;
9397
begin
@@ -97,7 +101,9 @@ begin
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));
@@ -122,8 +128,7 @@ end;
122128

123129
function TPoHLayoutFinder.FindAll(rooms: array of EHouseRoom): TPoHLayoutFinderMatchArray;
124130
var
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);
174179
end;
175180

176-
function TPoHLayoutFinder.Run(): TPoHLayoutFinderMatchArray;
181+
function TPoHLayoutFinder.Run(out topLeft, bottomRight: TPoint): TPoHLayoutFinderMatchArray;
177182
var
178183
matches: TPoHLayoutFinderMatchArray;
179184
match: TPoHLayoutFinderMatch;
180185
bs: TBoxArray;
181-
houseRoom: THouseRoom;
182186
r: EHouseRoom;
183187
begin
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;
@@ -201,5 +210,5 @@ end;
201210
var
202211
LayoutFinder: TPoHLayoutFinder;
203212
begin
204-
LayoutFinder.setup();
213+
LayoutFinder.Setup();
205214
end;

0 commit comments

Comments
 (0)