make terrain map load async

This commit is contained in:
evanpelle
2024-08-30 11:56:29 -07:00
parent 64265b1a75
commit 9cfe983824
2 changed files with 15 additions and 13 deletions
+5 -5
View File
@@ -29,8 +29,11 @@ export class Terrain {
constructor(public type: TerrainType) { }
}
export function loadTerrainMap(): TerrainMap {
const fileData = binAsString;
export async function loadTerrainMap(): Promise<TerrainMap> {
// Simulate an asynchronous file load
const fileData = await new Promise<string>((resolve) => {
setTimeout(() => resolve(binAsString), 100);
});
console.log(`Loaded data length: ${fileData.length} bytes`);
@@ -40,9 +43,6 @@ export function loadTerrainMap(): TerrainMap {
console.log(`Decoded dimensions: ${width}x${height}`);
// Log the first 100 bytes of data (including the width and height bytes)
// logBinaryAsAscii(fileData, 100);
// Check if the data length matches the expected size
if (fileData.length != width * height + 4) { // +4 for the width and height bytes
throw new Error(`Invalid data: buffer size ${fileData.length} incorrect for ${width}x${height} terrain plus 4 bytes for dimensions.`);