Skip to content

Commit

Permalink
fix(house): read notes
Browse files Browse the repository at this point in the history
-fixed object rotations with the room, they should now be proper.
- added a way to add custom objects easily: `House.CreateObject()`
-
  • Loading branch information
Torwent committed Dec 27, 2024
1 parent d419dd7 commit 150c78d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
33 changes: 30 additions & 3 deletions optional/handlers/house/house.simba
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ e.g., Nexus room, Combat Hall and Quest Hall are all identical.
{$ENDIF}

{$IFNDEF WL_HOUSEMAP_INCLUDED}
{$I WaspLib/optional/handlers/house/housemap.simba}
{$I WaspLib/optional/handlers/house/houseloader.simba}
{$ENDIF}

type
Expand Down Expand Up @@ -116,13 +116,13 @@ begin
if Self.Objects[obj].Coordinates <> [] then
begin
Self.Objects[obj].Coordinates += coordinate;
Self.Objects[obj].Rotations += rotation;
Self.Objects[obj].Rotations += rotation * 90;
Exit;
end;

Self.Objects[obj].SetupCoordinates([coordinate]);
Self.Objects[obj].Size := obj.GetSize();
Self.Objects[obj].Rotations := [rotation];
Self.Objects[obj].Rotations := [rotation * 90];
Self.Objects[obj].SetupUpText(obj.GetUpText());
Self.Objects[obj].Finder := obj.GetFinder();
Self.Objects[obj].Walker := @Self.Walker;
Expand Down Expand Up @@ -166,6 +166,33 @@ begin
end;
end;

function THouseHandler.CreateObject(offset: TPoint; size: vector3; eRoom: EHouseRoom): TRSObjectV2;
var
idx, coordinate: TPoint;
room: THouseRoom;
begin
for idx.Y := 0 to Self.Loader.AMOUNT-1 do
for idx.X := 0 to Self.Loader.AMOUNT-1 do
begin
room := Self.Loader.ReadRoom(idx);
if room.Room <> eRoom then Continue;

coordinate := _RotateRoomOffset(offset, Self.Loader.SIZE, room.Rotation);
coordinate += idx * Self.Loader.SIZE;

if Result.Coordinates <> [] then
begin
Result.Coordinates += coordinate;
Result.Rotations += room.Rotation * 90;
Continue;
end;

Result.SetupCoordinates([coordinate]);
Result.Size := size;
Result.Rotations := [room.Rotation * 90];
Result.Walker := @Self.Walker;
end;
end;

function THouseHandler._BuildGraph(map: TMufasaBitmap): TWebGraphV2;
var
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,7 @@ begin
SetLength(Self.TeleportRooms, Self.AMOUNT, Self.AMOUNT);

if Self.Config.Has('layout') then
begin
try
Self.LoadFromString(Self.Config.GetString('layout'));
except
MessageDlg('House Loader', 'Error loading old house layout.' + LineEnding + 'This could be because it was updated and the old version is not compatible anymore.', TMsgDlgType.mtError, [mbOk]);
WriteLn GetExceptionMessage();
Self.Location := EHouseLocation.RIMMINGTON;
Self.SetColors(EHouseDecoration.WOOD);
Self.DrawMap([EHouseRoom.GARDEN, 0, []], [Self.AMOUNT div 2, Self.AMOUNT div 2]);
end;
end
Self.LoadFromString(Self.Config.GetString('layout'))
else
begin
Self.Location := EHouseLocation.RIMMINGTON;
Expand Down
16 changes: 8 additions & 8 deletions optional/handlers/house/houseutils.simba
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ EHouseObject = (
```
*)
EHouseObject = (
EXIT, REPAIR_STAND, SERVANT_BAG,
LARDER, OAK_LARDER, TEAK_LARDER,
EXIT, LARDER, OAK_LARDER, TEAK_LARDER, REPAIR_STAND, SERVANT_BAG,

GLORY, MYTH_CAPE,

OAK_LECTERN, EAGLE_LECTERN, DEMON_LECTERN, TEAK_EAGLE_LECTERN,
Expand Down Expand Up @@ -268,13 +268,8 @@ begin
end;
end;

function EHouseObject.RotateOffset(size, rotation: Int32): TPoint;
var
coordinate: TPoint;
function _RotateRoomOffset(coordinate: TPoint; size, rotation: Int32): TPoint;
begin
//Don't touch this one.
coordinate := Self.GetOffset();

case rotation of
0: Result := coordinate;
1:
Expand All @@ -291,6 +286,11 @@ begin
end;
end;

function EHouseObject.RotateOffset(size, rotation: Int32): TPoint;
begin
Result := _RotateRoomOffset(Self.GetOffset(), size, rotation);
end;

function EHouseObject.GetUpText(): TStringArray;
begin
//Some uptext were not checked and might be wrong.
Expand Down
9 changes: 9 additions & 0 deletions templates/househandler_example.simba
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ end;
var
MyScriptForm: TMyScriptForm;
{$ENDIF}
var
obj: TRSObjectV2;

begin
{$IFDEF SCRIPT_GUI}
Expand Down Expand Up @@ -105,4 +107,11 @@ begin

while True do
Debug(House.Teleports[EHouseTeleport.MOONCLAN]);

//Custom objects example:
obj := House.CreateObject([14,16], [3.9,1.7,4], EHouseRoom.DINING);
obj.SetupUpText(['Dining table']);

while True do
Debug(obj);
end.

0 comments on commit 150c78d

Please sign in to comment.