Skip to content

Commit cdff286

Browse files
committed
Formatting
1 parent e43481a commit cdff286

File tree

10 files changed

+76
-76
lines changed

10 files changed

+76
-76
lines changed

dynmapexport-common/src/main/kotlin/nl/dantevg/dynmapexport/DynmapWebAPI.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ object DynmapWebAPI {
1010
.filter { it.name == name }
1111
.findAny()
1212
.orElse(null)
13-
13+
1414
fun getMapByName(world: String, map: String): Map? =
1515
getWorldByName(world)?.getMapByName(map)
1616
}
17-
17+
1818
@Serializable
1919
class World(val name: String, val maps: List<Map>) {
2020
fun getMapByName(name: String): Map? =
@@ -23,7 +23,7 @@ object DynmapWebAPI {
2323
.findAny()
2424
.orElse(null)
2525
}
26-
26+
2727
@Serializable
2828
data class Map(val name: String, val prefix: String, val scale: Int, val worldtomap: DoubleArray)
2929
}

dynmapexport-common/src/main/kotlin/nl/dantevg/dynmapexport/Paths.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Paths {
1515
*/
1616
private val instantFormat = DateTimeFormatter.ofPattern("uuuuMMdd'T'HHmmss'Z'")
1717
.withZone(ZoneId.from(ZoneOffset.UTC))
18-
18+
1919
/**
2020
* Get the Dynmap path to the tile, at
2121
* `{world}/{map}/{regionX}_{regionZ}/{zoom}_{tileX}_{tileY}.png`
@@ -26,20 +26,20 @@ object Paths {
2626
"tiles/${config.world}/${
2727
dynmapConfig.getMapByName(config.world, config.map)?.prefix
2828
}/${tile.tileGroupCoords}/${getZoomString(config.zoom)}${tile.x}_${tile.y}.png"
29-
29+
3030
/**
3131
* Get the local map directory, at `plugins/DynmapExport/exports/{world}/{map}/`
3232
*/
3333
fun getLocalMapDir(plugin: DynmapExport, config: ExportConfig): File =
3434
File(plugin.exportsDir, "${config.world}/${config.map}")
35-
35+
3636
/**
3737
* Get the local directory of a single export at a given [instant] in time,
3838
* at `plugins/DynmapExport/exports/{world}/{map}/{instant}/`
3939
*/
4040
fun getLocalExportDir(plugin: DynmapExport, config: ExportConfig, instant: Instant): File =
4141
File(getLocalMapDir(plugin, config), instantFormat.format(instant))
42-
42+
4343
/**
4444
* Get the local file for the image in a single export at a given [instant]
4545
* in time, at the given [tile]-location, at
@@ -50,16 +50,16 @@ object Paths {
5050
*/
5151
fun getLocalTileFile(plugin: DynmapExport, config: ExportConfig, instant: Instant, tile: TileCoords): File =
5252
File(getLocalExportDir(plugin, config, instant), "${getZoomString(config.zoom)}${tile.x}_${tile.y}.png")
53-
53+
5454
/**
5555
* Get the local file for the combined image of a single export at a given
5656
* [instant] in time, at `plugins/DynmapExport/exports/{world}/{map}/{instant}.png`
5757
*/
5858
fun getLocalCombinedFile(plugin: DynmapExport, config: ExportConfig, instant: Instant): File =
5959
File(getLocalMapDir(plugin, config), instantFormat.format(instant) + ".png")
60-
60+
6161
fun getInstantFromFile(file: File): Instant =
6262
Instant.from(instantFormat.parse(file.nameWithoutExtension))
63-
63+
6464
private fun getZoomString(zoom: Int): String = if (zoom > 0) "z".repeat(zoom) + "_" else ""
6565
}

dynmapexport-common/src/main/kotlin/nl/dantevg/dynmapexport/TileCombiner.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TileCombiner(
1818
private val minMaxTile = config.toMinMaxTileCoords(map)
1919
private val minTile = minMaxTile.first
2020
private val maxTile = minMaxTile.second
21-
21+
2222
fun combineAndSave(): Boolean {
2323
val result: BufferedImage = combine() ?: return false
2424
val file = Paths.getLocalCombinedFile(plugin, config, instant)
@@ -30,23 +30,23 @@ class TileCombiner(
3030
return false
3131
}
3232
}
33-
33+
3434
private fun combine(): BufferedImage? {
3535
val width = ((maxTile.x - minTile.x) / (1 shl config.zoom) + 1) * PIXELS_PER_TILE
3636
val height = ((maxTile.y - minTile.y) / (1 shl config.zoom) + 1) * PIXELS_PER_TILE
37-
37+
3838
plugin.logger.debug("Creating a ${width}x$height image from $minTile to $maxTile")
39-
39+
4040
val output = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
4141
val graphics = output.createGraphics()
42-
42+
4343
for (tile in config.toTileLocations(map)) {
4444
if (!drawTile(graphics, tile)) return null
4545
}
46-
46+
4747
return output
4848
}
49-
49+
5050
private fun drawTile(graphics: Graphics2D, tile: TileCoords): Boolean {
5151
val tileFile = Paths.getLocalTileFile(plugin, config, instant, tile)
5252
val tileImage = try {
@@ -55,12 +55,12 @@ class TileCombiner(
5555
plugin.logger.error("Cannot read image from file $tileFile", e)
5656
return false
5757
}
58-
58+
5959
val (x, y) = tileCoordsToPixel(tile)
6060
graphics.drawImage(tileImage, x, y, null)
6161
return true
6262
}
63-
63+
6464
private fun tileCoordsToPixel(tile: TileCoords): Pair<Int, Int> =
6565
Pair(
6666
(tile.x - minTile.x) / (1 shl config.zoom) * PIXELS_PER_TILE,

dynmapexport-common/src/main/kotlin/nl/dantevg/dynmapexport/location/TileCoords.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package nl.dantevg.dynmapexport.location
33
data class TileCoords(val x: Int, val y: Int) {
44
val tileGroupCoords: TileGroupCoords
55
get() = TileGroupCoords(x shr 5, y shr 5)
6-
6+
77
fun floorToZoom(zoom: Int): TileCoords =
88
TileCoords(zoomedFloor(x.toDouble(), zoom), zoomedFloor(y.toDouble(), zoom))
9-
9+
1010
fun ceilToZoom(zoom: Int): TileCoords =
1111
TileCoords(zoomedCeil(x.toDouble(), zoom), zoomedCeil(y.toDouble(), zoom))
12-
12+
1313
override fun toString(): String = x.toString() + SEPARATOR + y
14-
14+
1515
companion object {
1616
const val SEPARATOR = ","
17-
17+
1818
fun parse(str: String): TileCoords {
1919
val separator = str.indexOf(SEPARATOR)
2020
val x = Integer.parseInt(str.substring(0, separator - 1))

dynmapexport-common/src/main/kotlin/nl/dantevg/dynmapexport/log/Logger.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.util.logging.Level
44

55
interface Logger {
66
fun log(level: Level, message: String?, thrown: Throwable? = null)
7-
7+
88
fun debug(message: String?, thrown: Throwable? = null) = log(Level.CONFIG, message, thrown)
99
fun info(message: String?, thrown: Throwable? = null) = log(Level.INFO, message, thrown)
1010
fun warn(message: String?, thrown: Throwable? = null) = log(Level.WARNING, message, thrown)

dynmapexport-common/src/test/kotlin/nl/dantevg/dynmapexport/location/WorldCoordsTest.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class WorldCoordsTest {
1515
fun toTileCoordsFlat(worldCoords: WorldCoords, tileCoords: TileCoords?, zoom: Int) {
1616
Assertions.assertEquals(tileCoords, worldCoords.toTileCoords(flat, zoom))
1717
}
18-
18+
1919
@DisplayName("World coordinates to projection 'surface' tile coordinates")
2020
@ParameterizedTest(name = "zoom {2} @ {0} -> {1}")
2121
@MethodSource("surfaceCoordinateProvider")
2222
fun toTileCoordsSurface(worldCoords: WorldCoords, tileCoords: TileCoords?, zoom: Int) {
2323
Assertions.assertEquals(tileCoords, worldCoords.toTileCoords(surface, zoom))
2424
}
25-
25+
2626
companion object {
2727
val flat: DynmapWebAPI.Map = DynmapWebAPI.Map(
2828
"flat", "flat", 0, doubleArrayOf(
@@ -31,15 +31,15 @@ class WorldCoordsTest {
3131
0.0, 1.0, 0.0
3232
)
3333
)
34-
34+
3535
val surface: DynmapWebAPI.Map = DynmapWebAPI.Map(
3636
"surface", "surface", 0, doubleArrayOf(
3737
11.31370849898476, 0.0, -11.313708498984761,
3838
-5.6568542494923815, 13.856406460551018, -5.656854249492381,
3939
0.0, 1.0, 0.0
4040
)
4141
)
42-
42+
4343
@JvmStatic
4444
fun flatCoordinateProvider(): Stream<Arguments> {
4545
return Stream.of(
@@ -48,46 +48,46 @@ class WorldCoordsTest {
4848
Arguments.of(WorldCoords(31, 0, 0), TileCoords(0, -1), 0),
4949
Arguments.of(WorldCoords(0, 0, 31), TileCoords(0, -1), 0),
5050
Arguments.of(WorldCoords(31, 0, 31), TileCoords(0, -1), 0),
51-
51+
5252
Arguments.of(WorldCoords(0, 0, -32), TileCoords(0, 0), 0),
5353
Arguments.of(WorldCoords(31, 0, -32), TileCoords(0, 0), 0),
5454
Arguments.of(WorldCoords(0, 0, -1), TileCoords(0, 0), 0),
5555
Arguments.of(WorldCoords(31, 0, -1), TileCoords(0, 0), 0),
56-
56+
5757
// Zoom 1
5858
Arguments.of(WorldCoords(0, 0, -32), TileCoords(0, 0), 1),
5959
Arguments.of(WorldCoords(63, 0, -32), TileCoords(0, 0), 1),
6060
Arguments.of(WorldCoords(0, 0, 31), TileCoords(0, 0), 1),
6161
Arguments.of(WorldCoords(63, 0, 31), TileCoords(0, 0), 1),
62-
62+
6363
Arguments.of(WorldCoords(0, 0, -96), TileCoords(0, 2), 1),
6464
Arguments.of(WorldCoords(63, 0, -96), TileCoords(0, 2), 1),
6565
Arguments.of(WorldCoords(0, 0, -33), TileCoords(0, 2), 1),
6666
Arguments.of(WorldCoords(63, 0, -33), TileCoords(0, 2), 1),
67-
67+
6868
Arguments.of(WorldCoords(0, 0, 32), TileCoords(0, -2), 1),
6969
Arguments.of(WorldCoords(63, 0, 32), TileCoords(0, -2), 1),
7070
Arguments.of(WorldCoords(0, 0, 95), TileCoords(0, -2), 1),
7171
Arguments.of(WorldCoords(63, 0, 95), TileCoords(0, -2), 1),
72-
72+
7373
Arguments.of(WorldCoords(0, 0, 96), TileCoords(0, -4), 1),
7474
Arguments.of(WorldCoords(63, 0, 96), TileCoords(0, -4), 1),
7575
Arguments.of(WorldCoords(0, 0, 159), TileCoords(0, -4), 1),
7676
Arguments.of(WorldCoords(63, 0, 159), TileCoords(0, -4), 1),
77-
77+
7878
Arguments.of(WorldCoords(64, 0, -32), TileCoords(2, 0), 1),
7979
Arguments.of(WorldCoords(127, 0, -32), TileCoords(2, 0), 1),
8080
Arguments.of(WorldCoords(64, 0, 31), TileCoords(2, 0), 1),
8181
Arguments.of(WorldCoords(127, 0, 31), TileCoords(2, 0), 1),
82-
82+
8383
// Zoom 2
8484
Arguments.of(WorldCoords(0, 0, -32), TileCoords(0, 0), 2),
8585
Arguments.of(WorldCoords(127, 0, -32), TileCoords(0, 0), 2),
8686
Arguments.of(WorldCoords(0, 0, 95), TileCoords(0, 0), 2),
8787
Arguments.of(WorldCoords(127, 0, 95), TileCoords(0, 0), 2)
8888
)
8989
}
90-
90+
9191
@JvmStatic
9292
fun surfaceCoordinateProvider(): Stream<Arguments> {
9393
return Stream.of( // Zoom 0

dynmapexport-fabric/src/main/kotlin/nl/dantevg/dynmapexport/DynmapExportMod.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ import kotlin.io.path.outputStream
1515

1616
object DynmapExportMod : ModInitializer, DynmapExport {
1717
const val MOD_ID = "dynmapexport"
18-
18+
1919
override val logger = Slf4jLogger(LoggerFactory.getLogger(MOD_ID))
2020
override val exportsDir = FabricLoader.getInstance().gameDir.resolve(MOD_ID).toFile()
21-
21+
2222
override var config = loadConfig()
2323
override var worldConfiguration: DynmapWebAPI.Configuration? = null
2424
override var imageThresholdCache = ImageThresholdCache(this)
2525
override var downloader = Downloader(this)
26-
26+
2727
override fun onInitialize() {
2828
net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents.SERVER_STARTED.register {
2929
worldConfiguration = getDynmapConfiguration()
3030
?.also { logger.info("Loaded dynmap configuration") }
3131
}
32-
32+
3333
command // auto-register command with Silk
3434
}
35-
35+
3636
override fun reload() {
3737
logger.info("Reloading")
3838
config = loadConfig()
3939
worldConfiguration = getDynmapConfiguration()
4040
}
41-
41+
4242
private fun loadConfig(): Config {
4343
FabricLoader.getInstance().configDir.createDirectories()
4444
val configPath = FabricLoader.getInstance().configDir.resolve("$MOD_ID.yml")

dynmapexport-fabric/src/main/kotlin/nl/dantevg/dynmapexport/command.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ val command = command(DynmapExportMod.MOD_ID) {
77
literal("now") runsAsync {
88
DynmapExportMod.export { source.sendMessage(it.literal) }
99
}
10-
10+
1111
literal("reload") runs {
1212
DynmapExportMod.reload()
1313
if (source.isExecutedByPlayer) source.sendMessage("Reload complete".literal)
1414
}
15-
15+
1616
literal("export") {
1717
argument<String>("world") { world ->
1818
suggestList { DynmapExportMod.worldConfiguration?.worlds?.map { it.name } ?: emptyList() }
19-
19+
2020
argument<String>("map") { map ->
2121
suggestList { ctx ->
2222
DynmapExportMod.worldConfiguration?.getWorldByName(world(ctx))?.maps?.map { it.name } ?: emptyList()
2323
}
24-
24+
2525
argument<Int>("x") { x ->
2626
argument<Int>("z") { z ->
2727
argument<Int>("zoom") { zoom ->
@@ -40,15 +40,15 @@ val command = command(DynmapExportMod.MOD_ID) {
4040
}
4141
}
4242
}
43-
43+
4444
literal("purge") {
4545
runs {
4646
source.sendMessage("Warning: this will permanently delete all but the last export. To confirm, run /${DynmapExportMod.MOD_ID} purge confirm".literal)
4747
}
4848
literal("confirm") runs {
4949
DynmapExportMod.purge(false)
5050
}
51-
51+
5252
literal("all") {
5353
runs {
5454
source.sendMessage("Warning: this will permanently delete all exports. To confirm, run /${DynmapExportMod.MOD_ID} purge all confirm".literal)

0 commit comments

Comments
 (0)