Skip to content

Commit d354e29

Browse files
committed
[0.1.1] Update Dependencies
1 parent 6bedec2 commit d354e29

File tree

5 files changed

+51
-26
lines changed

5 files changed

+51
-26
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
`maven-publish`
77
}
88

9-
val v = "0.1.0"
9+
val v = "0.1.1"
1010

1111
group = "xyz.calcugames"
1212
version = if (project.hasProperty("snapshot")) "$v-SNAPSHOT" else v
@@ -20,8 +20,8 @@ repositories {
2020
}
2121

2222
dependencies {
23-
commonMainImplementation("com.github.ajalt.clikt:clikt:4.4.0")
24-
commonMainImplementation("xyz.calcugames:levelz-kt:0.3.1")
23+
commonMainImplementation("com.github.ajalt.clikt:clikt:5.0.0")
24+
commonMainImplementation("xyz.calcugames:levelz-kt:0.3.2")
2525
commonMainImplementation("com.soywiz:korlibs-io:6.0.1")
2626

2727
commonTestImplementation(kotlin("test"))

src/commonMain/kotlin/xyz/calcugames/levelz/cli/Create.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package xyz.calcugames.levelz.cli
22

33
import com.github.ajalt.clikt.core.CliktCommand
4+
import com.github.ajalt.clikt.core.Context
45
import com.github.ajalt.clikt.core.PrintMessage
6+
import com.github.ajalt.clikt.core.theme
57
import com.github.ajalt.clikt.parameters.arguments.argument
68
import com.github.ajalt.clikt.parameters.arguments.optional
79
import com.github.ajalt.clikt.parameters.options.*
@@ -16,7 +18,7 @@ import xyz.calcugames.levelz.builder.LevelBuilder
1618
import xyz.calcugames.levelz.coord.Coordinate2D
1719
import xyz.calcugames.levelz.coord.Coordinate3D
1820

19-
class Create : CliktCommand(name = "create", help = "Generates a new LevelZ save file") {
21+
class Create : CliktCommand(name = "create") {
2022
private val output by argument(help = "The path to output the save to. If empty, the save will be output to the console")
2123
.optional()
2224

@@ -39,15 +41,26 @@ class Create : CliktCommand(name = "create", help = "Generates a new LevelZ save
3941
private val override by option("-o", "--override", help = "Override the file if it already exists")
4042
.flag("--no-override")
4143

44+
override fun help(context: Context): String = context.theme.info("Generates a new LevelZ save file")
45+
4246
override fun run() = runBlocking(Dispatchers.IO) {
4347
val builder = if (dimension == 2) LevelBuilder.create2D() else LevelBuilder.create3D()
4448

45-
for ((header, value) in headers)
46-
builder.header(header, value)
49+
for ((header, value) in headers) {
50+
var value0 = value
51+
if (header == "spawn" && value == "default")
52+
value0 = if (dimension == 2) Coordinate2D(0, 0).toString() else Coordinate3D(0, 0, 0).toString()
53+
54+
builder.header(header, value0)
55+
}
4756

4857
for ((block, value) in blocks) {
49-
val coordinate = if (dimension == 2) Coordinate2D.fromString(value) else Coordinate3D.fromString(value)
50-
builder.block(block, coordinate)
58+
try {
59+
val coordinate = if (dimension == 2) Coordinate2D.fromString(value) else Coordinate3D.fromString(value)
60+
builder.block(block, coordinate)
61+
} catch (e: IllegalArgumentException) {
62+
throw PrintMessage("Invalid coordinate: $value", 1, true)
63+
}
5164
}
5265

5366
val level = builder.build()

src/commonMain/kotlin/xyz/calcugames/levelz/cli/Edit.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package xyz.calcugames.levelz.cli
22

3-
import com.github.ajalt.clikt.core.CliktCommand
4-
import com.github.ajalt.clikt.core.FileNotFound
5-
import com.github.ajalt.clikt.core.InvalidFileFormat
3+
import com.github.ajalt.clikt.core.*
64
import com.github.ajalt.clikt.parameters.arguments.argument
75
import com.github.ajalt.clikt.parameters.arguments.optional
86
import com.github.ajalt.clikt.parameters.options.*
@@ -19,7 +17,7 @@ import xyz.calcugames.levelz.coord.Coordinate3D
1917
import xyz.calcugames.levelz.parser.ParseException
2018
import xyz.calcugames.levelz.parser.parseLevel
2119

22-
class Edit : CliktCommand(name = "edit", help = "Edit a LevelZ save file") {
20+
class Edit : CliktCommand(name = "edit") {
2321
private val input by argument(help = "The save file to edit")
2422
private val output by argument(help = "The path to output the save to. If empty, the save will be output to the console")
2523
.optional()
@@ -44,6 +42,8 @@ class Edit : CliktCommand(name = "edit", help = "Edit a LevelZ save file") {
4442
private val override by option("-o", "--override", help = "Override the output file if it already exists")
4543
.flag("--no-override")
4644

45+
override fun help(context: Context): String = context.theme.info("Edit a LevelZ save file")
46+
4747
override fun run() = runBlocking(Dispatchers.IO) {
4848
val file = localCurrentDirVfs[input]
4949
if (!file.exists())
@@ -57,18 +57,27 @@ class Edit : CliktCommand(name = "edit", help = "Edit a LevelZ save file") {
5757
try {
5858
val level = parseLevel(save)
5959
val dimension = level.dimension
60-
val builder = if (dimension.is2D) LevelBuilder.create2D() else LevelBuilder.create3D()
60+
val builder = LevelBuilder.create(dimension)
6161

6262
val newHeaders = (level.headers + headers.toMap())
6363
.filter { (header, _) -> header !in removedHeaders }
6464

65-
for ((header, value) in newHeaders)
66-
builder.header(header, value)
65+
for ((header, value) in newHeaders) {
66+
var value0 = value
67+
if (header == "spawn" && value == "default")
68+
value0 = if (dimension.is2D) Coordinate2D(0, 0).toString() else Coordinate3D(0, 0, 0).toString()
69+
70+
builder.header(header, value0)
71+
}
6772

6873
val newBlocks = level.blocks.toMutableList()
6974
for ((block, value) in blocks) {
70-
val coordinate = if (dimension.is2D) Coordinate2D.fromString(value) else Coordinate3D.fromString(value)
71-
newBlocks.add(LevelObject(Block(block), coordinate))
75+
try {
76+
val coordinate = if (dimension.is2D) Coordinate2D.fromString(value) else Coordinate3D.fromString(value)
77+
newBlocks.add(LevelObject(Block(block), coordinate))
78+
} catch (e: IllegalArgumentException) {
79+
throw InvalidFileFormat(file.path, "Invalid coordinate: $value")
80+
}
7281
}
7382

7483
for (block in newBlocks.filter { it.block.name !in removedBlocks })

src/commonMain/kotlin/xyz/calcugames/levelz/cli/Validate.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package xyz.calcugames.levelz.cli
22

3-
import com.github.ajalt.clikt.core.CliktCommand
4-
import com.github.ajalt.clikt.core.FileNotFound
5-
import com.github.ajalt.clikt.core.InvalidFileFormat
6-
import com.github.ajalt.clikt.core.PrintMessage
3+
import com.github.ajalt.clikt.core.*
74
import com.github.ajalt.clikt.parameters.arguments.argument
85
import com.github.ajalt.clikt.parameters.options.*
96
import com.github.ajalt.clikt.parameters.types.int
@@ -17,7 +14,7 @@ import xyz.calcugames.levelz.coord.Coordinate3D
1714
import xyz.calcugames.levelz.parser.ParseException
1815
import xyz.calcugames.levelz.parser.parseLevel
1916

20-
class Validate : CliktCommand(name = "validate", help = "Validate a LevelZ save file") {
17+
class Validate : CliktCommand(name = "validate") {
2118
private val input by argument(help = "The save file to validate")
2219

2320
private val dimension by option("-d", "--dimension", help = "The dimension to validate the save file against")
@@ -37,6 +34,8 @@ class Validate : CliktCommand(name = "validate", help = "Validate a LevelZ save
3734
.pair()
3835
.multiple()
3936

37+
override fun help(context: Context): String = context.theme.info("Validate a LevelZ save file")
38+
4039
override fun run() = runBlocking(Dispatchers.IO) {
4140
echo("Validating '$input'...")
4241

@@ -59,10 +58,13 @@ class Validate : CliktCommand(name = "validate", help = "Validate a LevelZ save
5958
throw PrintMessage("Minimum coordinates mismatch: Expected $minBlocks+, got ${level.blocks.size}", 1, true)
6059

6160
if (spawn != null) {
62-
val spawn0 = if (level.dimension.is2D) Coordinate2D.fromString(spawn!!) else Coordinate3D.fromString(spawn!!)
63-
64-
if (level.spawn != spawn0)
65-
throw PrintMessage("Spawn point mismatch: Expected '$spawn0', got '${level.spawn}'", 1, true)
61+
try {
62+
val spawn0 = if (level.dimension.is2D) Coordinate2D.fromString(spawn!!) else Coordinate3D.fromString(spawn!!)
63+
if (level.spawn != spawn0)
64+
throw PrintMessage("Spawn point mismatch: Expected '$spawn0', got '${level.spawn}'", 1, true)
65+
} catch (e: IllegalArgumentException) {
66+
throw PrintMessage("Invalid coordinate: ${spawn!!}", 1, true)
67+
}
6668
}
6769

6870
val actualHeaders = level.getAllHeaders()

src/commonMain/kotlin/xyz/calcugames/levelz/cli/main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package xyz.calcugames.levelz.cli
22

33
import com.github.ajalt.clikt.core.CliktCommand
4+
import com.github.ajalt.clikt.core.main
45
import com.github.ajalt.clikt.core.subcommands
56

67
class LevelZ : CliktCommand(name = "levelz") {

0 commit comments

Comments
 (0)