From a3b62c4ab8a653217ac5f1ea0607e7aa23e0f8b5 Mon Sep 17 00:00:00 2001 From: "petrak@" Date: Sun, 26 Feb 2023 14:47:21 -0600 Subject: [PATCH] close the first half of #417 --- .../operators/math/logic/OpBoolToNumber.kt | 16 +++++++++++++ .../hexcasting/common/lib/hex/HexActions.java | 2 ++ .../assets/hexcasting/lang/en_us.json | 4 ++++ .../en_us/entries/patterns/logic.json | 24 ++++++++++++------- 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 Common/src/main/java/at/petrak/hexcasting/common/casting/operators/math/logic/OpBoolToNumber.kt diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/math/logic/OpBoolToNumber.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/math/logic/OpBoolToNumber.kt new file mode 100644 index 00000000..6d9ff987 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/math/logic/OpBoolToNumber.kt @@ -0,0 +1,16 @@ +package at.petrak.hexcasting.common.casting.operators.math.logic + +import at.petrak.hexcasting.api.casting.asActionResult +import at.petrak.hexcasting.api.casting.castables.ConstMediaAction +import at.petrak.hexcasting.api.casting.eval.CastingEnvironment +import at.petrak.hexcasting.api.casting.getBool +import at.petrak.hexcasting.api.casting.iota.Iota + +object OpBoolToNumber : ConstMediaAction { + override val argc = 1 + + override fun execute(args: List, ctx: CastingEnvironment): List { + val arg = args.getBool(0, argc) + return (if (arg) 1.0 else 0.0).asActionResult + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexActions.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexActions.java index 977c3bc8..877a0a27 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexActions.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexActions.java @@ -191,6 +191,8 @@ public class HexActions { new ActionRegistryEntry(HexPattern.fromAngles("dw", HexDir.NORTH_WEST), OpBoolNot.INSTANCE)); public static final ActionRegistryEntry BOOL_COERCE = make("bool_coerce", new ActionRegistryEntry(HexPattern.fromAngles("aw", HexDir.NORTH_EAST), OpCoerceToBool.INSTANCE)); + public static final ActionRegistryEntry BOOL_TO_NUMBER = make("bool_to_number", + new ActionRegistryEntry(HexPattern.fromAngles("awd", HexDir.SOUTH_EAST), OpBoolToNumber.INSTANCE)); public static final ActionRegistryEntry IF = make("if", new ActionRegistryEntry(HexPattern.fromAngles("awdd", HexDir.SOUTH_EAST), OpBoolIf.INSTANCE)); 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 3eca1657..a8303912 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.json @@ -332,6 +332,7 @@ "hexcasting.action.book.hexcasting:const/vec/y": "Vector Rfln. +Y/-Y", "hexcasting.action.book.hexcasting:const/vec/z": "Vector Rfln. +Z/-Z", "hexcasting.action.book.hexcasting:read/entity": "Chronicler's Prfn.", + "hexcasting.action.book.hexcasting:bool_to_number": "Numerologist's Prfn.", "hexcasting.action.book.hexcasting:number": "Numerical Reflection", "hexcasting.action.book.hexcasting:mask": "Bookkeeper's Gambit", @@ -427,6 +428,7 @@ "hexcasting.action.hexcasting:not_equals": "Inequality Distillation", "hexcasting.action.hexcasting:not": "Negation Purification", "hexcasting.action.hexcasting:bool_coerce": "Augur's Purification", + "hexcasting.action.hexcasting:bool_to_number": "Numerologist's Purification", "hexcasting.action.hexcasting:if": "Augur's Exaltation", "hexcasting.action.hexcasting:add": "Additive Distillation", @@ -557,6 +559,7 @@ "hexcasting.mishap.invalid_value.int.positive.less.equal": "a positive integer less than or equal to %d", "hexcasting.mishap.invalid_value.int.between": "an integer between %d and %d", "hexcasting.mishap.invalid_value.evaluatable": "something evaluatable", + "hexcasting.mishap.invalid_value.bool_commute": "a boolean, 0, or 1", "hexcasting.mishap.not_enough_args": "expected %s or more arguments but the stack was only %s tall", "hexcasting.mishap.no_args": "expected %s or more arguments but the stack was empty", "hexcasting.mishap.too_many_close_parens": "Did not first use Introspection", @@ -1002,6 +1005,7 @@ "hexcasting.entry.logic": "Logical Operators", "hexcasting.page.logic.bool_coerce": "Convert an argument to a boolean. The number $(thing)0/$, $(l:influences#null)$(thing)Null/$, and the empty list become False; everything else becomes True.", + "hexcasting.page.logic.bool_to_number": "Convert a boolean to a number; True becomes $(thing)1/$, and False becomes $(thing)0/$.", "hexcasting.page.logic.not": "If the argument is True, return False; if it is False, return True.", "hexcasting.page.logic.or": "Returns True if at least one of the arguments are True; otherwise returns False.", "hexcasting.page.logic.and": "Returns True if both arguments are true; otherwise returns False.", diff --git a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/logic.json b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/logic.json index c48dbf14..5a26c280 100644 --- a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/logic.json +++ b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/logic.json @@ -6,14 +6,6 @@ "advancement": "hexcasting:root", "read_by_default": true, "pages": [ - { - "type": "hexcasting:pattern", - "op_id": "hexcasting:not", - "anchor": "hexcasting:not", - "input": "any", - "output": "number", - "text": "hexcasting.page.logic.not" - }, { "type": "hexcasting:pattern", "op_id": "hexcasting:bool_coerce", @@ -22,6 +14,22 @@ "output": "bool", "text": "hexcasting.page.logic.bool_coerce" }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:bool_to_number", + "anchor": "hexcasting:bool_to_number", + "input": "bool", + "output": "number", + "text": "hexcasting.page.logic.bool_to_number" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:not", + "anchor": "hexcasting:not", + "input": "any", + "output": "number", + "text": "hexcasting.page.logic.not" + }, { "type": "hexcasting:pattern", "op_id": "hexcasting:or",