Skip to content
Merged
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
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.