Skip to content

Update to v0.3.0 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Change Permissions
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean assemble publishToMavenLocal
run: ./gradlew assemble publishToMavenLocal

test:
runs-on: ubuntu-latest
Expand All @@ -74,7 +74,43 @@ jobs:
- name: Change Permissions
run: chmod +x ./gradlew
- name: Gradle Test
run: ./gradlew clean test
run: ./gradlew test
- name: Collect JaCoCo Report
if: ${{ github.event_name != 'pull_request' }}
id: jacoco_reporter
uses: PavanMudigonda/jacoco-reporter@v5.0
with:
coverage_results_path: build/jacoco.xml
coverage_report_name: Code Coverage
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_check_run: false
minimum_coverage: 85
fail_below_threshold: false
publish_only_summary: false
- name: Print JaCoCo Report
if: ${{ github.event_name != 'pull_request' }}
run: |
echo "| Outcome | Value |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
echo "| Code Coverage % | ${{ steps.jacoco_reporter.outputs.coverage_percentage }} |" >> $GITHUB_STEP_SUMMARY
echo "| :heavy_check_mark: Number of Lines Covered | ${{ steps.jacoco_reporter.outputs.covered_lines }} |" >> $GITHUB_STEP_SUMMARY
echo "| :x: Number of Lines Missed | ${{ steps.jacoco_reporter.outputs.missed_lines }} |" >> $GITHUB_STEP_SUMMARY
echo "| Total Number of Lines | ${{ steps.jacoco_reporter.outputs.total_lines }} |" >> $GITHUB_STEP_SUMMARY
- name: Upload Code Coverage Artifacts (Push)
if: ${{ github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: "*/coverage-results.md"
- name: Upload Code Coverage Artifacts (Pull Request)
if: ${{ github.event_name == 'pull_request' }}
uses: madrapps/jacoco-report@v1.7.0
with:
paths: build/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
pass-emoji: ✅
min-coverage-overall: 85
min-coverage-changed-files: 90

deploy:
runs-on: ubuntu-latest
Expand All @@ -94,7 +130,7 @@ jobs:
- name: Change Permissions
run: chmod +x ./gradlew
- name: Build JavaDocs
run: ./gradlew clean javadoc
run: ./gradlew javadoc
- name: Deploy JavaDoc
run: bash javadoc.sh ${GITHUB_SHA::7}

Expand All @@ -119,4 +155,4 @@ jobs:
env:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: ./gradlew clean build publish -x test
run: ./gradlew publish -Psnapshot=true
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release Project
on:
release:
types: [published]
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
name: Publish to Repository
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up JDK 111
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'
- name: Change Permissions
run: chmod +x ./gradlew
- name: Publish to Repository
env:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: ./gradlew publish
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
build
.DS_Store
bin/
.vscode/
.vscode/
.kotlin/
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ plugins {
signing
}

val v = "0.3.0"
val jvm = JavaVersion.VERSION_11

group = "xyz.calcugames"
version = "0.2.2-SNAPSHOT"
version = if (project.hasProperty("snapshot")) "$v-SNAPSHOT" else v

java {
sourceCompatibility = jvm
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/xyz/calcugames/levelz/Block.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package xyz.calcugames.levelz;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import xyz.calcugames.levelz.parser.Errors;
import xyz.calcugames.levelz.parser.LevelParser;
import xyz.calcugames.levelz.parser.ParseException;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -89,4 +94,31 @@ public String toString() {
if (properties.isEmpty()) return name;
return name + "<" + properties.toString().replaceAll("[{}]", "") + ">";
}

/**
* Converts a string into a Block.
* @param string The string to convert.
* @return The Block, or null if the string is empty.
*/
@Nullable
public static Block fromString(@NotNull String string) {
if (string.isEmpty()) return null;

String[] split = string.replaceAll("[\\s>]", "").split("<");
String name = split[0].trim();

if (split.length < 2) return new Block(name, Map.of());

Map<String, Object> properties = new HashMap<>();
String[] props = split[1].split(",");

for (String entry : props) {
String[] kv = entry.split("=");
if (kv.length < 2) throw new ParseException(String.format(Errors.INVALID_BLOCK, string));

properties.put(kv[0], LevelParser.value(kv[1]));
}

return new Block(name, properties);
}
}
89 changes: 84 additions & 5 deletions src/main/java/xyz/calcugames/levelz/LevelExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
Expand Down Expand Up @@ -77,7 +79,7 @@ public String writeToString() {

for (LevelObject block : blocks)
if (blockMap.containsKey(block.getBlock()))
blockMap.put(block.getBlock(), blockMap.get(block.getBlock()) + "*" + block.getCoordinate().toString());
blockMap.put(block.getBlock(), blockMap.get(block.getBlock()) + "*" + block.getCoordinate());
else
blockMap.put(block.getBlock(), block.getCoordinate().toString());

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

/**
* <p>Writes to a byte array using the default charset.</p>
* <p>The exporter will only write to the byte buffer if there is enough space, stopping if the length if too small.</p>
* @param data Byte Array to encode into
* @throws IllegalArgumentException if the data is null
*/
public void writeToByteArray(byte[] data) throws IllegalArgumentException {
writeToByteArray(data, Charset.defaultCharset());
}

/**
* <p>Writes to a byte array.</p>
* <p>The exporter will only write to the byte buffer if there is enough space, stopping if the length if too small.</p>
* @param data Byte Array to encode into
* @param charset Charset to encode bytes with
* @throws IllegalArgumentException if the data or charset is null
*/
public void writeToByteArray(byte[] data, @NotNull Charset charset) throws IllegalArgumentException {
if (data == null) throw new IllegalArgumentException("Data cannot be null");
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");

String string = writeToString();
byte[] bytes = string.getBytes(charset);
System.arraycopy(bytes, 0, data, 0, Math.min(bytes.length, data.length));
}

/**
* Writes to a file using the default charset. This will create the file if it does not exist.
* @param file File
* @throws IllegalArgumentException if the file is null
*/
public void writeToFile(@NotNull File file) throws IllegalArgumentException {
writeToFile(file, Charset.defaultCharset());
}

/**
* Writes to a file. This will create the file if it does not exist.
* @param file File
* @param charset Charset to encode bytes with
* @throws IllegalArgumentException if the file or charset is null
*/
public void writeToFile(@NotNull File file) {
public void writeToFile(@NotNull File file, @NotNull Charset charset) throws IllegalArgumentException {
if (file == null) throw new IllegalArgumentException("File cannot be null");
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");

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

writeToPath(file.toPath());
writeToPath(file.toPath(), charset);
}

/**
* Writes to a file path using the default charset.
* @param file File Path
* @throws IllegalArgumentException if the path is null
*/
public void writeToPath(@NotNull Path file) throws IllegalArgumentException {
writeToPath(file, Charset.defaultCharset());
}

/**
* Writes to a file path.
* @param file File Path
* @param charset Charset to encode bytes with
* @throws IllegalArgumentException if the path or charset is null
*/
public void writeToPath(@NotNull Path file) {
public void writeToPath(@NotNull Path file, @NotNull Charset charset) throws IllegalArgumentException {
if (file == null) throw new IllegalArgumentException("Path cannot be null");
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");

String data = writeToString();
try {
Files.write(file, data.getBytes(charset));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
* Writes this level to an output stream using the default charset.
* @param stream Output Stream
* @throws IllegalArgumentException if the stream is null
*/
public void writeToStream(@NotNull OutputStream stream) throws IllegalArgumentException {
writeToStream(stream, Charset.defaultCharset());
}

/**
* Writes this level to an output stream.
* @param stream Output Stream
* @param charset Charset to encode bytes with
* @throws IllegalArgumentException if the stream or charset is null
*/
public void writeToStream(@NotNull OutputStream stream, @NotNull Charset charset) throws IllegalArgumentException {
if (stream == null) throw new IllegalArgumentException("Stream cannot be null");
if (charset == null) throw new IllegalArgumentException("Charset cannot be null");

String data = writeToString();
try {
Files.write(file, data.getBytes());
stream.write(data.getBytes(charset));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
39 changes: 37 additions & 2 deletions src/main/java/xyz/calcugames/levelz/coord/Coordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public interface Coordinate extends Comparable<Coordinate> {
*/
double getMagnitude();

/**
* Gets the distance between two Coordinates.
* @param other Other Coordinate
* @return Distance between Coordinates
* @throws IllegalArgumentException if the Coordinates are not the same dimension
*/
double getDistance(@NotNull Coordinate other) throws IllegalArgumentException;

/**
* Gets the dimension of the Coordinate.
* @return Coordinate Dimension
Expand All @@ -31,9 +39,36 @@ public interface Coordinate extends Comparable<Coordinate> {
* @param coords Coordinate Array
* @return A {@linkplain Coordinate2D 2D} or {@linkplain Coordinate3D 3D} Coordinate, depending on array size
*/
@NotNull
static Coordinate fromArray(int[] coords) {
if (coords.length == 2) return new Coordinate2D(coords[0], coords[1]);
if (coords.length == 3) return new Coordinate3D(coords[0], coords[1], coords[2]);
if (coords.length == 2) return new Coordinate2D(coords);
if (coords.length == 3) return new Coordinate3D(coords);

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

/**
* Creates a Coordinate from an array of floats.
* @param coords Coordinate Array
* @return A {@linkplain Coordinate2D 2D} or {@linkplain Coordinate3D 3D} Coordinate, depending on array size
*/
@NotNull
static Coordinate fromArray(float[] coords) {
if (coords.length == 2) return new Coordinate2D(coords);
if (coords.length == 3) return new Coordinate3D(coords);

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

/**
* Creates a Coordinate from an array of doubles.
* @param coords Coordinate Array
* @return A {@linkplain Coordinate2D 2D} or {@linkplain Coordinate3D 3D} Coordinate, depending on array size
*/
@NotNull
static Coordinate fromArray(double[] coords) {
if (coords.length == 2) return new Coordinate2D(coords);
if (coords.length == 3) return new Coordinate3D(coords);

throw new IllegalArgumentException("Invalid Coordinate Length");
}
Expand Down
Loading
Loading