Skip to content

Commit ca89149

Browse files
committed
1 parent 2c96c9e commit ca89149

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

core/src/com/etheller/warsmash/parsers/w3x/w3i/Player.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public void load(final LittleEndianDataInputStream stream, final int version) th
3030
ParseUtils.readFloatArray(stream, this.startLocation);
3131
this.allyLowPriorities = ParseUtils.readUInt32(stream);
3232
this.allyHighPriorities = ParseUtils.readUInt32(stream);
33-
if (version > 30) {
33+
if (version >= 31) {
3434
this.enemyLowPrioritiesFlags = ParseUtils.readUInt32(stream);
3535
this.enemyHighPrioritiesFlags = ParseUtils.readUInt32(stream);
3636
}
3737
}
3838

39-
public void save(final LittleEndianDataOutputStream stream) throws IOException {
39+
public void save(final LittleEndianDataOutputStream stream, int version) throws IOException {
4040
ParseUtils.writeUInt32(stream, this.id);
4141
stream.writeInt(this.type);
4242
stream.writeInt(this.race);
@@ -45,10 +45,10 @@ public void save(final LittleEndianDataOutputStream stream) throws IOException {
4545
ParseUtils.writeFloatArray(stream, this.startLocation);
4646
ParseUtils.writeUInt32(stream, this.allyLowPriorities);
4747
ParseUtils.writeUInt32(stream, this.allyHighPriorities);
48-
}
49-
50-
public int getByteLength() {
51-
return 33 + this.name.length();
48+
if (version >= 31) {
49+
ParseUtils.writeUInt32(stream, this.enemyLowPrioritiesFlags);
50+
ParseUtils.writeUInt32(stream, this.enemyHighPrioritiesFlags);
51+
}
5252
}
5353

5454
public int getId() {

core/src/com/etheller/warsmash/parsers/w3x/w3i/War3MapW3i.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public void save(final LittleEndianDataOutputStream stream) throws IOException {
326326
ParseUtils.writeUInt32(stream, this.players.size());
327327

328328
for (final Player player : this.players) {
329-
player.save(stream);
329+
player.save(stream, this.version);
330330
}
331331

332332
ParseUtils.writeUInt32(stream, this.forces.size());

core/test/com/etheller/warsmash/parsers/w3x/w3i/War3MapW3iTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.etheller.warsmash.parsers.w3x.w3i.War3MapW3i;
44
import com.google.common.io.LittleEndianDataInputStream;
5+
import com.google.common.io.LittleEndianDataOutputStream;
56
import org.junit.jupiter.api.Test;
67
import static org.junit.jupiter.api.Assertions.*;
78

@@ -21,5 +22,21 @@ void testWoWReforged() throws IOException {
2122
assertEquals("TRIGSTR_004", mapInfo.getAuthor());
2223
assertEquals(12, mapInfo.getPlayers().size());
2324
assertEquals(3, mapInfo.getForces().size());
25+
26+
java.io.File testFile = new java.io.File("target/wowr_w3x/war3map_out.w3i");
27+
testFile.getParentFile().mkdirs();
28+
29+
try (LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(new java.io.FileOutputStream(testFile))) {
30+
mapInfo.save(out);
31+
}
32+
33+
War3MapW3i mapInfo2;
34+
try (LittleEndianDataInputStream in = new LittleEndianDataInputStream(new java.io.FileInputStream(testFile))) {
35+
mapInfo2 = new War3MapW3i(in);
36+
}
37+
38+
assertEquals(mapInfo.getVersion(), mapInfo2.getVersion());
39+
assertEquals(mapInfo.getAuthor(), mapInfo2.getAuthor());
40+
assertEquals(mapInfo.getPlayers().size(), mapInfo2.getPlayers().size());
2441
}
2542
}

0 commit comments

Comments
 (0)