From baceb7415b2c4d3912c35b5fb2d5059d45987e87 Mon Sep 17 00:00:00 2001 From: MF366 <109810178+MF366-Coding@users.noreply.github.com> Date: Sat, 21 Sep 2024 19:23:08 +0100 Subject: [PATCH 1/4] Update Math.py --- src/NCapybaraLib/_internal/Math.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/NCapybaraLib/_internal/Math.py b/src/NCapybaraLib/_internal/Math.py index 6b825da..a6f86d5 100644 --- a/src/NCapybaraLib/_internal/Math.py +++ b/src/NCapybaraLib/_internal/Math.py @@ -38,4 +38,27 @@ def tetration(base: int, exponent: int) -> int: :return: The result. """ return base**(base**exponent) # type: ignore[no-any-return] - # Yeah what the fuck mypy \ No newline at end of file + # Yeah what the fuck mypy + +def clamp(value: int, minimum: int, maximum: int): + """ + clamp + + :param value: The value to clamp, duh?! + :param minimum: If value is below this number, return the later + :param maximum: If value is above this number, return the later + + and yeah that's literally all + """ + + # mf366 here saying "fuck abreviating shit" + # "I shall use the correct nerdy terms :nerd:" + + if value < minimum: + return minimum + + if value > maximum: + return maximum + + return value + From 9e64cd363093db0326df8cc781e7b740723dd204 Mon Sep 17 00:00:00 2001 From: MF366 <109810178+MF366-Coding@users.noreply.github.com> Date: Sat, 21 Sep 2024 19:26:54 +0100 Subject: [PATCH 2/4] Update init.py --- src/NCapybaraLib/_internal/init.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/NCapybaraLib/_internal/init.py b/src/NCapybaraLib/_internal/init.py index 825cb06..48e21d6 100644 --- a/src/NCapybaraLib/_internal/init.py +++ b/src/NCapybaraLib/_internal/init.py @@ -39,4 +39,25 @@ def clear_console() -> None: if sys.platform.casefold() == "win32": os.system("cls") else: - os.system("clear") \ No newline at end of file + os.system("clear") + +def nullish_operator(value: Any, new_value: Any) -> Any: + """ + nullish_operator + + Recreation of the GameMaker Studio 2's nullish operator (??) and self nullish operator (=??). + + For more information on how the operator is used in GMS2 visit: https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Overview/Expressions_And_Operators.htm?rhhlterm=nullish# + + :param value: The value to return if itself is not None + :param new_value: The value to return if value is None + + Example usage of the recreation in Python: + ``` + username = nullish_operator(data.username, "INVALID USERNAME") + ``` + """ + + # yet another contribution from y'allsss buddy MF366 + return new_value if value is None else value + From b08b4510212acfe8a4a030091bb8812ad502c5d5 Mon Sep 17 00:00:00 2001 From: MF366 <109810178+MF366-Coding@users.noreply.github.com> Date: Sat, 21 Sep 2024 19:27:33 +0100 Subject: [PATCH 3/4] Update Math.py --- src/NCapybaraLib/_internal/Math.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NCapybaraLib/_internal/Math.py b/src/NCapybaraLib/_internal/Math.py index a6f86d5..f93e39a 100644 --- a/src/NCapybaraLib/_internal/Math.py +++ b/src/NCapybaraLib/_internal/Math.py @@ -40,7 +40,7 @@ def tetration(base: int, exponent: int) -> int: return base**(base**exponent) # type: ignore[no-any-return] # Yeah what the fuck mypy -def clamp(value: int, minimum: int, maximum: int): +def clamp(value: int | float, minimum: int, maximum: int) -> int | float: """ clamp From 71a1c53f3905d04be8b69544fb028a47391821e7 Mon Sep 17 00:00:00 2001 From: norbcodes Date: Sun, 22 Sep 2024 10:46:33 +0200 Subject: [PATCH 4/4] v1.1.0 --- pyproject.toml | 2 +- src/NCapybaraLib/All.py | 1 + src/NCapybaraLib/Math.py | 3 ++- src/NCapybaraLib/__init__.py | 3 ++- src/NCapybaraLib/_internal/Math.py | 5 ++--- src/NCapybaraLib/_internal/init.py | 3 +-- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ce0797a..7cb6b86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" name = "NCapybaraLib" description = "A small library with a bunch of functions and thingies I made for fun." authors = [{name="NorbCodes"}] -version = "1.0.0" +version = "1.1.0" readme = "README.md" requires-python = ">=3.12" classifiers = [ diff --git a/src/NCapybaraLib/All.py b/src/NCapybaraLib/All.py index e9397ae..d14c9c5 100644 --- a/src/NCapybaraLib/All.py +++ b/src/NCapybaraLib/All.py @@ -9,6 +9,7 @@ from ._internal.init import print_hello_world from ._internal.init import inject_function from ._internal.init import clear_console +from ._internal.init import nullish_operator from .String import * diff --git a/src/NCapybaraLib/Math.py b/src/NCapybaraLib/Math.py index 71539d0..c5eaee7 100644 --- a/src/NCapybaraLib/Math.py +++ b/src/NCapybaraLib/Math.py @@ -8,4 +8,5 @@ from ._internal.Math import get_xy_in_2d_array from ._internal.Math import get_index_in_2d_array -from ._internal.Math import tetration \ No newline at end of file +from ._internal.Math import tetration +from ._internal.Math import clamp \ No newline at end of file diff --git a/src/NCapybaraLib/__init__.py b/src/NCapybaraLib/__init__.py index bc76bdc..ded4155 100644 --- a/src/NCapybaraLib/__init__.py +++ b/src/NCapybaraLib/__init__.py @@ -8,4 +8,5 @@ from ._internal.init import print_hello_world from ._internal.init import inject_function -from ._internal.init import clear_console \ No newline at end of file +from ._internal.init import clear_console +from ._internal.init import nullish_operator \ No newline at end of file diff --git a/src/NCapybaraLib/_internal/Math.py b/src/NCapybaraLib/_internal/Math.py index f93e39a..a9a0518 100644 --- a/src/NCapybaraLib/_internal/Math.py +++ b/src/NCapybaraLib/_internal/Math.py @@ -51,7 +51,7 @@ def clamp(value: int | float, minimum: int, maximum: int) -> int | float: and yeah that's literally all """ - # mf366 here saying "fuck abreviating shit" + # mf366 here saying "fuck abbreviating shit" # "I shall use the correct nerdy terms :nerd:" if value < minimum: @@ -60,5 +60,4 @@ def clamp(value: int | float, minimum: int, maximum: int) -> int | float: if value > maximum: return maximum - return value - + return value # Simply genius code. <3 \ No newline at end of file diff --git a/src/NCapybaraLib/_internal/init.py b/src/NCapybaraLib/_internal/init.py index 48e21d6..fe40a8c 100644 --- a/src/NCapybaraLib/_internal/init.py +++ b/src/NCapybaraLib/_internal/init.py @@ -59,5 +59,4 @@ def nullish_operator(value: Any, new_value: Any) -> Any: """ # yet another contribution from y'allsss buddy MF366 - return new_value if value is None else value - + return new_value if value is None else value \ No newline at end of file