don't use valueOf explicitly
This commit is contained in:
parent
233fb28eac
commit
481a9aef5d
6 changed files with 35 additions and 9 deletions
|
@ -159,7 +159,7 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
|
|||
SpellDatum(SpellList.fromNBT(nbt.getList(key, Tag.TAG_COMPOUND), world))
|
||||
}
|
||||
TAG_WIDGET -> {
|
||||
SpellDatum(Widget.valueOf(nbt.getString(key)))
|
||||
SpellDatum(Widget.fromString(nbt.getString(key)))
|
||||
}
|
||||
TAG_PATTERN -> {
|
||||
SpellDatum(HexPattern.fromNBT(nbt.getCompound(TAG_PATTERN)))
|
||||
|
@ -214,7 +214,8 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
|
|||
out += "]".white
|
||||
}
|
||||
TAG_WIDGET -> {
|
||||
val widget = Widget.valueOf(nbt.getString(key))
|
||||
val widget = Widget.fromString(nbt.getString(key))
|
||||
|
||||
out += if (widget == Widget.GARBAGE)
|
||||
"arimfexendrapuse".darkGray.obfuscated
|
||||
else
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package at.petrak.hexcasting.api.spell
|
||||
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Miscellaneous spell datums used as markers, etc.
|
||||
|
@ -17,4 +18,12 @@ enum class Widget : ConstManaOperator {
|
|||
|
||||
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> =
|
||||
this.asSpellResult
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromString(key: String): Widget {
|
||||
val lowercaseKey = key.lowercase(Locale.ROOT)
|
||||
return values().firstOrNull { it.name.lowercase(Locale.ROOT) == lowercaseKey } ?: GARBAGE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,7 @@ data class ResolvedPattern(val pattern: HexPattern, val origin: HexCoord, var ty
|
|||
fun fromNBT(tag: CompoundTag): ResolvedPattern {
|
||||
val pattern = HexPattern.fromNBT(tag.getCompound("Pattern"))
|
||||
val origin = HexCoord(tag.getInt("OriginQ"), tag.getInt("OriginR"))
|
||||
val valid = try {
|
||||
ResolvedPatternType.valueOf(tag.getString("Valid").uppercase(Locale.ROOT))
|
||||
} catch (e: IllegalArgumentException) {
|
||||
ResolvedPatternType.UNRESOLVED
|
||||
}
|
||||
val valid = ResolvedPatternType.fromString(tag.getString("Valid"))
|
||||
return ResolvedPattern(pattern, origin, valid)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
package at.petrak.hexcasting.api.spell.casting
|
||||
|
||||
import java.util.*
|
||||
|
||||
enum class ResolvedPatternType(val color: Int, val fadeColor: Int, val success: Boolean) {
|
||||
UNRESOLVED(0x7f7f7f, 0xcccccc, false),
|
||||
EVALUATED(0x7385de, 0xfecbe6, true),
|
||||
ESCAPED(0xddcc73, 0xfffae5, true),
|
||||
ERRORED(0xde6262, 0xffc7a0, false),
|
||||
INVALID(0xb26b6b, 0xcca88e, false)
|
||||
INVALID(0xb26b6b, 0xcca88e, false);
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromString(key: String): ResolvedPatternType {
|
||||
val lowercaseKey = key.lowercase(Locale.ROOT)
|
||||
return values().firstOrNull { it.name.lowercase(Locale.ROOT) == lowercaseKey } ?: UNRESOLVED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package at.petrak.hexcasting.api.spell.math
|
||||
|
||||
import java.util.*
|
||||
|
||||
enum class HexDir {
|
||||
NORTH_EAST, EAST, SOUTH_EAST, SOUTH_WEST, WEST, NORTH_WEST;
|
||||
|
||||
|
@ -22,4 +24,12 @@ enum class HexDir {
|
|||
WEST -> HexCoord(-1, 0)
|
||||
NORTH_WEST -> HexCoord(0, -1)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromString(key: String): HexDir {
|
||||
val lowercaseKey = key.lowercase(Locale.ROOT)
|
||||
return values().firstOrNull { it.name.lowercase(Locale.ROOT) == lowercaseKey } ?: WEST
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ManualPatternComponent extends AbstractPatternComponent {
|
|||
JsonElement json = ivar.unwrap();
|
||||
RawPattern raw = new Gson().fromJson(json, RawPattern.class);
|
||||
|
||||
var dir = HexDir.valueOf(raw.startdir);
|
||||
var dir = HexDir.fromString(raw.startdir);
|
||||
var pat = HexPattern.fromAngles(raw.signature, dir);
|
||||
var origin = new HexCoord(raw.q, raw.r);
|
||||
out.add(new Pair<>(pat, origin));
|
||||
|
|
Loading…
Reference in a new issue