Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
norbcodes authored Sep 22, 2024
2 parents 207019f + 71a1c53 commit 0c1be4f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions src/NCapybaraLib/All.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down
3 changes: 2 additions & 1 deletion src/NCapybaraLib/Math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from ._internal.Math import tetration
from ._internal.Math import clamp
3 changes: 2 additions & 1 deletion src/NCapybaraLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

from ._internal.init import print_hello_world
from ._internal.init import inject_function
from ._internal.init import clear_console
from ._internal.init import clear_console
from ._internal.init import nullish_operator
24 changes: 23 additions & 1 deletion src/NCapybaraLib/_internal/Math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
22 changes: 21 additions & 1 deletion src/NCapybaraLib/_internal/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,24 @@ def clear_console() -> None:
if sys.platform.casefold() == "win32":
os.system("cls")
else:
os.system("clear")
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

0 comments on commit 0c1be4f

Please sign in to comment.