aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/utils')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java
index f3bf6065..8fb90ec1 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java
@@ -132,4 +132,46 @@ public class MapUtils {
return -1;
}
+
+ public static boolean matches(byte[] colors, byte[] stencil, int targetColor, int x, int y) {
+ for (int i = y; i < y + stencil.length; i++) {
+ for (int j = x; j < x + 8; j++) {
+ boolean current = getMapColorAt(colors, j, i) == targetColor;
+ boolean expected = ((stencil[i - y] >> (7-(j-x))) & 0x1) == 1;
+ if (current != expected) return false;
+ }
+ }
+ return true;
+ }
+
+ public static int readDigit(byte[] colors, int x, int y) {
+ for (int i = 0; i < NUMBER_STENCIL.length; i++) {
+ if (matches(colors, NUMBER_STENCIL[i],34, x, y)) return i;
+ }
+ return -1;
+ }
+ public static int readNumber(byte[] colors, int x, int y, int gap) {
+ int number = 0;
+ for (int i = x; i < 128; i += gap) {
+ int digit = readDigit(colors, i, y);
+ if (digit != -1) number = number * 10 + digit;
+ }
+ return number;
+ }
+
+ private static final byte[][] NUMBER_STENCIL = {
+ {0x0, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x0},
+ {0x0, 0x1E, 0x1E, 0x1E, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0x0},
+ {0x0, 0x7F, 0x7F, 0x7F, 0x77, 0x77, 0x7, 0x7F, 0x7F, 0x70, 0x7F, 0x7F, 0x7F, 0x0},
+ {0x0, 0x7F, 0x7F, 0x7F, 0x7, 0x7, 0x1F, 0x1F, 0x7, 0x7, 0x7F, 0x7F, 0x7F, 0x0},
+ {0x0, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x7F, 0x7F, 0x7F, 0xE, 0xE, 0xE, 0x0},
+ {0x0, 0x7F, 0x7F, 0x7F, 0x70, 0x7F, 0x7F, 0x7, 0x77, 0x77, 0x7F, 0x7F, 0x7F, 0x0},
+ {0x0, 0x7F, 0x7F, 0x7F, 0x70, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x0},
+ {0x0, 0x7F, 0x7F, 0x7F, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x0},
+ {0x0, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x3E, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x0},
+ {0x0, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x7, 0x7F, 0x7F, 0x7F, 0x0}
+ };
+
+
+
}