Skip to content
Open
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.5"
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
9 changes: 5 additions & 4 deletions src/scrap_engine/addable/addable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from abc import abstractmethod
from typing import Optional, Protocol

from ..map.map import Map
from scrap_engine.interfaces import IMap

from .state import DEFAULT_STATE, State


Expand All @@ -17,7 +18,7 @@ class Addable(Protocol):
added: bool
group: Optional["Addable"]
state: State
map: Optional[Map]
map: Optional[IMap]

def __init__(self, state: State = DEFAULT_STATE):
self.x: int = -1
Expand All @@ -28,13 +29,13 @@ def __init__(self, state: State = DEFAULT_STATE):
self.added: bool = False
self.group: Optional[Addable] = None
self.state: State = state
self.map: Optional[Map] = None
self.map: Optional[IMap] = None

def set_state(self, state: State):
self.state = state

@abstractmethod
def add(self, _map: Map, x: int, y: int): ...
def add(self, _map: IMap, x: int, y: int): ...

@abstractmethod
def remove(self): ...
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.interfaces import IMap


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: IMap, 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
10 changes: 5 additions & 5 deletions src/scrap_engine/addable/misc/circle.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


Expand All @@ -18,7 +18,7 @@ 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:
Expand All @@ -29,7 +29,7 @@ def __init__(
self.state = state
self.__gen(radius)

def __gen(self, radius):
def __gen(self, radius: float):
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,15 @@ 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):
def resize(self, radius: float):
"""
Resizes the circle.
"""
Expand Down
8 changes: 3 additions & 5 deletions src/scrap_engine/addable/misc/frame.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
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 @@ -88,9 +88,7 @@ def __gen_obs(self):
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
):
def rechar(self, corner_chars=None, horizontal_chars=None, vertical_chars=None):
"""
Rechars the frame.
"""
Expand Down
10 changes: 5 additions & 5 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,15 +22,15 @@ 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:
ob_args = {}
self.char = char
self.char: str = char
self.ob_class = ob_class
self.ob_args = ob_args
self.state = state
self.state: State = state
self.type: LineType = l_type
self.__gen(cx, cy)

Expand Down Expand Up @@ -70,7 +70,7 @@ def __gen(self, cx: int, cy: int):
j,
)

def rechar(self, char):
def rechar(self, char: str):
"""
Changes the chars the line is made from.
"""
Expand Down
21 changes: 9 additions & 12 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,18 +13,17 @@ 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:
ob_args = {}
if state is not None:
self.state = state
self.state = state
self.ob_class = ob_class
self.char = char
self.ob_args = ob_args
Expand All @@ -34,22 +33,20 @@ 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,
)

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

def resize(self, width, height):
def resize(self, width: int, height: int):
"""
Resizes the rectangle to a certain size.
"""
Expand Down
4 changes: 2 additions & 2 deletions src/scrap_engine/addable/misc/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from scrap_engine.addable.area import HasArea
from scrap_engine.addable.state import DEFAULT_STATE, State

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

T = TypeVar("T", bound=Object)
Expand All @@ -21,7 +21,7 @@ def __init__(
state: State = DEFAULT_STATE,
esccode="",
ob_class: type[T] = Object,
ob_args=None,
ob_args: ArgProto = None,
ignore="",
):
super().__init__([], state)
Expand Down
Loading
Loading