Skip to content

Commit 42751de

Browse files
authored
Merge pull request #13 from jaoafa/feat/purge-isolated
feat: purge isolated chunks 🧹
2 parents 790f7b3 + 7395baa commit 42751de

File tree

4 files changed

+108
-124
lines changed

4 files changed

+108
-124
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "com.jaoafa"
11-
version = "1.0.0"
11+
version = "1.2.0"
1212

1313
repositories {
1414
mavenCentral()

src/main/kotlin/Coordinate.kt

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
import kotlinx.serialization.Serializable
2+
import java.io.File
3+
4+
data class ChunkImageFile(
5+
val x: Int,
6+
val y: Int,
7+
val file: File?
8+
) {
9+
fun toPlacementData() = PlacementData(x, y)
10+
}
211

312
@Serializable
413
data class PlacementData(
514
val xIndex: Int,
615
val yIndex: Int
7-
)
16+
) {
17+
fun chunksAround(multiplier: Int) = mutableListOf<PlacementData>().apply {
18+
add(PlacementData(xIndex + multiplier, yIndex))
19+
add(PlacementData(xIndex - multiplier, yIndex))
20+
add(PlacementData(xIndex, yIndex + multiplier))
21+
add(PlacementData(xIndex, yIndex - multiplier))
22+
add(PlacementData(xIndex + multiplier, yIndex + multiplier))
23+
add(PlacementData(xIndex - multiplier, yIndex + multiplier))
24+
add(PlacementData(xIndex + multiplier, yIndex - multiplier))
25+
add(PlacementData(xIndex - multiplier, yIndex - multiplier))
26+
}
27+
}
828

929
@Serializable
1030
data class PixelCoordinate(

src/main/kotlin/Main.kt

+27-21
Original file line numberDiff line numberDiff line change
@@ -30,90 +30,95 @@ class Main : CliktCommand(
3030
For more detailed information, please refer to https://github.com/jaoafa/DynmapProcessor#readme
3131
""".trimIndent()
3232
) {
33-
val inputType by option(
33+
private val inputType by option(
3434
"-t",
3535
"--type",
3636
help = "Input type"
3737
).enum<InputType>().default(InputType.FILE)
3838

39-
val input by option(
39+
private val input by option(
4040
"-i", "--input",
4141
help = "The directory of tile images."
4242
).path(mustExist = true, canBeFile = false)
4343

44-
val jdbcUrl by option(
44+
private val jdbcUrl by option(
4545
"-j", "--jdbc-url",
4646
help = "JDBC URL to connect to the dynmap database."
4747
).check { it.startsWith("jdbc:mysql://") }
4848

49-
val dbUser by option(
49+
private val dbUser by option(
5050
"-u", "--db-user",
5151
help = "Database user name."
5252
)
5353

54-
val dbPassword by option(
54+
private val dbPassword by option(
5555
"-p", "--db-password",
5656
help = "Database user password."
5757
)
5858

59-
val dbTablePrefix by option(
59+
private val dbTablePrefix by option(
6060
"--db-table-prefix",
6161
help = "Database table name."
6262
).default("dmap")
6363

64-
val dbMapId by option(
64+
private val dbMapId by option(
6565
"--db-map-id",
6666
help = "Map ID."
6767
).int().default(1)
6868

69-
val output by option(
69+
private val output by option(
7070
"-o", "--output",
7171
help = "The directory to output generated images and metadata."
7272
).path(canBeFile = false).required()
7373

74-
val cache by option(
74+
private val cache by option(
7575
"--cache", //fixme when zoom level is different but use of cache is allowed...
7676
help = "Whether to allow the use of cached basemap. (Skip basemap generation from scratch)"
7777
).flag(default = false)
7878

79-
val zoom by option(
79+
private val purgeIsolated by option(
80+
"--purge-isolated",
81+
help = "Whether to purge isolated chunks."
82+
).flag(default = false)
83+
84+
private val zoom by option(
8085
"-z", "--zoom",
8186
help = "Specify the zoom level from 0 to 4 (4 by default)"
8287
).int().default(4).check("Value must be 0 to 4") {
8388
it in 0..4
8489
}
8590

86-
val grid by option(
91+
private val grid by option(
8792
"-g", "--grid",
8893
help = "Whether to enable chunk grid."
8994
).flag(default = false)
9095

91-
val edit by option(
96+
private val edit by option(
9297
"-e", "--edit",
9398
help = "Whether to enable image editing."
9499
).flag(default = false)
95100

96-
val markers by option(
101+
private val markers by option(
97102
"-m", "--markers",
98103
help = "The file path to the JSON file that configures markers."
99104
).path(mustExist = true, canBeDir = false)
100105

101-
val clip by option(
106+
private val clip by option(
102107
"-c", "--clip",
103108
help = "Clip the specified area from the map image. Format: x1,y1,x2,y2"
104109
).split(",").check("Length of the list must be 4. For example: 120,150,-10,10") { it.size == 4 }
105110

106-
val height by option(
111+
private val height by option(
107112
"-h", "--height",
108113
help = "Height of the map image. Using this with the width option might cause distortion."
109114
).int().check("Value must be positive.") { 0 < it }
110115

111-
val width by option(
116+
private val width by option(
112117
"-w", "--width",
113118
help = "Width of the map image. Using this with the height option might cause distortion."
114119
).int().check("Value must be positive.") { 0 < it }
115120

116-
val resize by option(
121+
private val resize by option(
117122
"-r", "--resize",
118123
help = "Scale up (or down) the output image to the specified scale rate. (0<x<1 to scale down, 1<x to scale up)"
119124
).double().default(1.0).check { it > 0 }
@@ -139,9 +144,10 @@ class Main : CliktCommand(
139144

140145
val inputDirectory = when (inputType) {
141146
InputType.FILE -> input.toString()
142-
InputType.DATABASE -> if (input != null) input.toString() else createTempDirectory("dynmap-processor").toFile().apply {
143-
deleteOnExit()
144-
}.absolutePath
147+
InputType.DATABASE -> if (input != null) input.toString() else createTempDirectory("dynmap-processor").toFile()
148+
.apply {
149+
deleteOnExit()
150+
}.absolutePath
145151
}
146152

147153
if (jdbcUrl != null && dbUser != null && dbPassword != null) {
@@ -159,7 +165,7 @@ class Main : CliktCommand(
159165
val mapImage =
160166
if (basemapExists && metadataExists && cache)
161167
MapImage.load(outputString, inputDirectory)
162-
else MapImage.create(outputString, inputDirectory, zoom, chunkImageResolution, grid)
168+
else MapImage.create(outputString, inputDirectory, zoom, chunkImageResolution, grid, purgeIsolated)
163169

164170
if (edit) {
165171
val markerFile = File(this.markers.toString())

0 commit comments

Comments
 (0)