Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "scrap_engine"
authors = [{ name = "lxgr", email = "lxgr@protonmail.com" }]
description = "A 2D ascii game engine for the terminal"
keywords = ["game", "Ascii"]
version = "1.5.4"
version = "1.5.4-rc1"
license = { text = "GPL-3.0-only" }
readme = "README.md"
requires-python = ">=3.12"
Expand All @@ -21,6 +21,16 @@ Homepage = "https://github.com/lxgr-linux/scrap_engine"
Issues = "https://github.com/lxgr-linux/scrap_engine/issue"
Repository = "https://github.com/lxgr-linux/scrap_engine.git"

[tool.basedpyright]
reportMissingTypeStubs = false
reportUnknownMemberType = false
reportUnannotatedClassAttribute = false
deprecateTypingAliases = false
reportImplicitStringConcatenation = false
executionEnvironments = [
{ root = "src" },
]

[tool.ruff]
line-length = 88
target-version = "py312"
Expand Down
10 changes: 9 additions & 1 deletion src/scrap_engine/addable/misc/box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import override

from scrap_engine.addable.addable import Addable
from scrap_engine.addable.area import HasArea
from scrap_engine.addable.object_group import ObjectGroup
from scrap_engine.addable.state import DEFAULT_STATE
from scrap_engine.map import Map


class Box(ObjectGroup[Addable], HasArea):
Expand All @@ -16,14 +19,17 @@ def __init__(self, height: int, width: int):
self.__width: int = width

@property
@override
def height(self) -> int:
return self.__height

@property
@override
def width(self) -> int:
return self.__width

def add(self, _map, x: int, y: int):
@override
def add(self, _map: Map, x: int, y: int):
"""
Adds the box to a certain coordinate on a certain map.
"""
Expand All @@ -34,6 +40,7 @@ def add(self, _map, x: int, y: int):
obj.add(self.map, obj.rx + self.x, obj.ry + self.y)
self.added = True

@override
def add_ob(self, obj: Addable, x: int, y: int):
"""
Adds an object(group) to a certain coordinate relative to the box.
Expand All @@ -56,6 +63,7 @@ def set_ob(self, obj: Addable, x: int, y: int):
if self.added:
obj.set(obj.rx + self.x, obj.ry + self.y)

@override
def remove(self):
"""
Removes the box from the map.
Expand Down
15 changes: 8 additions & 7 deletions src/scrap_engine/addable/misc/circle.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import math
from typing import Type
from typing import Type, override

from scrap_engine.addable.state import DEFAULT_STATE, State

from ..object import Object
from ..object import ArgProto, Object
from .box import Box


Expand All @@ -18,18 +18,18 @@ def __init__(
radius: int,
state: State = DEFAULT_STATE,
ob_class: Type[Object] = Object,
ob_args=None,
ob_args: ArgProto = None,
):
super().__init__(0, 0)
if ob_args is None:
ob_args = {}
self.char = char
self.char: str = char
self.ob_class = ob_class
self.ob_args = ob_args
self.state = state
self.__gen(radius)

def __gen(self, radius):
def __gen(self, radius: int):
self.radius = radius
for i in range(-(int(radius) + 1), int(radius + 1) + 1):
for j in range(-(int(radius) + 1), int(radius + 1) + 1):
Expand All @@ -42,15 +42,16 @@ def __gen(self, radius):
j,
)

def rechar(self, char):
def rechar(self, char: str):
"""
Changes the chars the circle is filled with.
"""
self.char = char
for obj in self.obs:
obj.rechar(char)

def resize(self, radius):
@override
def resize(self, radius: int):
"""
Resizes the circle.
"""
Expand Down
16 changes: 10 additions & 6 deletions src/scrap_engine/addable/misc/frame.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional, Type
from typing import Optional, Type, override

from scrap_engine.addable.state import DEFAULT_STATE, State

from ..object import Object
from ..object import ArgProto, Object
from .box import Box
from .square import Square

Expand All @@ -28,7 +28,7 @@ def __init__(
vertical_chars: Optional[list[str]] = None,
state: State = DEFAULT_STATE,
ob_class: Type[Object] = Object,
ob_args=None,
ob_args: ArgProto = None,
):
super().__init__(height, width)
if ob_args is None:
Expand Down Expand Up @@ -83,13 +83,16 @@ def __gen_obs(self):
ob_class=Object,
ob_args=self.ob_args,
)
for i, j in zip(self.vertical_chars, range(2))
for i, _ in zip(self.vertical_chars, range(2))
]
for obj, rx, ry in zip(self.verticals, [0, self.width - 1], [1, 1]):
self.add_ob(obj, rx, ry)

def rechar(
self, corner_chars=None, horizontal_chars=None, vertical_chars=None
self,
corner_chars: Optional[list[str]] = None,
horizontal_chars: Optional[list[str]] = None,
vertical_chars: Optional[list[str]] = None,
):
"""
Rechars the frame.
Expand All @@ -108,7 +111,8 @@ def rechar(
for obj, _c in zip(self.verticals, self.vertical_chars):
obj.rechar(_c)

def resize(self, height, width):
@override
def resize(self, height: int, width: int):
"""
Changes the frames size.
"""
Expand Down
4 changes: 2 additions & 2 deletions src/scrap_engine/addable/misc/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from scrap_engine.addable.state import DEFAULT_STATE, State

from ..object import Object
from ..object import ArgProto, Object
from .box import Box

LineType = Literal["straight", "crippled"]
Expand All @@ -22,7 +22,7 @@ def __init__(
l_type: LineType = "straight",
state: State = DEFAULT_STATE,
ob_class: Type[Object] = Object,
ob_args=None,
ob_args: ArgProto = None,
):
super().__init__(0, 0)
if ob_args is None:
Expand Down
14 changes: 6 additions & 8 deletions src/scrap_engine/addable/misc/square.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from scrap_engine.addable.state import DEFAULT_STATE, State

from ..object import Object
from ..object import ArgProto, Object
from .box import Box


Expand All @@ -13,12 +13,12 @@ class Square(Box):

def __init__(
self,
char,
width,
height,
char: str,
width: int,
height: int,
state: State = DEFAULT_STATE,
ob_class: Type[Object] = Object,
ob_args=None,
ob_args: ArgProto = None,
):
super().__init__(height, width)
if ob_args is None:
Expand All @@ -34,9 +34,7 @@ def __create(self):
for ry in range(self.height):
for rx in range(self.width):
self.add_ob(
self.ob_class(
self.char, self.state, arg_proto=self.ob_args
),
self.ob_class(self.char, self.state, arg_proto=self.ob_args),
rx,
ry,
)
Expand Down
28 changes: 17 additions & 11 deletions src/scrap_engine/addable/misc/text.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
from typing import Generic, TypeVar
from typing import Any, Generic, TypeVar, override

from scrap_engine.addable.area import HasArea
from scrap_engine.addable.state import DEFAULT_STATE, State
from scrap_engine.map import Map

from ..object import Object
from ..object import ArgProto, Object
from ..object_group import ObjectGroup

T = TypeVar("T", bound=Object)


class Text(HasArea, ObjectGroup[T], Generic[T]):
class Text(ObjectGroup[T], HasArea, Generic[T]):
"""
A datatype containing a string, that can be added to a map.
Different Texts can be added together with the '+' operator.
"""

def __init__(
self,
text,
text: str,
state: State = DEFAULT_STATE,
esccode="",
esccode: str = "",
ob_class: type[T] = Object,
ob_args=None,
ignore="",
ob_args: ArgProto = None,
ignore: str = "",
):
super().__init__([], state)
if ob_args is None:
Expand All @@ -35,20 +36,22 @@ def __init__(
self.__texter(text)

@property
@override
def width(self) -> int:
"""
The Texts peak width
"""
return sorted(len(i) for i in self.text.split("\n"))[-1]

@property
@override
def height(self) -> int:
"""
The Texts height
"""
return len(self.text.split("\n"))

def __add__(self, other):
def __add__(self, other: "Text[Any]"):
self.text += other.text
self.obs += other.obs
for obj in self.obs:
Expand All @@ -58,7 +61,7 @@ def __add__(self, other):
self.add(self.map, self.x, self.y)
return self

def __texter(self, text):
def __texter(self, text: str):
for txt in text.split("\n"):
for char in txt:
if self.esccode != "":
Expand All @@ -69,7 +72,8 @@ def __texter(self, text):
for obj in self.obs:
obj.group = self

def add(self, _map, x, y):
@override
def add(self, _map: Map, x: int, y: int):
"""
Adds the text to a certain coordinate on a certain map.
"""
Expand All @@ -84,6 +88,7 @@ def add(self, _map, x, y):
obj.add(self.map, x + i, y + line)
count += len(text)

@override
def remove(self):
"""
Removes the text from the map.
Expand All @@ -92,6 +97,7 @@ def remove(self):
for obj in self.obs:
obj.remove()

@override
def rem_ob(self, obj: T):
"""
Removes an object from the group.
Expand All @@ -112,7 +118,7 @@ def rem_ob(self, obj: T):
return 0
return 1

def rechar(self, text: str, esccode=""):
def rechar(self, text: str, esccode: str = ""):
"""
Changes the string contained in the text.
"""
Expand Down
Loading
Loading