-
Notifications
You must be signed in to change notification settings - Fork 138
Advanced parenthesis patterns (and they're Actions now) #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
19014c2
1685ca9
1f01f3c
183d613
366338d
838fff3
507033c
990cbe1
e2b7905
bedf9b1
dc4c5c6
1a43604
a450fea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package at.petrak.hexcasting.common.casting.actions.escaping | ||
|
|
||
| import at.petrak.hexcasting.api.casting.castables.Action | ||
| import at.petrak.hexcasting.api.casting.eval.CastingEnvironment | ||
| import at.petrak.hexcasting.api.casting.eval.OperationResult | ||
| import at.petrak.hexcasting.api.casting.eval.ParenthesizedOperationResult | ||
| import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType | ||
| import at.petrak.hexcasting.api.casting.eval.vm.CastingImage | ||
| import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation | ||
| import at.petrak.hexcasting.api.casting.iota.DoubleIota | ||
| import at.petrak.hexcasting.api.casting.iota.Iota | ||
| import at.petrak.hexcasting.api.casting.iota.ListIota | ||
| import at.petrak.hexcasting.api.casting.mishaps.MishapNeedsParens | ||
| import at.petrak.hexcasting.common.lib.hex.HexEvalSounds | ||
|
|
||
| object OpCloseAllParens : Action { | ||
| override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult { | ||
| throw MishapNeedsParens() | ||
| } | ||
|
|
||
| override fun operateInParens(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation, thisIota: Iota): ParenthesizedOperationResult { | ||
| val newStack = image.stack.toMutableList() | ||
| newStack.add(DoubleIota(image.parenCount.toDouble())) | ||
| newStack.add(ListIota(image.parenthesized.toList().map { it.iota })) | ||
| val image2 = image.copy( | ||
| stack = newStack, | ||
| parenCount = 0, | ||
| parenthesized = listOf() | ||
| ) | ||
| return ParenthesizedOperationResult(image2, listOf(), continuation, HexEvalSounds.NORMAL_EXECUTE, ResolvedPatternType.EVALUATED) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package at.petrak.hexcasting.common.casting.actions.escaping | ||
|
|
||
| import at.petrak.hexcasting.api.casting.castables.Action | ||
| import at.petrak.hexcasting.api.casting.eval.CastingEnvironment | ||
| import at.petrak.hexcasting.api.casting.eval.OperationResult | ||
| import at.petrak.hexcasting.api.casting.eval.vm.CastingImage | ||
| import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation | ||
| import at.petrak.hexcasting.api.casting.getPositiveInt | ||
| import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs | ||
| import at.petrak.hexcasting.common.lib.hex.HexEvalSounds | ||
|
|
||
| object OpOpenNParens : Action { | ||
| override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult { | ||
| val newStack = image.stack.toMutableList() | ||
| val layers = when (val topIota = newStack.removeLastOrNull()) { | ||
| null -> throw MishapNotEnoughArgs(1, 0) | ||
| else -> listOf(topIota).getPositiveInt(0) | ||
| } | ||
|
Robotgiggle marked this conversation as resolved.
Outdated
|
||
| val image2 = image.copy( | ||
| stack = newStack, | ||
| parenCount = layers | ||
| ) | ||
| return OperationResult(image2, listOf(), continuation, HexEvalSounds.NORMAL_EXECUTE) | ||
| } | ||
|
|
||
| // Since there's no nice way to determine how many new layers it should open when drawn inside parens, we don't | ||
| // override operateInParens() at all. This pattern is just treated as any other pattern when parenthesized. | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package at.petrak.hexcasting.common.casting.actions.escaping | ||
|
|
||
| import at.petrak.hexcasting.api.casting.castables.Action | ||
| import at.petrak.hexcasting.api.casting.eval.CastingEnvironment | ||
| import at.petrak.hexcasting.api.casting.eval.OperationResult | ||
| import at.petrak.hexcasting.api.casting.eval.ParenthesizedOperationResult | ||
| import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType | ||
| import at.petrak.hexcasting.api.casting.eval.vm.CastingImage | ||
| import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation | ||
| import at.petrak.hexcasting.api.casting.iota.Iota | ||
| import at.petrak.hexcasting.api.casting.mishaps.MishapBadOffhandItem | ||
| import at.petrak.hexcasting.api.casting.mishaps.MishapNeedsParens | ||
| import at.petrak.hexcasting.common.lib.hex.HexEvalSounds | ||
| import at.petrak.hexcasting.xplat.IXplatAbstractions | ||
|
|
||
| object OpReadIntoParens : Action { | ||
| override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult { | ||
| throw MishapNeedsParens() | ||
| } | ||
|
|
||
| override fun operateInParens(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation, thisIota: Iota): ParenthesizedOperationResult { | ||
| val (handStack) = env.getHeldItemToOperateOn { | ||
| val dataHolder = IXplatAbstractions.INSTANCE.findDataHolder(it) | ||
| dataHolder != null && (dataHolder.readIota(env.world) != null || dataHolder.emptyIota() != null) | ||
| } | ||
| // If there are no data holders that are readable, find a data holder that isn't readable | ||
| // so that the error message is more helpful. | ||
| ?: env.getHeldItemToOperateOn { | ||
| val dataHolder = IXplatAbstractions.INSTANCE.findDataHolder(it) | ||
| dataHolder != null | ||
| } ?: throw MishapBadOffhandItem.of(null, "iota.read") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this indentation is pretty weird
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is straight out of OpRead. That said, it is indeed quite weird, so I'll change it. |
||
|
|
||
| val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) | ||
| ?: throw MishapBadOffhandItem.of(handStack, "iota.read") | ||
|
|
||
| val datum = datumHolder.readIota(env.world) | ||
| ?: datumHolder.emptyIota() | ||
| ?: throw MishapBadOffhandItem.of(handStack, "iota.read") | ||
|
|
||
| return ParenthesizedOperationResult( | ||
| image.withNewParenthesized(datum), | ||
| listOf(), continuation, | ||
| HexEvalSounds.NORMAL_EXECUTE, | ||
| ResolvedPatternType.EVALUATED | ||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ object OpUndo : Action { | |
| var newParenCount = image.parenCount | ||
| if (last == null) { | ||
| // if there was nothing in the parenthesized list, undo the initial open paren | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update the comment to mention why we specifically need to set it to 0, not decrement it? Also, do we need more special handing for undoing Mediation/Recollection/Interjection? I almost wonder if we should update the new escaped-action API to add an undo handler method on actions so they don't need to be hardcoded here (and so addons can handle it too).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No additional handling is necessary as far as I'm aware:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, there was a bit of a weird interaction if you Interjected an open or close paren and then undid it, but I was able to fix that by just making Interjection set the |
||
| newParenCount-- | ||
| newParenCount = 0 | ||
| } else if (last.iota is PatternIota && !last.escaped) { | ||
| // adjust paren count if undoing a non-escaped open or close paren | ||
| when (last.iota.pattern.angles) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.