Skip to content

Commit ec28754

Browse files
authored
Update to v0.3.0 (#14)
2 parents 39807e6 + 88fd3c2 commit ec28754

21 files changed

+697
-105
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Change Permissions
5454
run: chmod +x ./gradlew
5555
- name: Build with Gradle
56-
run: ./gradlew clean assemble publishToMavenLocal
56+
run: ./gradlew assemble publishToMavenLocal
5757

5858
test:
5959
runs-on: ubuntu-latest
@@ -74,7 +74,43 @@ jobs:
7474
- name: Change Permissions
7575
run: chmod +x ./gradlew
7676
- name: Gradle Test
77-
run: ./gradlew clean test
77+
run: ./gradlew test
78+
- name: Collect JaCoCo Report
79+
if: ${{ github.event_name != 'pull_request' }}
80+
id: jacoco_reporter
81+
uses: PavanMudigonda/jacoco-reporter@v5.0
82+
with:
83+
coverage_results_path: build/jacoco.xml
84+
coverage_report_name: Code Coverage
85+
github_token: ${{ secrets.GITHUB_TOKEN }}
86+
skip_check_run: false
87+
minimum_coverage: 85
88+
fail_below_threshold: false
89+
publish_only_summary: false
90+
- name: Print JaCoCo Report
91+
if: ${{ github.event_name != 'pull_request' }}
92+
run: |
93+
echo "| Outcome | Value |" >> $GITHUB_STEP_SUMMARY
94+
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
95+
echo "| Code Coverage % | ${{ steps.jacoco_reporter.outputs.coverage_percentage }} |" >> $GITHUB_STEP_SUMMARY
96+
echo "| :heavy_check_mark: Number of Lines Covered | ${{ steps.jacoco_reporter.outputs.covered_lines }} |" >> $GITHUB_STEP_SUMMARY
97+
echo "| :x: Number of Lines Missed | ${{ steps.jacoco_reporter.outputs.missed_lines }} |" >> $GITHUB_STEP_SUMMARY
98+
echo "| Total Number of Lines | ${{ steps.jacoco_reporter.outputs.total_lines }} |" >> $GITHUB_STEP_SUMMARY
99+
- name: Upload Code Coverage Artifacts (Push)
100+
if: ${{ github.event_name != 'pull_request' }}
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: coverage-report
104+
path: "*/coverage-results.md"
105+
- name: Upload Code Coverage Artifacts (Pull Request)
106+
if: ${{ github.event_name == 'pull_request' }}
107+
uses: madrapps/jacoco-report@v1.7.0
108+
with:
109+
paths: build/jacoco.xml
110+
token: ${{ secrets.GITHUB_TOKEN }}
111+
pass-emoji:
112+
min-coverage-overall: 85
113+
min-coverage-changed-files: 90
78114

79115
deploy:
80116
runs-on: ubuntu-latest
@@ -94,7 +130,7 @@ jobs:
94130
- name: Change Permissions
95131
run: chmod +x ./gradlew
96132
- name: Build JavaDocs
97-
run: ./gradlew clean javadoc
133+
run: ./gradlew javadoc
98134
- name: Deploy JavaDoc
99135
run: bash javadoc.sh ${GITHUB_SHA::7}
100136

@@ -119,4 +155,4 @@ jobs:
119155
env:
120156
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
121157
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
122-
run: ./gradlew clean build publish -x test
158+
run: ./gradlew publish -Psnapshot=true

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release Project
2+
on:
3+
release:
4+
types: [published]
5+
workflow_dispatch:
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
name: Publish to Repository
11+
timeout-minutes: 30
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
submodules: 'recursive'
17+
- name: Set up JDK 111
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: 'temurin'
21+
java-version: '11'
22+
cache: 'gradle'
23+
- name: Change Permissions
24+
run: chmod +x ./gradlew
25+
- name: Publish to Repository
26+
env:
27+
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
28+
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
29+
run: ./gradlew publish

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
build
44
.DS_Store
55
bin/
6-
.vscode/
6+
.vscode/
7+
.kotlin/

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ plugins {
99
signing
1010
}
1111

12+
val v = "0.3.0"
1213
val jvm = JavaVersion.VERSION_11
1314

1415
group = "xyz.calcugames"
15-
version = "0.2.2-SNAPSHOT"
16+
version = if (project.hasProperty("snapshot")) "$v-SNAPSHOT" else v
1617

1718
java {
1819
sourceCompatibility = jvm

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.

src/main/java/xyz/calcugames/levelz/Block.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package xyz.calcugames.levelz;
22

33
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
45
import org.jetbrains.annotations.Unmodifiable;
6+
import xyz.calcugames.levelz.parser.Errors;
7+
import xyz.calcugames.levelz.parser.LevelParser;
8+
import xyz.calcugames.levelz.parser.ParseException;
59

10+
import java.util.HashMap;
611
import java.util.Map;
712
import java.util.Objects;
813

@@ -89,4 +94,31 @@ public String toString() {
8994
if (properties.isEmpty()) return name;
9095
return name + "<" + properties.toString().replaceAll("[{}]", "") + ">";
9196
}
97+
98+
/**
99+
* Converts a string into a Block.
100+
* @param string The string to convert.
101+
* @return The Block, or null if the string is empty.
102+
*/
103+
@Nullable
104+
public static Block fromString(@NotNull String string) {
105+
if (string.isEmpty()) return null;
106+
107+
String[] split = string.replaceAll("[\\s>]", "").split("<");
108+
String name = split[0].trim();
109+
110+
if (split.length < 2) return new Block(name, Map.of());
111+
112+
Map<String, Object> properties = new HashMap<>();
113+
String[] props = split[1].split(",");
114+
115+
for (String entry : props) {
116+
String[] kv = entry.split("=");
117+
if (kv.length < 2) throw new ParseException(String.format(Errors.INVALID_BLOCK, string));
118+
119+
properties.put(kv[0], LevelParser.value(kv[1]));
120+
}
121+
122+
return new Block(name, properties);
123+
}
92124
}

src/main/java/xyz/calcugames/levelz/LevelExporter.java

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import java.io.File;
66
import java.io.IOException;
7+
import java.io.OutputStream;
8+
import java.nio.charset.Charset;
79
import java.nio.file.Files;
810
import java.nio.file.Path;
911
import java.util.Map;
@@ -77,7 +79,7 @@ public String writeToString() {
7779

7880
for (LevelObject block : blocks)
7981
if (blockMap.containsKey(block.getBlock()))
80-
blockMap.put(block.getBlock(), blockMap.get(block.getBlock()) + "*" + block.getCoordinate().toString());
82+
blockMap.put(block.getBlock(), blockMap.get(block.getBlock()) + "*" + block.getCoordinate());
8183
else
8284
blockMap.put(block.getBlock(), block.getCoordinate().toString());
8385

@@ -89,12 +91,50 @@ public String writeToString() {
8991
return builder.toString();
9092
}
9193

94+
/**
95+
* <p>Writes to a byte array using the default charset.</p>
96+
* <p>The exporter will only write to the byte buffer if there is enough space, stopping if the length if too small.</p>
97+
* @param data Byte Array to encode into
98+
* @throws IllegalArgumentException if the data is null
99+
*/
100+
public void writeToByteArray(byte[] data) throws IllegalArgumentException {
101+
writeToByteArray(data, Charset.defaultCharset());
102+
}
103+
104+
/**
105+
* <p>Writes to a byte array.</p>
106+
* <p>The exporter will only write to the byte buffer if there is enough space, stopping if the length if too small.</p>
107+
* @param data Byte Array to encode into
108+
* @param charset Charset to encode bytes with
109+
* @throws IllegalArgumentException if the data or charset is null
110+
*/
111+
public void writeToByteArray(byte[] data, @NotNull Charset charset) throws IllegalArgumentException {
112+
if (data == null) throw new IllegalArgumentException("Data cannot be null");
113+
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");
114+
115+
String string = writeToString();
116+
byte[] bytes = string.getBytes(charset);
117+
System.arraycopy(bytes, 0, data, 0, Math.min(bytes.length, data.length));
118+
}
119+
120+
/**
121+
* Writes to a file using the default charset. This will create the file if it does not exist.
122+
* @param file File
123+
* @throws IllegalArgumentException if the file is null
124+
*/
125+
public void writeToFile(@NotNull File file) throws IllegalArgumentException {
126+
writeToFile(file, Charset.defaultCharset());
127+
}
128+
92129
/**
93130
* Writes to a file. This will create the file if it does not exist.
94131
* @param file File
132+
* @param charset Charset to encode bytes with
133+
* @throws IllegalArgumentException if the file or charset is null
95134
*/
96-
public void writeToFile(@NotNull File file) {
135+
public void writeToFile(@NotNull File file, @NotNull Charset charset) throws IllegalArgumentException {
97136
if (file == null) throw new IllegalArgumentException("File cannot be null");
137+
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");
98138

99139
if (!file.exists())
100140
try {
@@ -103,19 +143,58 @@ public void writeToFile(@NotNull File file) {
103143
throw new RuntimeException(e);
104144
}
105145

106-
writeToPath(file.toPath());
146+
writeToPath(file.toPath(), charset);
147+
}
148+
149+
/**
150+
* Writes to a file path using the default charset.
151+
* @param file File Path
152+
* @throws IllegalArgumentException if the path is null
153+
*/
154+
public void writeToPath(@NotNull Path file) throws IllegalArgumentException {
155+
writeToPath(file, Charset.defaultCharset());
107156
}
108157

109158
/**
110159
* Writes to a file path.
111160
* @param file File Path
161+
* @param charset Charset to encode bytes with
162+
* @throws IllegalArgumentException if the path or charset is null
112163
*/
113-
public void writeToPath(@NotNull Path file) {
164+
public void writeToPath(@NotNull Path file, @NotNull Charset charset) throws IllegalArgumentException {
114165
if (file == null) throw new IllegalArgumentException("Path cannot be null");
166+
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");
167+
168+
String data = writeToString();
169+
try {
170+
Files.write(file, data.getBytes(charset));
171+
} catch (IOException e) {
172+
throw new RuntimeException(e);
173+
}
174+
}
175+
176+
/**
177+
* Writes this level to an output stream using the default charset.
178+
* @param stream Output Stream
179+
* @throws IllegalArgumentException if the stream is null
180+
*/
181+
public void writeToStream(@NotNull OutputStream stream) throws IllegalArgumentException {
182+
writeToStream(stream, Charset.defaultCharset());
183+
}
184+
185+
/**
186+
* Writes this level to an output stream.
187+
* @param stream Output Stream
188+
* @param charset Charset to encode bytes with
189+
* @throws IllegalArgumentException if the stream or charset is null
190+
*/
191+
public void writeToStream(@NotNull OutputStream stream, @NotNull Charset charset) throws IllegalArgumentException {
192+
if (stream == null) throw new IllegalArgumentException("Stream cannot be null");
193+
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");
115194

116195
String data = writeToString();
117196
try {
118-
Files.write(file, data.getBytes());
197+
stream.write(data.getBytes(charset));
119198
} catch (IOException e) {
120199
throw new RuntimeException(e);
121200
}

src/main/java/xyz/calcugames/levelz/coord/Coordinate.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public interface Coordinate extends Comparable<Coordinate> {
1414
*/
1515
double getMagnitude();
1616

17+
/**
18+
* Gets the distance between two Coordinates.
19+
* @param other Other Coordinate
20+
* @return Distance between Coordinates
21+
* @throws IllegalArgumentException if the Coordinates are not the same dimension
22+
*/
23+
double getDistance(@NotNull Coordinate other) throws IllegalArgumentException;
24+
1725
/**
1826
* Gets the dimension of the Coordinate.
1927
* @return Coordinate Dimension
@@ -31,9 +39,36 @@ public interface Coordinate extends Comparable<Coordinate> {
3139
* @param coords Coordinate Array
3240
* @return A {@linkplain Coordinate2D 2D} or {@linkplain Coordinate3D 3D} Coordinate, depending on array size
3341
*/
42+
@NotNull
3443
static Coordinate fromArray(int[] coords) {
35-
if (coords.length == 2) return new Coordinate2D(coords[0], coords[1]);
36-
if (coords.length == 3) return new Coordinate3D(coords[0], coords[1], coords[2]);
44+
if (coords.length == 2) return new Coordinate2D(coords);
45+
if (coords.length == 3) return new Coordinate3D(coords);
46+
47+
throw new IllegalArgumentException("Invalid Coordinate Length");
48+
}
49+
50+
/**
51+
* Creates a Coordinate from an array of floats.
52+
* @param coords Coordinate Array
53+
* @return A {@linkplain Coordinate2D 2D} or {@linkplain Coordinate3D 3D} Coordinate, depending on array size
54+
*/
55+
@NotNull
56+
static Coordinate fromArray(float[] coords) {
57+
if (coords.length == 2) return new Coordinate2D(coords);
58+
if (coords.length == 3) return new Coordinate3D(coords);
59+
60+
throw new IllegalArgumentException("Invalid Coordinate Length");
61+
}
62+
63+
/**
64+
* Creates a Coordinate from an array of doubles.
65+
* @param coords Coordinate Array
66+
* @return A {@linkplain Coordinate2D 2D} or {@linkplain Coordinate3D 3D} Coordinate, depending on array size
67+
*/
68+
@NotNull
69+
static Coordinate fromArray(double[] coords) {
70+
if (coords.length == 2) return new Coordinate2D(coords);
71+
if (coords.length == 3) return new Coordinate3D(coords);
3772

3873
throw new IllegalArgumentException("Invalid Coordinate Length");
3974
}

0 commit comments

Comments
 (0)