Matt-MX / KtPaperGui

Declarative GUI focused library for PaperMC. Made for personal use but open source enjoy! :)
Apache License 2.0
28 stars 5 forks source link

Subcommand after argument #33

Closed Matt-MX closed 4 months ago

Matt-MX commented 4 months ago

Currently declarative command builder doesn't allow for defining a subcommand/enum choice after an argument.

val a by doubleArgument()
val b by doubleArgument()

("math" / a / listOf(
    "add".runs<Player> { reply(!"&a${a()} + ${b()} = ${a() + b()}") },
    "sub".runs<Player> { reply(!"&a${a()} - ${b()} = ${a() - b()}") },
    "mul".runs<Player> { reply(!"&a${a()} * ${b()} = ${a() * b()}") },
    "div".runs<Player> { reply(!"&a${a()} / ${b()} = ${a() / b()}") },
) / b) register this

This syntax is not final and is just an example.

Matt-MX commented 4 months ago

Might not be an issue since we can just treat these "subcommands" as multi-args e.g

val choices by multiChoiceArgument<(Double, Double) -> Double>(
    "add" to { a, b -> a + b },
    "sub" to { a, b -> a - b },
    "mul" to { a, b -> a * b },
    "div" to { a, b -> a / b },
)

("math" / a / choices / b) {
    runs<Player> {
        reply(!"&a${choices(a(), b())}")
    }
}