Skip to content

Commit

Permalink
Merge pull request #24 from xcoder-tool/linting-fixes
Browse files Browse the repository at this point in the history
fix: config importing, linting errors
  • Loading branch information
danila-schelkov authored Aug 20, 2024
2 parents ced7155 + ff3f2d7 commit 1a8b1b7
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install requirements
run: |
Expand Down
6 changes: 3 additions & 3 deletions system/lib/features/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@


def write_sc(
output_filename: str | os.PathLike,
output_filename: os.PathLike | str,
buffer: bytes,
signature: Signatures,
version: int | None = None,
):
with open(output_filename, "wb") as file_out:
file_out.write(compress(buffer, signature, version))
file_out.write(compress(buffer, signature, version)) # type: ignore


def open_sc(input_filename: str) -> tuple[bytes, Signatures]:
def open_sc(input_filename: os.PathLike | str) -> tuple[bytes, Signatures]:
with open(input_filename, "rb") as f:
file_data = f.read()

Expand Down
2 changes: 1 addition & 1 deletion system/lib/features/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from loguru import logger

from system import clear, run
from system.lib import config
from system.lib.config import config
from system.lib.features.directories import create_directories
from system.lib.features.update.check import get_pip_info, get_tags
from system.localization import locale
Expand Down
9 changes: 5 additions & 4 deletions system/lib/features/sc/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def decode_textures_only():
)

_save_meta_file(
swf, objects_output_folder, base_name.rstrip("_"), signature
swf, objects_output_folder, base_name.rsplit("_", 1)[0], signature
)
_save_textures(swf, objects_output_folder, base_name)
except Exception as exception:
Expand Down Expand Up @@ -96,6 +96,7 @@ def decode_and_render_objects():


def get_file_basename(swf: SupercellSWF):
assert swf.filename is not None
return os.path.basename(swf.filename).rsplit(".", 1)[0]


Expand All @@ -109,9 +110,9 @@ def _create_objects_output_folder(output_folder: Path, base_name: str) -> Path:

def _save_textures(swf: SupercellSWF, textures_output: Path, base_name: str) -> None:
os.makedirs(textures_output, exist_ok=True)
for img_index in range(len(swf.textures)):
filename = base_name + "_" * img_index
swf.textures[img_index].image.save(textures_output / f"{filename}.png")
for texture_index, texture in enumerate(swf.textures):
assert texture.image is not None
texture.image.save(textures_output / f"{base_name}_{texture_index}.png")


def _save_meta_file(
Expand Down
2 changes: 1 addition & 1 deletion system/lib/features/update/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from loguru import logger

from system import run
from system.lib import config
from system.lib.config import config
from system.lib.features.update.download import download_update
from system.localization import locale

Expand Down
2 changes: 1 addition & 1 deletion system/lib/features/update/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from loguru import logger

from system import run
from system.lib import config
from system.lib.config import config
from system.localization import locale


Expand Down
4 changes: 2 additions & 2 deletions system/lib/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def add_pixel(pixel: tuple) -> None:
if pixel_x >= width:
break

add_pixel(loaded_clone[pixel_x, pixel_y])
add_pixel(loaded_clone[pixel_x, pixel_y]) # type: ignore
pixel_index += 1

Console.progress_bar(locale.split_pic, y_chunk, y_chunks_count + 1)
Expand Down Expand Up @@ -149,7 +149,7 @@ def save_texture(writer: Writer, image: Image.Image, pixel_type: int) -> None:
point = -1
for y in range(height):
for x in range(width):
writer.write(write_pixel(pixels[y * width + x]))
writer.write(write_pixel(pixels[y * width + x])) # type: ignore

curr = Console.percent(y, height)
if curr > point:
Expand Down
2 changes: 1 addition & 1 deletion system/lib/math/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PointOrder(IntEnum):
COUNTER_CLOCKWISE = 1


def get_polygon_sum_of_edges(polygon: Polygon) -> int:
def get_polygon_sum_of_edges(polygon: Polygon) -> float:
"""
Mostly like signed area, but two times bigger and more accurate with signs.
Expand Down
2 changes: 2 additions & 0 deletions system/lib/objects/movie_clip/movie_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self):
self.matrix_bank_index: int = 0

def load(self, swf: SupercellSWF, tag: int):
assert swf.reader is not None

self.id = swf.reader.read_ushort()

self.fps = swf.reader.read_char()
Expand Down
2 changes: 2 additions & 0 deletions system/lib/objects/renderable/renderable_movie_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def calculate_bounds(self, matrix: Matrix2x3) -> Rect:
return rect

def set_frame(self, frame_index: int):
assert self._matrix_bank is not None

self._frame_children = []

frame = self._frames[frame_index]
Expand Down
4 changes: 4 additions & 0 deletions system/lib/objects/shape/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self):
self._cache_image: Image.Image | None = None

def load(self, swf: SupercellSWF, tag: int):
assert swf.reader is not None

self.texture_index = swf.reader.read_uchar()

self._texture = swf.textures[self.texture_index]
Expand Down Expand Up @@ -83,6 +85,8 @@ def get_image(self) -> Image.Image:
if self._cache_image is not None:
return self._cache_image

assert self._texture is not None and self._texture.image is not None

rect = get_rect(self._uv_points)

width = max(int(rect.width), 1)
Expand Down
2 changes: 2 additions & 0 deletions system/lib/objects/shape/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(self):
self.regions: list[Region] = []

def load(self, swf: SupercellSWF, tag: int):
assert swf.reader is not None

self.id = swf.reader.read_ushort()

swf.reader.read_ushort() # regions_count
Expand Down
12 changes: 7 additions & 5 deletions system/lib/objects/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ def __init__(self):
self.height = 0

self.pixel_type = -1
self.khronos_texture_filename: str | None = None

self.image: Image.Image | None = None

def load(self, swf: SupercellSWF, tag: int, has_texture: bool):
assert swf.reader is not None

khronos_texture_length = 0
khronos_texture_filename = None
if tag == 45:
khronos_texture_length = swf.reader.read_int()
elif tag == 47:
self.khronos_texture_filename = swf.reader.read_string()
khronos_texture_filename = swf.reader.read_string()

self.pixel_type = swf.reader.read_char()
self.width, self.height = (swf.reader.read_ushort(), swf.reader.read_ushort())
Expand All @@ -45,9 +48,8 @@ def load(self, swf: SupercellSWF, tag: int, has_texture: bool):
# noinspection PyUnboundLocalVariable
khronos_texture_data = swf.reader.read(khronos_texture_length)
elif tag == 47:
with open(
swf.filepath.parent / self.khronos_texture_filename, "rb"
) as file:
assert khronos_texture_filename is not None
with open(swf.filepath.parent / khronos_texture_filename, "rb") as file:
decompressor = zstandard.ZstdDecompressor()
khronos_texture_data = decompressor.decompress(file.read())

Expand Down
9 changes: 7 additions & 2 deletions system/lib/swf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):
self.xcod_writer = Writer("big")

self._filepath: Path | None = None
self._uncommon_texture_path: str | os.PathLike | None = None
self._uncommon_texture_path: os.PathLike | str | None = None

self._lowres_suffix: str = DEFAULT_LOWRES_SUFFIX
self._highres_suffix: str = DEFAULT_HIGHRES_SUFFIX
Expand Down Expand Up @@ -63,6 +63,7 @@ def load(self, filepath: str | os.PathLike) -> tuple[bool, Signatures]:

if not texture_loaded:
if self._use_uncommon_texture:
assert self._uncommon_texture_path is not None
texture_loaded, signature = self._load_internal(
self._uncommon_texture_path, True
)
Expand All @@ -73,7 +74,7 @@ def load(self, filepath: str | os.PathLike) -> tuple[bool, Signatures]:
return texture_loaded, signature

def _load_internal(
self, filepath: str | os.PathLike, is_texture_file: bool
self, filepath: os.PathLike | str, is_texture_file: bool
) -> tuple[bool, Signatures]:
self.filename = os.path.basename(filepath)

Expand Down Expand Up @@ -136,6 +137,8 @@ def _load_internal(
return loaded, signature

def _load_tags(self, is_texture_file: bool) -> bool:
assert self.reader is not None

has_texture = True

texture_id = 0
Expand Down Expand Up @@ -183,6 +186,7 @@ def _load_tags(self, is_texture_file: bool) -> bool:
self.movie_clips[movie_clips_loaded].load(self, tag)
movie_clips_loaded += 1
elif tag == 8 or tag == 36: # Matrix
assert self._matrix_bank is not None
self._matrix_bank.get_matrix(matrices_loaded).load(self.reader, tag)
matrices_loaded += 1
elif tag == 26:
Expand Down Expand Up @@ -244,4 +248,5 @@ def get_matrix_bank(self, index: int) -> MatrixBank:

@property
def filepath(self) -> Path:
assert self._filepath is not None
return self._filepath

0 comments on commit 1a8b1b7

Please sign in to comment.