Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/micropolis/src/lib/citySaveFormat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it, expect } from 'vitest';
import { loadMicropolisMainModule } from './wasm/node';
import { createNoopJsCallback } from './wasm/callbacks';

describe('city save format', () => {
it('writes a city file the same size as the one it loaded', async () => {
const engine = await loadMicropolisMainModule();
const micropolis = new engine.Micropolis();
micropolis.setCallback(createNoopJsCallback(engine), {});
micropolis.init();
const city = '/cities/haight.cty';
expect(micropolis.loadCity(city)).toBe(true);

micropolis.saveCityAs('/saved.cty');
expect(engine.FS_readFile('/saved.cty').length).toBe(engine.FS_readFile(city).length);

micropolis.delete();
});
});
3 changes: 1 addition & 2 deletions packages/micropolis-engine/src/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ bool Micropolis::saveFile(const std::string &filename)
* linear index x * WORLD_H + y. This is column-major relative to city
* coordinates, and is the same order exposed to JavaScript/WASM tools.
*/
save_short(((short *)&map[0][0]), WORLD_W * WORLD_H, f) &&
save_short(((short *)&mop[0][0]), WORLD_W * WORLD_H, f);
save_short(((short *)&map[0][0]), WORLD_W * WORLD_H, f);

fclose(f);

Expand Down