Skip to content

Commit

Permalink
w3i fixes: item tables, better testing, public mutators, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
WaterKnight committed Mar 29, 2020
1 parent 257fcbd commit 7160b2d
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public byte[] readBytes(int size) throws StreamException {

return vals;
} catch (IndexOutOfBoundsException e) {
throw new StreamException(this);
throw new StreamException(this, e.getMessage());
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/moonlightflower/wc3libs/bin/BinStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public BinStream getStream() {
}

@Override
public String toString() {
public String getMessage() {
StringBuilder sb = new StringBuilder();

for (String s : _stream.getLogLines()) {
Expand All @@ -47,6 +47,11 @@ public String toString() {
return sb.toString();
}

@Override
public String toString() {
return getMessage();
}

public StreamException(@Nonnull BinStream stream, @Nonnull String msg) {
this(stream);

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/moonlightflower/wc3libs/bin/app/SHD.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.moonlightflower.wc3libs.bin.Wc3BinInputStream;
import net.moonlightflower.wc3libs.bin.Wc3BinOutputStream;
import net.moonlightflower.wc3libs.dataTypes.app.Bounds;
import net.moonlightflower.wc3libs.dataTypes.app.Coords2DF;
import net.moonlightflower.wc3libs.dataTypes.app.Coords2DI;
import net.moonlightflower.wc3libs.misc.ShadowMap;
import net.moonlightflower.wc3libs.misc.Size;
Expand Down Expand Up @@ -72,7 +73,7 @@ private void read_0x0(@Nonnull Wc3BinInputStream stream) throws BinInputStream.S
//TODO: long?
int sizeI = (int) stream.size();

_shadowMap.setBounds(new Bounds(new Size(1, sizeI), new Coords2DI(0, 0)), false, false);
_shadowMap.setBounds(new Bounds(new Size(1, sizeI)), false, false);

for (int i = 0; i < sizeI; i++) {
Boolean val = ((stream.readByte() & 0xFF) == 0xFF);
Expand Down Expand Up @@ -148,7 +149,7 @@ public SHD clone() throws CloneNotSupportedException {
}

public SHD(@Nonnull BufferedImage img) {
this(new Bounds(new Size(img.getWidth(), img.getHeight()), new Coords2DI(0, 0)));
this(new Bounds(new Size(img.getWidth(), img.getHeight())));

for (int x = 0; x < img.getWidth(); x++) {
for (int y = 0; y < img.getHeight(); y++) {
Expand All @@ -174,7 +175,7 @@ public SHD(@Nonnull Wc3BinInputStream stream) throws IOException {
}

public SHD() {
_shadowMap = new ShadowMap(new Bounds(new Size(0, 0), new Coords2DI(0, 0)));
_shadowMap = new ShadowMap(new Bounds(new Size(0, 0)));
}

@Nonnull
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/moonlightflower/wc3libs/bin/app/W3E.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.moonlightflower.wc3libs.bin.*;
import net.moonlightflower.wc3libs.dataTypes.app.Bounds;
import net.moonlightflower.wc3libs.dataTypes.app.Coords2DF;
import net.moonlightflower.wc3libs.dataTypes.app.Coords2DI;
import net.moonlightflower.wc3libs.misc.*;

Expand Down Expand Up @@ -428,7 +429,7 @@ private void write_0xB(@Nonnull Wc3BinOutputStream stream) throws BinStream.Stre
stream.writeInt32(width);
stream.writeInt32(height);

Coords2DI center = getCenter();
Coords2DF center = getCenter();

stream.writeFloat32(center.getX());
stream.writeFloat32(center.getY());
Expand Down Expand Up @@ -531,7 +532,7 @@ private W3E read_0xB() throws BinInputStream.StreamException {
_w3e.setCliffTile(i, stream.readId("cliffTilesUsed" + i));
}

_w3e.setBounds(new Bounds(new Size(stream.readInt32("width"), stream.readInt32("height")), new Coords2DI(stream.readFloat32("x").intValue(), stream.readFloat32("y").intValue())), false, false);
_w3e.setBounds(new Bounds(new Size(stream.readInt32("width"), stream.readInt32("height")), new Coords2DF(stream.readFloat32("x"), stream.readFloat32("y"))), false, false);

int width = _w3e.getWidth();
int height = _w3e.getHeight();
Expand Down
Loading

1 comment on commit 7160b2d

@WaterKnight
Copy link
Contributor Author

@WaterKnight WaterKnight commented on 7160b2d Mar 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Frotty Should solve SpellBound's problem. Corrected the API a bit. Tell if anything broke.

Please sign in to comment.