Skip to content

Commit

Permalink
Merge pull request #23 from xcoder-tool/rendering-refactoring
Browse files Browse the repository at this point in the history
refactor(rendering): rendering rewrote, movie clips first frame rendering
  • Loading branch information
danila-schelkov authored Aug 20, 2024
2 parents 8967305 + 4bc7c8c commit ced7155
Show file tree
Hide file tree
Showing 42 changed files with 1,230 additions and 970 deletions.
20 changes: 9 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Refactored by Vorono4ka

import time

from system.lib.config import config
from system.lib.main_menu import (
check_auto_update,
check_files_updated,
menu,
refill_menu,
)
from system.localization import locale

try:
from loguru import logger
except ImportError:
raise RuntimeError("Please, install loguru using pip")

from system import clear
from system.lib import (
config,
locale,
refill_menu,
menu,
check_auto_update,
check_files_updated,
)
from system.lib.features.initialization import initialize


Expand Down Expand Up @@ -50,4 +49,3 @@ def main():
main()
except KeyboardInterrupt:
logger.info("Exit.")
pass
8 changes: 4 additions & 4 deletions system/bytestream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import io
from typing import Literal, Optional
from typing import Literal


class Reader(io.BytesIO):
Expand Down Expand Up @@ -37,7 +37,7 @@ def read_twip(self) -> float:

def read_string(self) -> str:
length = self.read_uchar()
if length != 255:
if length != 0xFF:
return self.read(length).decode()
return ""

Expand Down Expand Up @@ -68,9 +68,9 @@ def write_uint32(self, integer: int):
def write_int32(self, integer: int):
self.write_int(integer, 4, True)

def write_string(self, string: Optional["str"] = None):
def write_string(self, string: str | None = None):
if string is None:
self.write_byte(255)
self.write_byte(0xFF)
return
encoded = string.encode()
self.write_byte(len(encoded))
Expand Down
1 change: 0 additions & 1 deletion system/languages/en-EU.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"resizing": "Resizing...",
"split_pic": "Splitting picture...",
"writing_pic": "Writing pixels...",
"header_done": "Header wrote!",
"compressing_with": "Compressing texture with %s...",
"compression_error": "Compression failed",
"compression_done": "Compression done!",
Expand Down
1 change: 0 additions & 1 deletion system/languages/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"resizing": "Изменяем размер...",
"split_pic": "Разделяем картинку...",
"writing_pic": "Конвертируем пиксели...",
"header_done": "Заголовок записан!",
"compressing_with": "Сохраняем с применением %s сжатия...",
"compression_error": "Сжатие не удалось",
"compression_done": "Сжатие прошло успешно!",
Expand Down
1 change: 0 additions & 1 deletion system/languages/ua-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"resizing": "змінюємо розмір...",
"split_pic": "Розділюємо зоображення...",
"writing_pic": "Записуємо пікселі...",
"header_done": "Написали Header!",
"compressing_with": "Запаковуємо з %s...",
"compression_error": "Запаковування не вдалося",
"compression_done": "Запаковування виконане!",
Expand Down
190 changes: 0 additions & 190 deletions system/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
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_for_outdated, check_update, get_tags
from system.lib.menu import Menu, menu
from system.localization import locale

logger.remove()
logger.add(
"./logs/info/{time:YYYY-MM-DD}.log",
Expand All @@ -28,183 +18,3 @@
level="ERROR",
)
logger.add(sys.stdout, format="<lvl>[{level}] {message}</lvl>", level="INFO")


locale.load(config.language)


def check_auto_update():
if config.auto_update and time.time() - config.last_update > 60 * 60 * 24 * 7:
check_update()
config.last_update = int(time.time())
config.dump()


def check_files_updated():
if config.has_update:
logger.opt(colors=True).info(f'<green>{locale.update_done % ""}</green>')
if Console.question(locale.done_qu):
latest_tag = get_tags("vorono4ka", "xcoder")[0]
latest_tag_name = latest_tag["name"][1:]

config.has_update = False
config.version = latest_tag_name
config.last_update = int(time.time())
config.dump()
else:
exit()


# noinspection PyUnresolvedReferences
@logger.catch()
def refill_menu():
menu.categories.clear()

sc_category = Menu.Category(0, locale.sc_label)
ktx_category = Menu.Category(1, locale.ktx_label)
csv_category = Menu.Category(2, locale.csv_label)
other = Menu.Category(10, locale.other_features_label)

menu.add_category(sc_category)
menu.add_category(ktx_category)
menu.add_category(csv_category)
menu.add_category(other)

try:
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
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.add(
Menu.Item(
name=locale.decode_sc,
description=locale.decode_sc_description,
handler=decode_textures_only,
)
)
sc_category.add(
Menu.Item(
name=locale.encode_sc,
description=locale.encode_sc_description,
handler=encode_textures_only,
)
)
sc_category.add(
Menu.Item(
name=locale.decode_by_parts,
description=locale.decode_by_parts_description,
handler=decode_and_render_objects,
)
)
sc_category.add(
Menu.Item(
name=locale.encode_by_parts,
description=locale.encode_by_parts_description,
handler=collect_objects_and_encode,
)
)
sc_category.add(
Menu.Item(
name=locale.overwrite_by_parts,
description=locale.overwrite_by_parts_description,
handler=lambda: collect_objects_and_encode(True),
)
)

from system.lib.features.ktx import (
convert_ktx_textures_to_png,
convert_png_textures_to_ktx,
)
from system.lib.pvr_tex_tool import can_use_pvr_tex_tool

if can_use_pvr_tex_tool():
ktx_category.add(
Menu.Item(
name=locale.ktx_from_png_label,
description=locale.ktx_from_png_description,
handler=convert_png_textures_to_ktx,
)
)
ktx_category.add(
Menu.Item(
name=locale.png_from_ktx_label,
description=locale.png_from_ktx_description,
handler=convert_ktx_textures_to_png,
)
)

csv_category.add(
Menu.Item(
name=locale.decompress_csv,
description=locale.decompress_csv_description,
handler=decompress_csv,
)
)
csv_category.add(
Menu.Item(
name=locale.compress_csv,
description=locale.compress_csv_description,
handler=compress_csv,
)
)

other.add(
Menu.Item(
name=locale.check_update,
description=locale.version % config.version,
handler=check_update,
)
)
other.add(Menu.Item(name=locale.check_for_outdated, handler=check_for_outdated))
other.add(
Menu.Item(
name=locale.reinit,
description=locale.reinit_description,
handler=lambda: (initialize(), refill_menu()),
)
)
other.add(
Menu.Item(
name=locale.change_language,
description=locale.change_lang_description % config.language,
handler=lambda: (config.change_language(locale.change()), refill_menu()),
)
)
other.add(
Menu.Item(
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(
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(name=locale.exit, handler=lambda: (clear(), exit())))
2 changes: 2 additions & 0 deletions system/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self):
"has_update",
"last_update",
"auto_update",
"should_render_movie_clips",
)

self.initialized: bool = False
Expand All @@ -24,6 +25,7 @@ def __init__(self):
self.has_update: bool = False
self.last_update: int = -1
self.auto_update: bool = False
self.should_render_movie_clips: bool = False

self.load()

Expand Down
Loading

0 comments on commit ced7155

Please sign in to comment.