tested & fixed some bugs for ConfigArgs.kt

This commit is contained in:
2024-12-15 10:57:59 +01:00
parent 7716ba30f8
commit 3e08bd4d81
4 changed files with 37 additions and 15 deletions
@@ -201,12 +201,15 @@ fun emitterListArg(argName: String) : RequiredArgumentBuilder<ServerCommandSourc
} }
fun curveListArg(argName: String) : RequiredArgumentBuilder<ServerCommandSource, String> { fun curveListArg(argName: String): RequiredArgumentBuilder<ServerCommandSource, String> {
return CommandManager.argument(argName, StringArgumentType.string()) return CommandManager.argument(argName, StringArgumentType.string())
.suggests { _, builder -> .suggests { _, builder ->
LerpCurves::class.nestedClasses.forEach { nestClass -> LerpCurves.Companion::class.members
builder.suggest(nestClass.simpleName) .filterIsInstance<kotlin.reflect.KProperty1<LerpCurves.Companion, *>>()
} .filter { it.returnType.classifier == LerpCurves::class }
.forEach { property ->
builder.suggest(property.name)
}
CompletableFuture.completedFuture(builder.build()) CompletableFuture.completedFuture(builder.build())
} }
} }
@@ -81,11 +81,14 @@ fun parseArgTypeToFunc(type: KType) : CommandArgumentBuilder? {
ParamClasses.PairInt::class -> ::pairIntArg ParamClasses.PairInt::class -> ::pairIntArg
SpawningShape::class -> ::shapeArg SpawningShape::class -> ::shapeArg
ParamClasses.PairVec3f::class -> ::pairVec3fArg ParamClasses.PairVec3f::class -> ::pairVec3fArg
ParamClasses.PairFloat::class -> ::pairFloatArg ParamClasses.PairFloat::class -> ::pairFloatArg // unexpected error
ParamClasses.TransformWithVel::class -> ::transformWithVelArg ParamClasses.TransformWithVel::class -> ::transformWithVelArg
ParamClasses.StringCurve::class -> ::stringCurveArg ParamClasses.StringCurve::class -> ::stringCurveArg // curve suggestion is only "companion" (bypassing doesn't work)
ParamClasses.LerpVal::class -> ::lerpValArg // doesn't add items (added items result with a space: "acacia boat" instead of "acacia_boat")
ParamClasses.ForceFieldArray::class -> ::forceFieldArg // doesn't remove items
ParamClasses.LerpVal::class -> ::lerpValArg // curve suggestion (see above)
ParamClasses.ForceFieldArray::class -> ::forceFieldArg // doesn't add force fields
// removing gives unexpected error (because index error)
else -> null else -> null
} }
} }
@@ -272,12 +275,14 @@ fun shapeArgExec(paramName: String, access: KProperty1<EmitterParams, SpawningSh
val radius = FloatArgumentType.getFloat(context, "Radius") val radius = FloatArgumentType.getFloat(context, "Radius")
val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge") val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge")
updateParam(id, access, SpawningShape.Circle(radius, onEdge)) updateParam(id, access, SpawningShape.Circle(radius, onEdge))
successText(access, "Circle", id, context)
} }
"Rect" -> { "Rect" -> {
val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge") val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge")
val x = FloatArgumentType.getFloat(context, "X") val x = FloatArgumentType.getFloat(context, "X")
val y = FloatArgumentType.getFloat(context, "Y") val y = FloatArgumentType.getFloat(context, "Y")
updateParam(id, access, SpawningShape.Rect(Vector2f(x, y), onEdge)) updateParam(id, access, SpawningShape.Rect(Vector2f(x, y), onEdge))
successText(access, "Rect", id, context)
} }
"Cube" -> { "Cube" -> {
val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge") val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge")
@@ -285,18 +290,19 @@ fun shapeArgExec(paramName: String, access: KProperty1<EmitterParams, SpawningSh
val y = FloatArgumentType.getFloat(context, "Y") val y = FloatArgumentType.getFloat(context, "Y")
val z = FloatArgumentType.getFloat(context, "Z") val z = FloatArgumentType.getFloat(context, "Z")
updateParam(id, access, SpawningShape.Cube(Vector3f(x, y, z), onEdge)) updateParam(id, access, SpawningShape.Cube(Vector3f(x, y, z), onEdge))
successText(access, "Cube", id, context)
} }
"Sphere" -> { "Sphere" -> {
val radius = FloatArgumentType.getFloat(context, "Radius") val radius = FloatArgumentType.getFloat(context, "Radius")
val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge") val onEdge = BoolArgumentType.getBool(context, "Spawn On Edge")
updateParam(id, access, SpawningShape.Sphere(radius, onEdge)) updateParam(id, access, SpawningShape.Sphere(radius, onEdge))
successText(access, "Sphere", id, context)
} }
"Point" -> { "Point" -> {
updateParam(id, access, SpawningShape.Point) updateParam(id, access, SpawningShape.Point)
successText(access, "Point", id, context)
} }
} }
successText(access, access::class.simpleName ?: "UNKNOWN", id, context)
} }
fun pairVec3fArg(access: KProperty1<EmitterParams,ParamClasses.PairVec3f>, fun pairVec3fArg(access: KProperty1<EmitterParams,ParamClasses.PairVec3f>,
@@ -115,7 +115,20 @@ class ParticleEmitter(
} }
else if (params.spawnDuration is ParamClasses.Duration.InfiniteLoop) { else if (params.spawnDuration is ParamClasses.Duration.InfiniteLoop) {
return val loopDur = (params.spawnDuration as ParamClasses.Duration.InfiniteLoop).loopDur
val loopDelay = (params.spawnDuration as ParamClasses.Duration.InfiniteLoop).loopDelay
if (timePaused >= loopDelay) {
isPaused = false
timePaused = 0
}
if (timeAlive >= loopDur && loopDelay > 0) {
isPaused = true
timeAlive = 0
}
if (!isPaused) { timeAlive += 1 }
else { timePaused += 1 }
} }
} }
@@ -23,7 +23,7 @@ sealed class SpawningShape() {
} }
} }
class Rect(private val size: Vector2f, val spawnOnEdge: Boolean) : SpawningShape() { class Rect(val size: Vector2f, val spawnOnEdge: Boolean) : SpawningShape() {
fun randomWithin(): Vector3f { fun randomWithin(): Vector3f {
return Vector3f(randomFloatBetween(0.0f, size.x), 0.0f, randomFloatBetween(0.0f, size.y)) return Vector3f(randomFloatBetween(0.0f, size.x), 0.0f, randomFloatBetween(0.0f, size.y))
} }
@@ -41,7 +41,7 @@ sealed class SpawningShape() {
} }
} }
class Cube(private val size: Vector3f, val spawnOnEdge: Boolean) : SpawningShape() { class Cube(val size: Vector3f, val spawnOnEdge: Boolean) : SpawningShape() {
fun randomWithin(): Vector3f { fun randomWithin(): Vector3f {
return Vector3f( return Vector3f(
randomFloatBetween(0.0f, size.x), randomFloatBetween(0.0f, size.x),
@@ -108,8 +108,8 @@ sealed class SpawningShape() {
return when (shape) { return when (shape) {
is Circle -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() } is Circle -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() }
is Sphere -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() } is Sphere -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() }
is Rect -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() } is Rect -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() }.sub(Vector3f(shape.size.x, 0.0f, shape.size.y).div(2.0f))
is Cube -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() } is Cube -> if (!shape.spawnOnEdge) { shape.randomWithin() } else { shape.randomOnEdge() }.sub(Vector3f(shape.size.x, shape.size.y, shape.size.z).div(2.0f))
is Point -> Vector3f(0.0f, 0.0f, 0.0f) is Point -> Vector3f(0.0f, 0.0f, 0.0f)
} }
} }