mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-10 02:08:04 +00:00
make terrain map load async
This commit is contained in:
@@ -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.`);
|
||||
|
||||
Reference in New Issue
Block a user