Skip to content
This repository was archived by the owner on Jan 8, 2023. It is now read-only.

Commit 49d806a

Browse files
committed
Fixes incorrect valueOf conversion
1 parent 61f16a9 commit 49d806a

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/main/java/io/github/spair/byond/dmi/Diff.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Objects;
1010

1111
@Data
12+
@Setter(AccessLevel.PACKAGE)
1213
@SuppressWarnings("WeakerAccess")
1314
public class Diff {
1415

@@ -19,9 +20,7 @@ public class Diff {
1920
@Setter(AccessLevel.NONE)
2021
@Nonnull private DiffStatus status;
2122

22-
public Diff(@Nonnull final String stateName,
23-
@Nullable final DmiSprite oldSprite,
24-
@Nullable final DmiSprite newSprite) {
23+
Diff(@Nonnull final String stateName, @Nullable final DmiSprite oldSprite, @Nullable final DmiSprite newSprite) {
2524
this.stateName = stateName;
2625
this.oldSprite = oldSprite;
2726
this.newSprite = newSprite;

src/main/java/io/github/spair/byond/dmi/DmiDiff.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
package io.github.spair.byond.dmi;
22

3+
import lombok.AccessLevel;
34
import lombok.Data;
5+
import lombok.Setter;
46

57
import javax.annotation.Nonnull;
68
import javax.annotation.Nullable;
79
import java.util.List;
810
import java.util.Objects;
911

1012
@Data
13+
@Setter(AccessLevel.PACKAGE)
1114
@SuppressWarnings("WeakerAccess")
1215
public class DmiDiff {
1316

1417
@Nullable private DmiMeta oldMeta;
1518
@Nullable private DmiMeta newMeta;
1619
@Nonnull private List<Diff> diffs;
1720

21+
DmiDiff(@Nonnull final List<Diff> diffs) {
22+
this.diffs = diffs;
23+
}
24+
1825
/**
1926
* Shows that current diff was generated from the same Dmi's.
2027
* @return true, if Dmi's was the same, otherwise false

src/main/java/io/github/spair/byond/dmi/DmiMeta.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.github.spair.byond.dmi;
22

3-
import lombok.AllArgsConstructor;
43
import lombok.Data;
54
import lombok.NoArgsConstructor;
5+
import lombok.AllArgsConstructor;
66

77
import java.util.List;
88

src/main/java/io/github/spair/byond/dmi/SpriteDir.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ public enum SpriteDir {
1212
NORTHEAST(5, "NE", 7),
1313
NORTHWEST(9, "NW", 8);
1414

15-
private static final int NORTH_DIR = 1;
16-
private static final int SOUTH_DIR = 2;
17-
private static final int EAST_DIR = 4;
18-
private static final int WEST_DIR = 8;
19-
20-
private static final int SOUTHEAST_DIR = 6;
21-
private static final int SOUTHWEST_DIR = 10;
22-
private static final int NORTHEAST_DIR = 5;
23-
private static final int NORTHWEST_DIR = 9;
24-
2515
/**
2616
* <p>BYOND representation of dir as int value.
2717
* <ul>
@@ -65,7 +55,7 @@ public enum SpriteDir {
6555
* Returns {@link SpriteDir} equivalent to BYOND dir value. If method got value different from the list below,
6656
* {@link IllegalArgumentException} will be thrown.
6757
* <ul>
68-
* <li>1 - NORTH</li>
58+
* <li>0,1,3,7 - NORTH</li>
6959
* <li>2 - SOUTH</li>
7060
* <li>4 - EAST</li>
7161
* <li>8 - WEST</li>
@@ -78,23 +68,24 @@ public enum SpriteDir {
7868
* @param dirValue BYOND representation of dir
7969
* @return {@link SpriteDir} equivalent of BYOND dir value
8070
*/
71+
@SuppressWarnings("checkstyle:MagicNumber")
8172
public static SpriteDir valueOfByondDir(final int dirValue) {
8273
switch (dirValue) {
83-
case NORTH_DIR:
74+
case 0: case 1: case 3: case 7:
8475
return NORTH;
85-
case SOUTH_DIR:
76+
case 2:
8677
return SOUTH;
87-
case EAST_DIR:
78+
case 4:
8879
return EAST;
89-
case WEST_DIR:
80+
case 8:
9081
return WEST;
91-
case NORTHEAST_DIR:
82+
case 5:
9283
return NORTHEAST;
93-
case SOUTHEAST_DIR:
84+
case 6:
9485
return SOUTHEAST;
95-
case NORTHWEST_DIR:
86+
case 9:
9687
return NORTHWEST;
97-
case SOUTHWEST_DIR:
88+
case 10:
9889
return SOUTHWEST;
9990
default:
10091
throw new IllegalArgumentException("Illegal value of BYOND dir. Dir value: " + dirValue);

src/test/java/io/github/spair/byond/dmi/SpriteDirTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ public class SpriteDirTest {
88

99
@Test
1010
public void testValueOfByondDir() {
11+
assertEquals(SpriteDir.NORTH, SpriteDir.valueOfByondDir(0));
1112
assertEquals(SpriteDir.NORTH, SpriteDir.valueOfByondDir(1));
13+
assertEquals(SpriteDir.NORTH, SpriteDir.valueOfByondDir(3));
14+
assertEquals(SpriteDir.NORTH, SpriteDir.valueOfByondDir(7));
1215
assertEquals(SpriteDir.SOUTH, SpriteDir.valueOfByondDir(2));
1316
assertEquals(SpriteDir.EAST, SpriteDir.valueOfByondDir(4));
1417
assertEquals(SpriteDir.WEST, SpriteDir.valueOfByondDir(8));
@@ -22,7 +25,7 @@ public void testValueOfByondDir() {
2225
@Test(expected = IllegalArgumentException.class)
2326
public void testValueOfByondDirWithIllegalValue() {
2427
//noinspection ResultOfMethodCallIgnored
25-
SpriteDir.valueOfByondDir(0);
28+
SpriteDir.valueOfByondDir(-1);
2629
}
2730

2831
@Test

0 commit comments

Comments
 (0)