make special handlers also have resource locations

This commit is contained in:
gamma-delta 2022-04-08 16:13:29 -05:00
parent db2db1ce56
commit 3645a4eade
4 changed files with 11 additions and 12 deletions

View file

@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentMap
*/
object PatternRegistry {
private val operatorLookup = ConcurrentHashMap<ResourceLocation, Operator>()
private val specialHandlers: ConcurrentLinkedDeque<SpecialHandler> = ConcurrentLinkedDeque()
private val specialHandlers: ConcurrentLinkedDeque<SpecialHandlerEntry> = ConcurrentLinkedDeque()
// Map signatures to the "preferred" direction they start in and their operator ID.
private val regularPatternLookup: ConcurrentMap<String, RegularEntry> =
@ -60,7 +60,7 @@ object PatternRegistry {
* Add a special handler, to take an arbitrary pattern and return whatever kind of operator you like.
*/
@JvmStatic
fun addSpecialHandler(handler: SpecialHandler) {
fun addSpecialHandler(handler: SpecialHandlerEntry) {
this.specialHandlers.add(handler)
}
@ -75,13 +75,13 @@ object PatternRegistry {
* Internal use only.
*/
@JvmStatic
fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair<Operator, ResourceLocation?> {
fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair<Operator, ResourceLocation> {
// Pipeline:
// patterns are registered here every time the game boots
// when we try to look
for (handler in specialHandlers) {
val op = handler.handlePattern(pat)
if (op != null) return Pair(op, null)
val op = handler.handler.handlePattern(pat)
if (op != null) return Pair(op, handler.id)
}
// Is it global?
@ -143,6 +143,8 @@ object PatternRegistry {
fun handlePattern(pattern: HexPattern): Operator?
}
data class SpecialHandlerEntry(val id: ResourceLocation, val handler: SpecialHandler)
class RegisterPatternException(msg: String) : java.lang.Exception(msg)
private data class RegularEntry(val preferredStart: HexDir, val opId: ResourceLocation)

View file

@ -62,7 +62,7 @@ class CastingHarness private constructor(
if (this.ctx.spellCircle == null)
this.ctx.caster.awardStat(HexStatistics.PATTERNS_DRAWN)
var operatorIdPair: Pair<Operator, ResourceLocation?>? = null
var operatorIdPair: Pair<Operator, ResourceLocation>? = null
try {
// wouldn't it be nice to be able to go paren'
// i guess i'll call it paren2

View file

@ -1,6 +1,5 @@
package at.petrak.hexcasting.common.casting;
import at.petrak.hexcasting.HexMod;
import at.petrak.hexcasting.api.PatternRegistry;
import at.petrak.hexcasting.api.spell.Operator;
import at.petrak.hexcasting.api.spell.SpellDatum;
@ -37,7 +36,6 @@ public class RegisterPatterns {
// I guess this means the client will have a big empty map for patterns
@SubscribeEvent
public static void registerSpellPatterns(FMLCommonSetupEvent evt) {
int count = 0;
try {
// In general:
// - CCW is the normal or construction version
@ -365,7 +363,7 @@ public class RegisterPatterns {
}
// Add zilde->number
PatternRegistry.addSpecialHandler(pat -> {
PatternRegistry.addSpecialHandler(new PatternRegistry.SpecialHandlerEntry(prefix("number"), pat -> {
var sig = pat.anglesSignature();
if (sig.startsWith("aqaa") || sig.startsWith("dedd")) {
var negate = sig.startsWith("dedd");
@ -390,8 +388,6 @@ public class RegisterPatterns {
} else {
return null;
}
});
HexMod.getLogger().info("Registered {} patterns", count);
}));
}
}

View file

@ -251,6 +251,7 @@
"hexcasting.spell.hexcasting:const/vec/ny": "Vector Reflection -Y",
"hexcasting.spell.hexcasting:const/vec/nz": "Vector Reflection -Z",
"hexcasting.spell.hexcasting:const/vec/0": "Vector Reflection Zero",
"hexcasting.spell.hexcasting:number": "Numerical Reflection",
"hexcasting.spell.unknown": "Special Handler",
"hexcasting.mishap.invalid_pattern": "That pattern isn't associated with any action",