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 6b825da..a9a0518 100644 --- a/src/NCapybaraLib/_internal/Math.py +++ b/src/NCapybaraLib/_internal/Math.py @@ -38,4 +38,26 @@ 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 | float, minimum: int, maximum: int) -> int | float: + """ + 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 abbreviating shit" + # "I shall use the correct nerdy terms :nerd:" + + if value < minimum: + return minimum + + if value > maximum: + return maximum + + 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 825cb06..fe40a8c 100644 --- a/src/NCapybaraLib/_internal/init.py +++ b/src/NCapybaraLib/_internal/init.py @@ -39,4 +39,24 @@ 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 \ No newline at end of file