# MapLoader This file is responsible for loading maps for TRSMap. It was made from scratch by Torwent but heavily inspired in the original TRSWalker by Slacky and it's future iterations made by Olly. ```{note} Most things in this file are for internal use only and you shouldn't use them directly nor modify them if you don't quite understand them. ``` - - - (RSMAP_PATH)= # const RSMAP_PATH Default path to look for map files. - - - (TRSMapChunk)= ## type TRSMapChunk ```pascal TRSMapChunk = record Chunk: TBox; Planes: TIntegerArray; end; ``` Helper record to store chunk data with a name associated with. - - - (ERSMap)= ## type ERSMap ```pascal ERSMap = (NORMAL, HEIGHT, COLLISION); ``` Enum of map types. - - - (ERSMapJSON)= ## type ERSMapJSON ```pascal ERSMapJSON = (OBJECTS, NPCS); ``` Enum of map json types. - - - (TRSChunkLoader)= ## type TRSChunkLoader ```pascal TRSChunkLoader = record(TSRLBaseRecord) Cache: String; end; ``` ChunkLoader record, this is what's responsible for loading a "chunks" map. - - - ## TRSChunkLoader.Setup ```pascal procedure TRSChunkLoader.Setup(name, cache: String); ``` This is responsible for setting up the TRSChunkLoader. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TRSChunkLoader.GetBitmap ```pascal function TRSChunkLoader.GetBitmap(chunk: String; plane: UInt32; map: ERSMap): TMufasaBitmap; function TRSChunkLoader.GetBitmap(chunk: TPoint; plane: UInt32; map: ERSMap): TMufasaBitmap; overload; ``` Returns a chunk bitmap. If possible, it will be loaded from a cached .bmp file. If no cache file exists, the .png file is unzipped, loaded and saved as a .bmp for future uses. The files are cached as .bmp because .bmp is a raw format and simba loads them much faster that way. ```{note} This are internal methods. Don't use them if you don't know what you are doing. ``` - - - ## TRSChunkLoader.GetJSONFile ```pascal function TRSChunkLoader.GetJSONFile(chunk: String; plane: UInt32; jsonType: ERSMapJSON): TJSONArray; function TRSChunkLoader.GetJSONFile(chunk: TPoint; plane: UInt32; jsonType: ERSMapJSON): TJSONArray; overload; ``` Returns a chunk json file. If possible, it will be loaded from a cached file. If no cache file exists, the file is unzipped, loaded and saved into cache for future uses. ```{note} This are an internal methods. Don't use them if you don't know what you are doing. ``` - - - ## TRSChunkLoader.GetChunks ```pascal function TRSChunkLoader.GetChunks(start, finish: TPoint): TPointArray; static; ``` Simple methods that will return all chunks in between a `start` and `finish` chunks. This will also fix their order if required, as osrs chunks are oddly numbered from bottom to top on the Y axis. Example: ```pascal WriteLn TRSChunkLoader.GetChunks([20,20], [22,22]).ToString(); //This will return: //[[20, 20], [20, 21], [20, 22], [21, 20], [21, 21], [21, 22], [22, 20], [22, 21], [22, 22]]; ``` - - - ## TRSChunkLoader.GetMap ```pascal function TRSChunkLoader.GetMap(chunks: TPointArray; plane: UInt32; map: ERSMap): TMufasaBitmap; function TRSChunkLoader.GetMap(start, finish: TPoint; plane: UInt32; map: ERSMap): TMufasaBitmap; overload; ``` This returns a bitmap of all the `chunks` you pass into it or `start` and `finish` plus everything inbetween. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TRSChunkLoader.BuildGraph ```pascal function TRSChunkLoader.BuildGraph(name: String; map: TMufasaBitmap): TWebGraphV2; ``` Magically builds a webgraph for you for a given collision map passed into `map`. The collision map can only have 4 colors: - white ($FFFFFF) for walkable space - black ($000000) for non walkable space - red ($0000FF) for doors (optional) - gray ($333333) for objects (optional) ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TRSChunkLoader.GetGraph ```pascal function TRSChunkLoader.GetGraph(name: String; plane: UInt32; map: TMufasaBitmap): TWebGraphV2; ``` Returns a TWebGraphV2 for the given `map`. If the graph is already cached we load it from cache, otherwise we build it and save it into cache. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TRSChunkLoader.GetJSON ```pascal function TRSChunkLoader.GetJSON(chunks: TPointArray; plane: UInt32; jsonType: ERSMapJSON): TJSONArray; function TRSChunkLoader.GetJSON(start, finish: TPoint; level: UInt32; json: ERSMapJSON): TMufasaBitmap; ``` Returns a merged JSON file of all the jsons of our `chunks` or `start` and `finish` plus everything inbetween. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - (TRSLegacyMapLoader)= ## type TRSLegacyMapLoader ```pascal TRSLegacyMapLoader = record(TSRLBaseRecord) Cache: String; end; ``` LegacyChunkLoader record, this is what's responsible for loading a map from a file, same as the original TRSWalker by slacky. - - - ## TRSLegacyMapLoader.Setup ```pascal procedure TRSLegacyMapLoader.Setup(name, cache: String); ``` This is responsible for setting up the TRSLegacyMapLoader. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TRSLegacyMapLoader.FindFiles ```pascal function TRSLegacyMapLoader.FindFiles(filename: String): TStringArray; ``` This is responsible for finding the map file to be loaded. Will only find `.png` or `.bmp` files in `RSMAP_PATH`. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TRSLegacyMapLoader.GetMap ```pascal function TRSLegacyMapLoader.GetMap(filename: String; crop: TBox = []): TMufasaBitmap; ``` Returns the map file from cache if it exists, if it doesn't, the map is loaded and saved as a `.bmp` cache file for next usages. .bmp is used for caching because it's a raw image format and Simba loads it much faster than .png. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - (TRSMapRegion)= ## type TRSMapRegion ```pascal TRSMapRegion = record Name: String; Original: TBox; Region: TBox; Plane: UInt32; Offset: TPoint; end; ``` Map region record, responsible for storing the map region/chunk data. ```{note} This is an internal type. Don't use it if you don't know what you are doing. ``` - - - (TRSMapLoader)= ## type TRSMapLoader ```pascal TRSMapLoader = record(TSRLBaseRecord) Cache: String; Map, Heightmap, Collision, DownscaledMap: TMufasaBitmap; MapBox: TBox; Graph: TWebGraphV2; Regions: array of TRSMapRegion; Padding, Downscale: UInt32; Loader: TRSChunkLoader; LegacyLoader: TRSLegacyMapLoader; UsingChunks, SkipGraph: Boolean; ObjectData: TJSONArray; NPCData: TJSONArray; end; ``` TRSMapLoader is what's responsible for loading a map for TRSMap. It will use `TRSChunkLoader` or `TRSLegacyMapLoader` depending on what the situation requires. ```{note} This is an internal type. Don't use it if you don't know what you are doing. ```