Skip to content
Merged
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
35 changes: 17 additions & 18 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ jobs:
runs-on: ubuntu-latest

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

- name: Install requirements
run: |
pip install pipx
pipx install cookiecutter
pipx runpip cookiecutter install -r requirements.txt
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Linting code by flake8
run: |
pipx run flake8 --show-source --statistics

- name: Check types by pyright
run: |
pipx run pyright
- name: Install requirements
run: |
pip install flake8 pyright
pip install -r requirements.txt

- name: Linting code by flake8
run: |
flake8 --show-source --statistics

- name: Check types by pyright
run: |
pyright
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ repos:
hooks:
- id: black
language_version: python3.10
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.261'
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
16 changes: 7 additions & 9 deletions system/bytestream.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import io
from typing import Literal, Optional, Union
from typing import Literal, Optional


class Reader(io.BytesIO):
def __init__(
self,
buffer: bytes = b"",
endian: Union[Literal["little"], Literal["big"]] = "little",
initial_buffer: bytes = b"",
endian: Literal["little", "big"] = "little",
):
super().__init__(buffer)

self.buffer = buffer
self.endian = endian
super().__init__(initial_buffer)
self.endian: Literal["little", "big"] = endian

def read_integer(self, length: int, signed=False) -> int:
return int.from_bytes(self.read(length), self.endian, signed=signed)
Expand Down Expand Up @@ -47,10 +45,10 @@ def read_string(self) -> str:
class Writer(io.BytesIO):
def __init__(self, endian: Literal["little", "big"] = "little"):
super().__init__()
self.endian = endian
self._endian: Literal["little", "big"] = endian

def write_int(self, integer: int, length: int = 1, signed: bool = False):
self.write(integer.to_bytes(length, self.endian, signed=signed))
self.write(integer.to_bytes(length, self._endian, signed=signed))

def write_ubyte(self, integer: int):
self.write_int(integer)
Expand Down
9 changes: 4 additions & 5 deletions system/languages/en-EU.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
"clean_dirs_description": "Clear In and Out dirs",

"not_latest": "Not the latest version installed",
"collecting_inf": "Collecting information...",
"collecting_inf": "File: %s. Collecting information...",
"about_sc": "About texture. Filename: %s (%d), Pixel type: %d, Size: %sx%s",
"decompression_error": "Error while decompressing! Trying to decode as is...",
"skip_not_installed": "%s isn't installed! Reinitialize",
"detected_comp": "Detected %s compression!",
"unk_type": "Unknown pixel type: %s",
"detected_comp": "%s compression detected",
"unknown_pixel_type": "Unknown pixel type: %s",
"crt_pic": "Creating picture...",
"join_pic": "Joining picture...",
"png_save": "Saving to png...",
Expand All @@ -73,7 +73,6 @@
"cut_sprites_process": "Cutting sprites... (%d/%d)",
"place_sprites_process": "Placing sprites... (%d/%d)",
"not_implemented": "This feature will be added in future updates.\nYou can follow XCoder updates here: github.com/Vorono4ka/XCoder",
"dec_sc": "Decoding .sc file...",
"error": "ERROR! (%s.%s: %s)",
"e1sc1": "Overwrite SC sprites",
"cgl": "Changelog:\n%s",
Expand All @@ -88,4 +87,4 @@
"disabled": "Disabled",

"install_to_unlock": "Install '%s' to unlock more functions!"
}
}
9 changes: 4 additions & 5 deletions system/languages/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
"clean_dirs_description": "Очистить In и Out папки",

"not_latest": "Установлена не последняя версия",
"collecting_inf": "Сбор информации...",
"collecting_inf": "Файл: %s. Сбор информации...",
"about_sc": "О текстуре. Файл: %s (%d), Тип пикселя: %d, Размеры: %dx%d",
"decompression_error": "Ошибка распаковки! Проведите повторную инициализацию!",
"skip_not_installed": "%s не установлен! Пропускаем...",
"detected_comp": "Обнаружено %s сжатие!",
"unk_type": "Неизвестный подтип: %s",
"detected_comp": "Обнаружено сжатие: %s",
"unknown_pixel_type": "Неизвестный подтип: %s",
"crt_pic": "Создаём картинку...",
"join_pic": "Соединяем картинку...",
"png_save": "Сохраняем в png...",
Expand All @@ -73,7 +73,6 @@
"cut_sprites_process": "Вырезаем спрайты... (%d/%d)",
"place_sprites_process": "Ставим спрайты на место... (%d/%d)",
"not_implemented": "Данная возможность будет добавлена в будущих обновлениях.\nЗа обновлениями XCoder вы можете следить здесь: github.com/Vorono4ka/XCoder",
"dec_sc": "Декодируем SC...",
"error": "ОШИБКА! (%s.%s: %s)",
"e1sc1": "Перезапись спрайтов",
"cgl": "Список изменений: \n%s",
Expand All @@ -88,4 +87,4 @@
"disabled": "Выключено",

"install_to_unlock": "Установите '%s' чтобы открыть больше функций!"
}
}
9 changes: 4 additions & 5 deletions system/languages/ua-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
"clean_dirs_description": "Очистити папки і файли в них",

"not_latest": "Встановлена не остання версія",
"collecting_inf": "Збираємо інформацію...",
"collecting_inf": "Файл: %s. Збираємо інформацію...",
"about_sc": "Про текстуру. Назва файлу: %s (%d), Тип пікселів: %d, Величина: %sx%s",
"decompression_error": "Помилка при розпакуванні! Намагаємся розпакувати як є...",
"skip_not_installed": "%s не встановлений, повторіть налаштування",
"detected_comp": "Виявлено %s компресію!",
"unk_type": "Невідомий вид пікселів: %s",
"detected_comp": "Виявлено компресію: %s",
"unknown_pixel_type": "Невідомий вид пікселів: %s",
"crt_pic": "Створюємо зоображеня...",
"join_pic": "З'єднуємо зоображення...",
"png_save": "Зберігаємо PNG...",
Expand All @@ -73,7 +73,6 @@
"cut_sprites_process": "Обрізаємо спрайти... (%d/%d)",
"place_sprites_process": "Вставляємо спрайти... (%d/%d)",
"not_implemented": "Ця функція буде додана у наступних оновленнях.\nТи можеш сладкувати за оновленнями тут: github.com/Vorono4ka/XCoder",
"dec_sc": "Розпаковуємо .sc файл...",
"error": "Помилка! (%s.%s: %s)",
"e1sc1": "Переписати SC спрайти",
"cgl": "Список змін:\n%s",
Expand All @@ -88,4 +87,4 @@
"disabled": "Виключено",

"install_to_unlock": "Встанови '%s' щоб розблокувати більше функції!"
}
}
106 changes: 64 additions & 42 deletions system/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import sys
import time

from loguru import logger

from system import clear
from system.lib.config import config
from system.lib.console import Console
from system.lib.features.directories import clear_directories
from system.lib.features.initialization import initialize
from system.lib.features.update.check import check_update, check_for_outdated, get_tags
from system.lib.menu import menu, Menu
from system.lib.features.update.check import check_for_outdated, check_update, get_tags
from system.lib.menu import Menu, menu
from system.localization import locale

from loguru import logger

logger.remove()
logger.add(
"./logs/info/{time:YYYY-MM-DD}.log",
Expand Down Expand Up @@ -64,99 +64,121 @@ def refill_menu():
import sc_compression

del sc_compression

except ImportError:
logger.warning(locale.install_to_unlock % "sc-compression")
else:
from system.lib.features.csv.compress import compress_csv
from system.lib.features.csv.decompress import decompress_csv

try:
import PIL

del PIL

from system.lib.features.sc.decode import sc_decode
from system.lib.features.sc.encode import sc_encode
from system.lib.features.sc.decode_and_cut import decode_and_cut
from system.lib.features.sc.assembly_encode import sc1_encode
except ImportError:
logger.warning(locale.install_to_unlock % "PILLOW")
else:
from system.lib.features.sc.decode import (
decode_and_render_objects,
decode_textures_only,
)
from system.lib.features.sc.encode import (
collect_objects_and_encode,
encode_textures_only,
)

sc_category = Menu.Category(0, locale.sc_label)
sc_category.add(
Menu.Item(locale.decode_sc, locale.decode_sc_description, sc_decode)
Menu.Item(
name=locale.decode_sc,
description=locale.decode_sc_description,
handler=decode_textures_only,
)
)
sc_category.add(
Menu.Item(locale.encode_sc, locale.encode_sc_description, sc_encode)
Menu.Item(
name=locale.encode_sc,
description=locale.encode_sc_description,
handler=encode_textures_only,
)
)
sc_category.add(
Menu.Item(
locale.decode_by_parts,
locale.decode_by_parts_description,
decode_and_cut,
name=locale.decode_by_parts,
description=locale.decode_by_parts_description,
handler=decode_and_render_objects,
)
)
sc_category.add(
Menu.Item(
locale.encode_by_parts,
locale.encode_by_parts_description,
sc1_encode,
name=locale.encode_by_parts,
description=locale.encode_by_parts_description,
handler=collect_objects_and_encode,
)
)
sc_category.add(
Menu.Item(
locale.overwrite_by_parts,
locale.overwrite_by_parts_description,
lambda: sc1_encode(True),
name=locale.overwrite_by_parts,
description=locale.overwrite_by_parts_description,
handler=lambda: collect_objects_and_encode(True),
)
)
menu.add_category(sc_category)
except ImportError:
logger.warning(locale.install_to_unlock % "PILLOW")

csv_category = Menu.Category(1, locale.csv_label)
csv_category.add(
Menu.Item(
locale.decompress_csv, locale.decompress_csv_description, decompress_csv
name=locale.decompress_csv,
description=locale.decompress_csv_description,
handler=decompress_csv,
)
)
csv_category.add(
Menu.Item(
locale.compress_csv, locale.compress_csv_description, compress_csv
name=locale.compress_csv,
description=locale.compress_csv_description,
handler=compress_csv,
)
)
menu.add_category(csv_category)
except ImportError:
logger.warning(locale.install_to_unlock % "sc-compression")

other = Menu.Category(10, locale.other_features_label)
other.add(
Menu.Item(locale.check_update, locale.version % config.version, check_update)
Menu.Item(
name=locale.check_update,
description=locale.version % config.version,
handler=check_update,
)
)
other.add(Menu.Item(locale.check_for_outdated, None, check_for_outdated))
other.add(Menu.Item(name=locale.check_for_outdated, handler=check_for_outdated))
other.add(
Menu.Item(
locale.reinit,
locale.reinit_description,
lambda: (initialize(), refill_menu()),
name=locale.reinit,
description=locale.reinit_description,
handler=lambda: (initialize(), refill_menu()),
)
)
other.add(
Menu.Item(
locale.change_language,
locale.change_lang_description % config.language,
lambda: (config.change_language(locale.change()), refill_menu()),
name=locale.change_language,
description=locale.change_lang_description % config.language,
handler=lambda: (config.change_language(locale.change()), refill_menu()),
)
)
other.add(
Menu.Item(
locale.clear_directories,
locale.clean_dirs_description,
lambda: clear_directories() if Console.question(locale.clear_qu) else -1,
name=locale.clear_directories,
description=locale.clean_dirs_description,
handler=lambda: clear_directories()
if Console.question(locale.clear_qu)
else -1,
)
)
other.add(
Menu.Item(
locale.toggle_update_auto_checking,
locale.enabled if config.auto_update else locale.disabled,
lambda: (config.toggle_auto_update(), refill_menu()),
name=locale.toggle_update_auto_checking,
description=locale.enabled if config.auto_update else locale.disabled,
handler=lambda: (config.toggle_auto_update(), refill_menu()),
)
)
other.add(Menu.Item(locale.exit, None, lambda: (clear(), exit())))
other.add(Menu.Item(name=locale.exit, handler=lambda: (clear(), exit())))
menu.add_category(other)
Loading