Skip to content

Commit 24aa1ab

Browse files
authored
Update to v0.1.2 (#4)
2 parents 8166190 + edcf5e9 commit 24aa1ab

File tree

17 files changed

+91
-27
lines changed

17 files changed

+91
-27
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.idea
22
.gradle/
33
build
4-
.DS_Store
4+
.DS_Store
5+
bin/
6+
.vscode/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
> Java & Kotlin Parser & API For LevelZ File Format
44
5-
[![](https://jitpack.io/v/LevelZ-File/java-bindings.svg)](https://jitpack.io/#LevelZ-File/java-bindings)
6-
[![JitCi](https://jitci.com/gh/LevelZ-File/java-bindings/svg)](https://jitci.com/gh/LevelZ-File/java-bindings)
5+
[![JitPack](https://jitpack.io/v/LevelZ-File/java-bindings.svg)](https://jitpack.io/#LevelZ-File/java-bindings)
6+
![GitHub Release](https://img.shields.io/github/v/release/LevelZ-File/java-bindings)
77

88
## Overview
99

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
val jvm = JavaVersion.VERSION_11
1111

1212
group = "me.gamercoder215.calcgames"
13-
version = "0.1.1"
13+
version = "0.1.2"
1414

1515
java {
1616
sourceCompatibility = jvm

javadoc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if [ ! -d "docs" ]; then
77
fi;
88

99
cp -Rfv build/docs/javadoc/* ./docs/
10+
cp -Rfv src/main/javadoc/favicon.ico ./docs/
1011

1112
git switch -f gh-pages
1213

src/main/java/me/gamercoder215/calcgames/levelz/Level2D.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import java.util.*;
99
import java.util.stream.Collectors;
10-
import java.util.stream.Stream;
1110

1211
/**
1312
* Represents a 2D level.

src/main/java/me/gamercoder215/calcgames/levelz/LevelExporter.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import java.nio.file.Files;
88
import java.nio.file.Path;
99
import java.util.Map;
10+
import java.util.stream.Collectors;
11+
import java.util.HashMap;
12+
import java.util.List;
1013

1114
/**
1215
* Represents a class that exports a LevelZ Level to a file.
@@ -67,8 +70,19 @@ public String writeToString() {
6770
}
6871

6972
if (includeData) {
70-
for (LevelObject block : level.getBlocks())
71-
builder.append(block.toString()).append(lineSeparator);
73+
Map<Block, String> blockMap = new HashMap<>();
74+
List<LevelObject> blocks = level.getBlocks().stream()
75+
.sorted()
76+
.collect(Collectors.toList());
77+
78+
for (LevelObject block : blocks)
79+
if (blockMap.containsKey(block.getBlock()))
80+
blockMap.put(block.getBlock(), blockMap.get(block.getBlock()) + "*" + block.getCoordinate().toString());
81+
else
82+
blockMap.put(block.getBlock(), block.getCoordinate().toString());
83+
84+
for (Map.Entry<Block, String> entry : blockMap.entrySet())
85+
builder.append(entry.getKey()).append(": ").append(entry.getValue()).append(lineSeparator);
7286
}
7387

7488
builder.append("end");

src/main/java/me/gamercoder215/calcgames/levelz/LevelObject.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Utility Object for representing a Level Block and its Coordinate.
1010
*/
11-
public final class LevelObject {
11+
public final class LevelObject implements Comparable<LevelObject> {
1212

1313
private final Block block;
1414
private final Coordinate coordinate;
@@ -58,4 +58,9 @@ public int hashCode() {
5858
public String toString() {
5959
return block + ": " + coordinate;
6060
}
61+
62+
@Override
63+
public int compareTo(LevelObject o) {
64+
return coordinate.compareTo(o.coordinate);
65+
}
6166
}

src/main/java/me/gamercoder215/calcgames/levelz/builder/LevelBuilder.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.gamercoder215.calcgames.levelz.coord.Coordinate2D;
66
import me.gamercoder215.calcgames.levelz.coord.Coordinate3D;
77
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
89
import org.jetbrains.annotations.Unmodifiable;
910

1011
import java.util.HashMap;
@@ -71,15 +72,40 @@ public LevelBuilder spawn(int[] coords) {
7172
return spawn(Coordinate.fromArray(coords));
7273
}
7374

75+
/**
76+
* Sets the scroll direction for the level.
77+
* @param scroll Scroll Direction
78+
* @return this class, for chaining
79+
* @throws IllegalArgumentException If the level is not 2D
80+
*/
81+
@NotNull
82+
public LevelBuilder scroll(@Nullable Scroll scroll) throws IllegalArgumentException {
83+
if (!dimension.is2D())
84+
throw new IllegalArgumentException("Scroll is only supported for 2D levels");
85+
86+
if (scroll == null)
87+
headers.remove("scroll");
88+
else
89+
headers.put("scroll", scroll.name().toLowerCase());
90+
91+
return this;
92+
}
93+
7494
/**
7595
* Sets a header value.
7696
* @param key Header Key
77-
* @param value Header Value
97+
* @param value Header Value, can be null
7898
* @return this class, for chaining
99+
* @throws IllegalArgumentException If the key is null
79100
*/
80101
@NotNull
81-
public LevelBuilder header(@NotNull String key, @NotNull String value) {
82-
headers.put(key, value);
102+
public LevelBuilder header(@NotNull String key, @Nullable String value) throws IllegalArgumentException {
103+
if (key == null) throw new IllegalArgumentException("Key cannot be null");
104+
105+
if (value == null)
106+
headers.remove(key);
107+
else
108+
headers.put(key, value);
83109
return this;
84110
}
85111

src/main/java/me/gamercoder215/calcgames/levelz/coord/Coordinate.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Represents a Game Coordinate.
88
*/
9-
public interface Coordinate {
9+
public interface Coordinate extends Comparable<Coordinate> {
1010

1111
/**
1212
* Gets the magnitude of the Coordinate.
@@ -38,4 +38,8 @@ static Coordinate fromArray(int[] coords) {
3838
throw new IllegalArgumentException("Invalid Coordinate Length");
3939
}
4040

41+
default int compareTo(@NotNull Coordinate o) {
42+
return Double.compare(getMagnitude(), o.getMagnitude());
43+
}
44+
4145
}

src/main/java/me/gamercoder215/calcgames/levelz/coord/Coordinate2D.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ public int hashCode() {
124124

125125
@Override
126126
public String toString() {
127-
return "[" + x + ", " + y + "]";
127+
int xInt = (int) x, yInt = (int) y;
128+
String xs = x == xInt ? String.valueOf(xInt) : String.valueOf(x);
129+
String ys = y == yInt ? String.valueOf(yInt) : String.valueOf(y);
130+
131+
return "[" + xs + ", " + ys + "]";
128132
}
129133

130134
/**

0 commit comments

Comments
 (0)