Skip to content

Commit 0706fa7

Browse files
A new method for calculating rotation of regions
1 parent 397d403 commit 0706fa7

File tree

14 files changed

+198
-217
lines changed

14 files changed

+198
-217
lines changed

main.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
# Refactored by Vorono4ka
22
# Finished ~99%
3-
# Translated by yura331.com
43

54
import time
65

76
try:
87
from loguru import logger
98
except ImportError:
10-
print('Please, install loguru using pip')
11-
exit()
9+
raise RuntimeError('Please, install loguru using pip')
1210

1311
from system import clear
14-
from system.lib import config, Console, locale, refill_menu, menu
12+
from system.lib import config, locale, refill_menu, menu
1513
from system.lib.features.initialization import initialize
1614

1715

18-
if __name__ == '__main__':
16+
def main():
1917
if not config.initialized:
2018
config.change_language(locale.change())
2119

@@ -26,16 +24,19 @@
2624
refill_menu()
2725

2826
while True:
29-
try:
30-
handler = menu.choice()
31-
if handler is not None:
32-
start_time = time.time()
33-
with logger.catch():
34-
handler()
35-
logger.opt(colors=True).info(f'<green>{locale.done % (time.time() - start_time)}</green>')
36-
input(locale.to_continue)
37-
clear()
38-
except KeyboardInterrupt:
39-
if Console.question(locale.want_exit):
40-
clear()
41-
break
27+
handler = menu.choice()
28+
if handler is not None:
29+
start_time = time.time()
30+
with logger.catch():
31+
handler()
32+
logger.opt(colors=True).info(f'<green>{locale.done % (time.time() - start_time)}</green>')
33+
input(locale.to_continue)
34+
clear()
35+
36+
37+
if __name__ == '__main__':
38+
try:
39+
main()
40+
except KeyboardInterrupt:
41+
logger.info('Exit.')
42+
pass

system/languages/en-EU.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"cut_sprites_process": "Cutting sprites... (%d/%d)",
7474
"place_sprites_process": "Placing sprites... (%d/%d)",
7575
"not_implemented": "This feature will be added in future updates.\nYou can follow XCoder updates here: github.com/Vorono4ka/XCoder",
76-
"want_exit": "Want to exit?",
7776
"dec_sc": "Decoding .sc file...",
7877
"error": "ERROR! (%s.%s: %s)",
7978
"e1sc1": "Overwrite SC sprites",

system/languages/ru-RU.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"cut_sprites_process": "Вырезаем спрайты... (%d/%d)",
7474
"place_sprites_process": "Ставим спрайты на место... (%d/%d)",
7575
"not_implemented": "Данная возможность будет добавлена в будущих обновлениях.\nЗа обновлениями XCoder вы можете следить здесь: github.com/Vorono4ka/XCoder",
76-
"want_exit": "Хотите выйти?",
7776
"dec_sc": "Декодируем SC...",
7877
"error": "ОШИБКА! (%s.%s: %s)",
7978
"e1sc1": "Перезапись спрайтов",

system/languages/ua-UA.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"cut_sprites_process": "Обрізаємо спрайти... (%d/%d)",
7474
"place_sprites_process": "Вставляємо спрайти... (%d/%d)",
7575
"not_implemented": "Ця функція буде додана у наступних оновленнях.\nТи можеш сладкувати за оновленнями тут: github.com/Vorono4ka/XCoder",
76-
"want_exit": "Справді хочете вийти?",
7776
"dec_sc": "Розпаковуємо .sc файл...",
7877
"error": "Помилка! (%s.%s: %s)",
7978
"e1sc1": "Переписати SC спрайти",

system/lib/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44

55
class Config:
6+
DEFAULT_LANGUAGE = 'en-EU'
7+
68
config_path = './system/config.json'
79
inited: bool
810

@@ -18,7 +20,7 @@ def __init__(self):
1820

1921
self.initialized: bool = False
2022
self.version = None
21-
self.language: str = 'en-EU'
23+
self.language: str = Config.DEFAULT_LANGUAGE
2224
self.has_update: bool = False
2325
self.last_update: int = -1
2426
self.auto_update: bool = False

system/lib/features/cut_sprites.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def cut_sprites(swf: SupercellSWF, export_folder: str):
3030
for region_index in range(regions_count):
3131
region = shape.regions[region_index]
3232

33-
swf.xcod_writer.write_ubyte(region.texture_id)
34-
swf.xcod_writer.write_ubyte(region.points_count)
35-
36-
for point in region.sheet_points:
37-
swf.xcod_writer.write_uint16(int(point.x))
38-
swf.xcod_writer.write_uint16(int(point.y))
39-
swf.xcod_writer.write_ubyte(1 if region.mirroring else 0)
40-
swf.xcod_writer.write_ubyte(region.rotation // 90)
33+
swf.xcod_writer.write_ubyte(region.texture_index)
34+
swf.xcod_writer.write_ubyte(region.get_points_count())
35+
36+
for i in range(region.get_points_count()):
37+
swf.xcod_writer.write_uint16(int(region.get_u(i)))
38+
swf.xcod_writer.write_uint16(int(region.get_v(i)))
39+
swf.xcod_writer.write_ubyte(1 if region.is_mirrored else 0)
40+
swf.xcod_writer.write_byte(region.rotation // 90)
4141

4242
rendered_region = region.render(swf)
4343
rendered_region.save(f'{export_folder}/shape_{shape.id}_{region_index}.png')

system/lib/features/place_sprites.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ def place_sprites(xcod_path: str, folder: str, overwrite: bool = False) -> (list
3434
texture_id, points_count = xcod.read_ubyte(), xcod.read_ubyte()
3535
texture_width, texture_height = sheets[texture_id].width, sheets[texture_id].height
3636
polygon = [(xcod.read_uint16(), xcod.read_uint16()) for _ in range(points_count)]
37-
mirroring, rotation = xcod.read_ubyte() == 1, xcod.read_ubyte() * 90
37+
mirroring, rotation = xcod.read_ubyte() == 1, xcod.read_byte() * 90
3838

3939
filename = f'shape_{shape_id}_{region_index}.png'
4040
if filename not in files_to_overwrite:
4141
continue
4242

4343
tmp_region = Image.open(
4444
f'{folder}{"/overwrite" if overwrite else ""}/{filename}'
45-
).convert('RGBA').rotate(360 - rotation, expand=True)
45+
).convert('RGBA').rotate(-rotation, expand=True)
4646

4747
img_mask = Image.new('L', (texture_width, texture_height), 0)
4848
color = 255
@@ -80,8 +80,7 @@ def place_sprites(xcod_path: str, folder: str, overwrite: bool = False) -> (list
8080
tmp_region = tmp_region.resize(region_size, Image.ANTIALIAS)
8181

8282
if mirroring:
83-
tmp_region = tmp_region.transform(region_size, Image.EXTENT,
84-
(tmp_region.width, 0, 0, tmp_region.height))
83+
tmp_region = tmp_region.transpose(Image.FLIP_LEFT_RIGHT)
8584

8685
sheets[texture_id].paste(Image.new('RGBA', region_size), (left, top), img_mask.crop(bbox))
8786
sheets[texture_id].paste(tmp_region, (left, top), tmp_region)

system/lib/features/sc/assembly_encode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def sc1_encode(overwrite: bool = False):
2424
compile_sc(f'{folder}{file}/', file_info, sheets, output_folder)
2525
except Exception as exception:
2626
logger.exception(locale.error % (exception.__class__.__module__, exception.__class__.__name__, exception))
27-
print()
27+
print()

system/lib/features/sc/decode_and_cut.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,27 @@ def sc1_decode():
2929
logger.error(locale.not_found % (base_name + '_tex.sc'))
3030
continue
3131

32-
current_sub_path = os.path.basename(swf.filename).rsplit('.', 1)[0]
33-
if os.path.isdir(f'{output_folder}/{current_sub_path}'):
34-
shutil.rmtree(f'{output_folder}/{current_sub_path}')
35-
os.mkdir(f'{output_folder}/{current_sub_path}')
36-
os.makedirs(f"{output_folder}/{current_sub_path}/textures", exist_ok=True)
37-
base_name = os.path.basename(file).rsplit('.', 1)[0]
32+
base_name = os.path.basename(swf.filename).rsplit('.', 1)[0]
33+
if os.path.isdir(f'{output_folder}/{base_name}'):
34+
shutil.rmtree(f'{output_folder}/{base_name}')
35+
os.mkdir(f'{output_folder}/{base_name}')
36+
os.makedirs(f"{output_folder}/{base_name}/textures", exist_ok=True)
3837

39-
with open(f'{output_folder}/{current_sub_path}/{base_name}.xcod', 'wb') as xcod_file:
38+
with open(f'{output_folder}/{base_name}/{base_name}.xcod', 'wb') as xcod_file:
4039
xcod_file.write(b'XCOD' + bool.to_bytes(use_lzham, 1, 'big') +
4140
int.to_bytes(len(swf.textures), 1, 'big'))
4241

4342
for img_index in range(len(swf.textures)):
4443
filename = base_name + '_' * img_index
4544
swf.textures[img_index].image.save(
46-
f'{output_folder}/{current_sub_path}/textures/{filename}.png'
45+
f'{output_folder}/{base_name}/textures/{filename}.png'
4746
)
4847

4948
logger.info(locale.dec_sc)
5049

5150
cut_sprites(
5251
swf,
53-
f'{output_folder}/{current_sub_path}'
52+
f'{output_folder}/{base_name}'
5453
)
5554
xcod_file.write(swf.xcod_writer.getvalue())
5655
except Exception as exception:

system/lib/images.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def read_pixel():
152152
if curr > point:
153153
Console.progress_bar(locale.crt_pic, y, height)
154154
point = curr
155-
print()
156155

157156

158157
def save_texture(sc, img, _type):

0 commit comments

Comments
 (0)