-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,061 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# Linux start script should use lf | ||
/gradlew text eol=lf | ||
|
||
# These are Windows script files and should use crlf | ||
*.bat text eol=crlf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Automatically build the project and run any configured tests for every push | ||
# and submitted pull request. This can help catch issues that only occur on | ||
# certain platforms or Java versions, and provides a first line of defence | ||
# against bad commits. | ||
|
||
name: build | ||
on: [pull_request, push] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
# Use these Java versions | ||
java: [ | ||
21, # Current Java LTS | ||
] | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: checkout repository | ||
uses: actions/checkout@v4 | ||
- name: validate gradle wrapper | ||
uses: gradle/wrapper-validation-action@v2 | ||
- name: setup jdk ${{ matrix.java }} | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: ${{ matrix.java }} | ||
distribution: 'microsoft' | ||
- name: make gradle wrapper executable | ||
run: chmod +x ./gradlew | ||
- name: build | ||
run: ./gradlew build | ||
- name: capture build artifacts | ||
if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Artifacts | ||
path: build/libs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,40 @@ | ||
.gradle | ||
.idea | ||
build | ||
debug | ||
# gradle | ||
|
||
.gradle/ | ||
build/ | ||
out/ | ||
classes/ | ||
|
||
# eclipse | ||
|
||
*.launch | ||
|
||
# idea | ||
|
||
.idea/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
# vscode | ||
|
||
.settings/ | ||
.vscode/ | ||
bin/ | ||
.classpath | ||
.project | ||
|
||
# macos | ||
|
||
*.DS_Store | ||
|
||
# fabric | ||
|
||
run/ | ||
|
||
# java | ||
|
||
hs_err_*.log | ||
replay_*.log | ||
*.hprof | ||
*.jfr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 RedPolygon | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id "org.jetbrains.kotlin.jvm" version "2.0.0" apply false | ||
id "org.jetbrains.kotlin.plugin.serialization" version "2.0.0" apply false | ||
id "kr.entree.spigradle" version "2.4.3" apply false | ||
id "fabric-loom" version "1.7-SNAPSHOT" apply false | ||
id "com.github.johnrengelman.shadow" version "8.1.1" apply false | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
allprojects { | ||
version = project.version | ||
group = project.group | ||
} | ||
|
||
subprojects { | ||
apply plugin: "java" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
tasks.withType(JavaCompile).configureEach { | ||
it.options.release = 21 | ||
} | ||
|
||
tasks.withType(KotlinCompile).configureEach { | ||
kotlinOptions { | ||
jvmTarget = 21 | ||
} | ||
} | ||
|
||
jar { | ||
from("LICENSE") { | ||
rename { "${it}_${project.base.archivesName.get()}"} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id "org.jetbrains.kotlin.jvm" | ||
id "org.jetbrains.kotlin.plugin.serialization" | ||
id "com.github.johnrengelman.shadow" | ||
} | ||
|
||
repositories {} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1" | ||
implementation "org.slf4j:slf4j-api:2.0.13" | ||
implementation "com.charleskorn.kaml:kaml:${project.kaml_version}" | ||
|
||
testImplementation(platform "org.junit:junit-bom:5.10.3") | ||
testImplementation "org.junit.jupiter:junit-jupiter" | ||
testRuntimeOnly "org.junit.platform:junit-platform-launcher" | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
90 changes: 90 additions & 0 deletions
90
dynmapexport-common/src/main/kotlin/nl/dantevg/dynmapexport/Config.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package nl.dantevg.dynmapexport | ||
|
||
import com.charleskorn.kaml.YamlComment | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import nl.dantevg.dynmapexport.location.TileCoords | ||
import nl.dantevg.dynmapexport.location.WorldCoords | ||
import kotlin.math.max | ||
import kotlin.math.min | ||
|
||
@Serializable | ||
data class Config( | ||
@SerialName("dynmap-host") | ||
@YamlComment( | ||
"The hostname/ip and port of Dynmap.", | ||
"(use localhost for Dynmap running on the same server)" | ||
) | ||
val dynmapHost: String = "localhost:8123", | ||
|
||
@SerialName("auto-combine") | ||
@YamlComment( | ||
"Whether to automatically combine the tiles into a single image.", | ||
"Disabling this can reduce server lag if you encounter it (for large images),", | ||
"but you'll need to combine the tiles yourself.", | ||
) | ||
val autoCombine: Boolean = true, | ||
|
||
@YamlComment( | ||
"A list of export configurations. Example:", | ||
" exports:", | ||
" - world: world", | ||
" map: surface", | ||
" zoom: 0", | ||
" change-threshold: 0.2", | ||
" from:", | ||
" x: -100", | ||
" z: -100", | ||
" to:", | ||
" x: 100", | ||
" z: 100", | ||
) | ||
val exports: List<ExportConfig> = emptyList(), | ||
) | ||
|
||
@Serializable | ||
data class ExportConfig( | ||
val world: String, | ||
val map: String, | ||
val zoom: Int = 0, | ||
@SerialName("change-threshold") | ||
val changeThreshold: Double = 0.2, | ||
val from: WorldCoords, | ||
val to: WorldCoords, | ||
) { | ||
constructor( | ||
world: DynmapWebAPI.World, | ||
map: DynmapWebAPI.Map, | ||
zoom: Int, | ||
changeThreshold: Double, | ||
from: WorldCoords, | ||
to: WorldCoords = from, | ||
) : this(world.name, map.name, zoom, changeThreshold, from, to) | ||
|
||
/** | ||
* Get all tile locations from this export config. | ||
* | ||
* @return a list of tiles that are within the range from the config | ||
*/ | ||
fun toTileLocations(map: DynmapWebAPI.Map): List<TileCoords> { | ||
val tiles: MutableList<TileCoords> = ArrayList() | ||
val (fromTile, toTile) = toMinMaxTileCoords(map) | ||
|
||
for (x in fromTile.x..toTile.x step (1 shl zoom)) { | ||
for (y in fromTile.y..toTile.y step (1 shl zoom)) { | ||
tiles += TileCoords(x, y) | ||
} | ||
} | ||
|
||
return tiles | ||
} | ||
|
||
fun toMinMaxTileCoords(map: DynmapWebAPI.Map): Pair<TileCoords, TileCoords> { | ||
val fromTile = from.toTileCoords(map, zoom) | ||
val toTile = to.toTileCoords(map, zoom) | ||
return Pair( | ||
TileCoords(min(fromTile.x, toTile.x), min(fromTile.y, toTile.y)).floorToZoom(zoom), | ||
TileCoords(max(fromTile.x, toTile.x), max(fromTile.y, toTile.y)).ceilToZoom(zoom) | ||
) | ||
} | ||
} |
Oops, something went wrong.