From 6d4434fed6893c2b1dd47ad7adc4addcb7f60403 Mon Sep 17 00:00:00 2001 From: Alwinfy <20421383+Alwinfy@users.noreply.github.com> Date: Sun, 8 May 2022 15:57:22 -0400 Subject: [PATCH] Add O(1) cons/uncons --- .../common/casting/RegisterPatterns.java | 4 ++++ .../common/casting/operators/lists/OpCons.kt | 17 ++++++++++++++++ .../casting/operators/lists/OpUnCons.kt | 20 +++++++++++++++++++ .../assets/hexcasting/lang/en_us.json | 4 ++++ .../en_us/entries/patterns/lists.json | 16 +++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpCons.kt create mode 100644 Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpUnCons.kt diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java index d05e5d6a..87c1dcbd 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java @@ -450,6 +450,10 @@ public class RegisterPatterns { OpSlice.INSTANCE); PatternRegistry.mapPattern(HexPattern.FromAnglesSig("wqaeaqw", HexDir.NORTH_WEST), modLoc("modify_in_place"), OpModifyInPlace.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("ddewedd", HexDir.SOUTH_EAST), modLoc("construct"), + OpCons.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("aaqwqaa", HexDir.SOUTH_WEST), modLoc("deconstruct"), + OpUnCons.INSTANCE); } catch (PatternRegistry.RegisterPatternException exn) { exn.printStackTrace(); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpCons.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpCons.kt new file mode 100644 index 00000000..8a47175c --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpCons.kt @@ -0,0 +1,17 @@ +package at.petrak.hexcasting.common.casting.operators.lists + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.api.spell.SpellList +import at.petrak.hexcasting.api.spell.casting.CastingContext + +object OpCons : ConstManaOperator { + override val argc = 2 + override fun execute(args: List>, ctx: CastingContext): List> { + val bottom = args.getChecked(0) + val top = args[1] + return spellListOf(SpellList.LPair(top, bottom)) + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpUnCons.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpUnCons.kt new file mode 100644 index 00000000..63c4bbad --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpUnCons.kt @@ -0,0 +1,20 @@ +package at.petrak.hexcasting.common.casting.operators.lists + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.api.spell.SpellList +import at.petrak.hexcasting.api.spell.Widget +import at.petrak.hexcasting.api.spell.casting.CastingContext + +object OpUnCons : ConstManaOperator { + override val argc = 1 + override fun execute(args: List>, ctx: CastingContext): List> { + val list = args.getChecked(0) + if (list.nonEmpty) { + return spellListOf(list.cdr, list.car) + } + return spellListOf(list, Widget.NULL) + } +} diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.json b/Common/src/main/resources/assets/hexcasting/lang/en_us.json index a3598c12..a198ac19 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.json @@ -200,6 +200,8 @@ "hexcasting.spell.hexcasting:list_remove": "Excisor's Distillation", "hexcasting.spell.hexcasting:slice": "Selection Exaltation", "hexcasting.spell.hexcasting:modify_in_place": "Surgeon's Exaltation", + "hexcasting.spell.hexcasting:construct": "Speaker's Distillation", + "hexcasting.spell.hexcasting:deconstruct": "Speaker's Decomposition", "hexcasting.spell.hexcasting:get_entity": "Entity Purification", "hexcasting.spell.hexcasting:get_entity/animal": "Entity Prfn.: Animal", "hexcasting.spell.hexcasting:get_entity/monster": "Entity Prfn.: Monster", @@ -808,6 +810,8 @@ "hexcasting.page.lists.index_of": "Remove the iota at the top of the stack, then replace the list at the top with the first index of that iota within the list (starting from 0). Replaces the list with -1 if the iota doesn't exist in the list.", "hexcasting.page.lists.list_remove": "Remove the number at the top of the stack, then remove the nth element of the list at the top of the stack (where n is the number you removed).", "hexcasting.page.lists.modify_in_place": "Remove the top iota of the stack and the number at the top, then set the nth element of the list at the top of the stack to that iota (where n is the number you removed). Does nothing if the number is out of bounds.", + "hexcasting.page.lists.construct": "Remove the top iota, then add it as the first element to the list at the top of the stack.", + "hexcasting.page.lists.deconstruct": "Remove the first iota from the list at the top of the stack, then push that iota to the stack.", "hexcasting.entry.patterns_as_iotas": "Patterns as Iotas", "hexcasting.page.patterns_as_iotas.1": "One of the many peculiarities of this art is that $(italic)patterns themselves/$ can act as iotas-- I can even put them onto my stack when casting.$(br2)This raises a fairly obvious question: how do I express them? If I simply drew a pattern, it would hardly tell Nature to add it to my stack-- rather, it would simply be matched to an action.", diff --git a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/lists.json b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/lists.json index b61edaf1..4a7ae9f3 100644 --- a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/lists.json +++ b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/lists.json @@ -93,6 +93,22 @@ "input": "list, num, any", "output": "list", "text": "hexcasting.page.lists.modify_in_place" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:construct", + "anchor": "hexcasting:construct", + "input": "list, any", + "output": "list", + "text": "hexcasting.page.lists.construct" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:deconstruct", + "anchor": "hexcasting:deconstruct", + "input": "list", + "output": "list, any", + "text": "hexcasting.page.lists.deconstruct" } ] }