Skip to content

Commit

Permalink
Bugfix: Handle newer version format (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
photogineer committed Sep 18, 2023
1 parent 7c37fff commit 6a06672
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
47 changes: 47 additions & 0 deletions lib/saveHandlers/oldWorldSaveHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ describe('OldWorldSaveHandler', () => {
expect(handler.civData[1].isCurrentTurn).to.eq(true);
});

it('should parse correctly (newer format)', () => {
const buffer = fs.readFileSync('testdata/saves/oldWorld/Turn1B.zip');
const handler = new OldWorldSaveHandler(buffer);

expect(handler.gameSpeed).to.eq('');
expect(handler.gameTurn).to.eq(1);
expect(handler.mapFile).to.eq('MAPCLASS_CoastalRainBasin');
expect(handler.mapSize).to.eq('MAPSIZE_MEDIUM');

expect(handler.parsedDlcs.length).to.eq(0);

expect(handler.civData.length).to.eq(5);
expect(handler.civData[0].isCurrentTurn).to.eq(false);
expect(handler.civData[0].leaderName).to.eq('NATION_ASSYRIA');
expect(handler.civData[0].password).to.eq('');
expect(handler.civData[0].playerName).to.eq('matt');
expect(handler.civData[0].type).to.eq(ActorType.HUMAN);
expect(handler.civData[1].isCurrentTurn).to.eq(true);
});

it('should update civs correctly', () => {
const buffer = fs.readFileSync('testdata/saves/oldWorld/Turn1.zip');
let handler = new OldWorldSaveHandler(buffer);
Expand Down Expand Up @@ -53,6 +73,33 @@ describe('OldWorldSaveHandler', () => {
expect(handler.civData[1].isCurrentTurn).to.eq(true);
});

it('should update civs correctly (newer format)', () => {
const buffer = fs.readFileSync('testdata/saves/oldWorld/Turn1B.zip');
let handler = new OldWorldSaveHandler(buffer);

const civ = handler.civData[0];
//civ.password = 'password';
civ.playerName = 'playerName';
//civ.type = ActorType.AI;

handler = new OldWorldSaveHandler(handler.getData());

expect(handler.gameSpeed).to.eq('');
expect(handler.gameTurn).to.eq(1);
expect(handler.mapFile).to.eq('MAPCLASS_CoastalRainBasin');
expect(handler.mapSize).to.eq('MAPSIZE_MEDIUM');

expect(handler.parsedDlcs.length).to.eq(0);

expect(handler.civData.length).to.eq(5);
expect(handler.civData[0].isCurrentTurn).to.eq(false);
expect(handler.civData[0].leaderName).to.eq('NATION_ASSYRIA');
expect(handler.civData[0].password).to.eq('');
expect(handler.civData[0].playerName).to.eq('playerName');
expect(handler.civData[0].type).to.eq(ActorType.HUMAN);
expect(handler.civData[1].isCurrentTurn).to.eq(true);
});

it('should detect dead correctly', () => {
const buffer = fs.readFileSync('testdata/saves/oldWorld/deadtest.zip');
const handler = new OldWorldSaveHandler(buffer);
Expand Down
5 changes: 4 additions & 1 deletion lib/saveHandlers/oldWorldSaveHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export class OldWorldSaveHandler implements SaveHandler {
const entries = zip.getEntries();
this.saveData = xml2js(entries[0].getData().toString('utf-8'));

if (this.root.attributes.Version.indexOf('Play-Your-Damn-Turn-Support') < 0) {
if (
this.root.attributes.Version.indexOf('Play-Your-Damn-Turn-Support') < 0 &&
this.root.attributes.Version.indexOf('Play Your Damn Turn Support') < 0
) {
throw new HttpResponseError(
400,
`To play Old World, the "Play Your Damn Turn Support" mod must be enabled!`
Expand Down
Binary file added testdata/saves/oldWorld/Turn1B.zip
Binary file not shown.

0 comments on commit 6a06672

Please sign in to comment.