🚧 Preview design placement
This commit is contained in:
+59
-34
@@ -32,6 +32,19 @@ type
|
||||
constructor CreateFromStream(AStream: TStream);
|
||||
end;
|
||||
|
||||
TUoaDesign = class
|
||||
private
|
||||
FHeader: TUoaDesignHeader;
|
||||
FTiles: TStaticItemList;
|
||||
|
||||
constructor Create(AHeader: TUoaDesignHeader; AData: TStream);
|
||||
public
|
||||
property Header: TUoaDesignHeader read FHeader;
|
||||
property Tiles: TStaticItemList read Ftiles;
|
||||
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TUoaDesigns }
|
||||
|
||||
TUoaDesigns = class
|
||||
@@ -42,8 +55,7 @@ type
|
||||
constructor Create(AIdxFile, ABinFile: String);
|
||||
destructor Destroy; override;
|
||||
|
||||
function LoadTiles(AHeader: TUoaDesignHeader; AOffsetX, AOffsetY: Word;
|
||||
AOffsetZ: ShortInt): TStaticItemList;
|
||||
function LoadDesign(AHeader: TUoaDesignHeader): TUoaDesign;
|
||||
public
|
||||
property Headers: TUoaDesignHeaders read FHeaders;
|
||||
end;
|
||||
@@ -65,6 +77,49 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TUoaDesign }
|
||||
|
||||
constructor TUoaDesign.Create(AHeader: TUoaDesignHeader; AData: TStream);
|
||||
var
|
||||
i: Integer;
|
||||
tile: TStaticItem;
|
||||
version: Int32;
|
||||
|
||||
function ReadInt: Int32;
|
||||
begin
|
||||
AData.Read(Result, SizeOf(Result));
|
||||
end;
|
||||
|
||||
begin
|
||||
FHeader := AHeader;
|
||||
FTiles := TStaticItemList.Create(True);
|
||||
AData.Seek(FHeader.FilePosition, soFromBeginning);
|
||||
for i := 0 to FHeader.TileCount - 1 do
|
||||
begin
|
||||
AData.Read(version, SizeOf(version));
|
||||
if (version < 0) or (version > 1) then
|
||||
raise Exception.Create('Unsupported binary version');
|
||||
|
||||
tile := TStaticItem.Create(nil);
|
||||
tile.TileID := ReadInt;
|
||||
tile.X := ReadInt;
|
||||
tile.Y := ReadInt;
|
||||
tile.Z := ReadInt;
|
||||
ReadInt; // Level; unused
|
||||
|
||||
if version = 1 then
|
||||
tile.Hue := ReadInt;
|
||||
|
||||
FTiles.Add(tile);
|
||||
end;
|
||||
end;
|
||||
|
||||
destructor TUoaDesign.Destroy;
|
||||
begin
|
||||
FTiles.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TUoaDesignHeaders }
|
||||
|
||||
constructor TUoaDesignHeaders.CreateFromStream(AStream: TStream);
|
||||
@@ -120,39 +175,9 @@ begin
|
||||
Headers.Free;
|
||||
end;
|
||||
|
||||
function TUoaDesigns.LoadTiles(AHeader: TUoaDesignHeader; AOffsetX,
|
||||
AOffsetY: Word; AOffsetZ: ShortInt): TStaticItemList;
|
||||
var
|
||||
i: Integer;
|
||||
tile: TStaticItem;
|
||||
version: Int32;
|
||||
|
||||
function ReadInt: Int32;
|
||||
begin
|
||||
FData.Read(Result, SizeOf(Result));
|
||||
end;
|
||||
|
||||
function TUoaDesigns.LoadDesign(AHeader: TUoaDesignHeader): TUoaDesign;
|
||||
begin
|
||||
Result := TStaticItemList.Create(True);
|
||||
FData.Seek(AHeader.FilePosition, soFromBeginning);
|
||||
for i := 0 to AHeader.TileCount - 1 do
|
||||
begin
|
||||
FData.Read(version, SizeOf(version));
|
||||
if (version < 0) or (version > 1) then
|
||||
raise Exception.Create('Unsupported binary version');
|
||||
|
||||
tile := TStaticItem.Create(nil);
|
||||
tile.TileID := ReadInt;
|
||||
tile.X := AOffsetX + ReadInt;
|
||||
tile.Y := AOffsetY + ReadInt;
|
||||
tile.Z := AOffsetZ + ReadInt;
|
||||
ReadInt; // TODO: Level??
|
||||
|
||||
if version = 1 then
|
||||
tile.Hue := ReadInt;
|
||||
|
||||
Result.Add(tile);
|
||||
end;
|
||||
Result := TUoaDesign.Create(AHeader, FData);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user