# MapLoader This file is responsible for loading maps for TMap. It was made from scratch by Torwent but heavily inspired in the original TWalker 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. ``` - - - (MAP_PATH)= # const MAP_PATH Default path to look for map files. - - - (TMapChunk)= ## type TMapChunk ```pascal TMapChunk = record Chunk: TBox; Planes: TIntegerArray; end; ``` Helper record to store chunk data with a name associated with. - - - (EGameMap)= ## type EGameMap ```pascal EGameMap = (NORMAL, HEIGHT, COLLISION); ``` Enum of map types. - - - (EGameMapJSON)= ## type EGameMapJSON ```pascal EGameMapJSON = (OBJECTS, NPCS); ``` Enum of map json types. - - - (TChunkLoader)= ## type TChunkLoader ```pascal TChunkLoader = record(TSRLBaseRecord) Cache: String; end; ``` ChunkLoader record, this is what's responsible for loading a "chunks" map. - - - ## TChunkLoader.Setup ```pascal procedure TChunkLoader.Setup(name, cache: String); ``` This is responsible for setting up the TChunkLoader. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TChunkLoader.GetBitmap ```pascal function TChunkLoader.GetBitmap(chunk: String; plane: UInt32; map: EGameMap): TMufasaBitmap; function TChunkLoader.GetBitmap(chunk: TPoint; plane: UInt32; map: EGameMap): 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. ``` - - - ## TChunkLoader.GetJSONFile ```pascal function TChunkLoader.GetJSONFile(chunk: String; plane: UInt32; jsonType: EGameMapJSON): TJSONArray; function TChunkLoader.GetJSONFile(chunk: TPoint; plane: UInt32; jsonType: EGameMapJSON): 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. ``` - - - ## TChunkLoader.GetChunks ```pascal function TChunkLoader.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 game chunks are oddly numbered from bottom to top on the Y axis. Example: ```pascal WriteLn TChunkLoader.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]]; ``` - - - ## TChunkLoader.GetMap ```pascal function TChunkLoader.GetMap(chunks: TPointArray; plane: UInt32; map: EGameMap): TMufasaBitmap; function TChunkLoader.GetMap(start, finish: TPoint; plane: UInt32; map: EGameMap): 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. ``` - - - ## TChunkLoader.BuildGraph ```pascal function TChunkLoader._BuildGraph(map: TMufasaBitmap; white, red: TPointArray): TWebGraphV2; function TChunkLoader.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. ``` - - - ## TChunkLoader.GetGraph ```pascal function TChunkLoader.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. ``` - - - ## TChunkLoader.GetJSON ```pascal function TChunkLoader.GetJSON(chunks: TPointArray; plane: UInt32; jsonType: EGameMapJSON): TJSONArray; function TChunkLoader.GetJSON(start, finish: TPoint; level: UInt32; json: EGameMapJSON): 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. ``` - - - (TLegacyMapLoader)= ## type TLegacyMapLoader ```pascal TLegacyMapLoader = record(TSRLBaseRecord) Cache: String; end; ``` LegacyChunkLoader record, this is what's responsible for loading a map from a file, same as the original TWalker by slacky. - - - ## TLegacyMapLoader.Setup ```pascal procedure TLegacyMapLoader.Setup(name, cache: String); ``` This is responsible for setting up the TLegacyMapLoader. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TLegacyMapLoader.FindFiles ```pascal function TLegacyMapLoader.FindFiles(filename: String): TStringArray; ``` This is responsible for finding the map file to be loaded. Will only find `.png` or `.bmp` files in `MAP_PATH`. ```{note} This is an internal method. Don't use it if you don't know what you are doing. ``` - - - ## TLegacyMapLoader.GetMap ```pascal function TLegacyMapLoader.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. ``` - - - (TMapRegion)= ## type TMapRegion ```pascal TMapRegion = 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. ``` - - - (TMapLoader)= ## type TMapLoader ```pascal TMapLoader = record(TSRLBaseRecord) Cache: String; Map, Heightmap, Collision, DownscaledMap: TMufasaBitmap; MapBox: TBox; Graph: TWebGraphV2; Regions: array of TMapRegion; Padding, Downscale: UInt32; Loader: TChunkLoader; LegacyLoader: TLegacyMapLoader; UsingChunks, SkipGraph: Boolean; ObjectData: TJSONArray; NPCData: TJSONArray; end; ``` TMapLoader is what's responsible for loading a map for TMap. It will use `TChunkLoader` or `TLegacyMapLoader` 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. ```