1
1
from system .bytestream import Writer
2
2
from system .lib .config import Config
3
3
from system .lib .logger import Logger
4
+ from system .lib .menu import Menu
4
5
from system .localization import Locale
5
6
6
7
from system .lib .objects .texture import SWFTexture
7
8
from system .lib .objects .shape import Shape
8
- from system .lib .objects .movie_clip import MovieClip
9
+ from system .lib .objects .movieclip import MovieClip
9
10
10
11
logger = Logger ('en-EU' )
11
12
38
39
is_windows = platform .system () == 'Windows'
39
40
null_output = f'{ "nul" if is_windows else "/dev/null" } 2>&1'
40
41
42
+
41
43
config = Config ()
42
44
locale = Locale ()
43
45
locale .load_from (config .lang )
@@ -89,61 +91,88 @@ def make_dirs(directory):
89
91
os .makedirs (directory )
90
92
91
93
92
- def print_feature (name : str , description : str = None , console_width : int = - 1 ):
93
- print (name , end = '' )
94
- if description :
95
- print (' ' * (console_width // 2 - len (name )) + ': ' + description , end = '' )
96
- print ()
97
-
98
-
99
- def print_category (text , color = None ):
100
- if color is None :
101
- color = colorama .Back .GREEN
102
- return print (color + colorama .Fore .BLACK + text + ' ' * (10 - len (text )) + colorama .Style .RESET_ALL )
103
-
104
-
105
- def welcome_text ():
106
- locale .load_from (config .lang )
107
-
108
- console_width = shutil .get_terminal_size ().columns
109
- print ((
110
- colorama .Back .BLACK + colorama .Fore .GREEN +
111
- locale .xcoder_header % config .version +
112
- colorama .Style .RESET_ALL
113
- ).center (console_width + 14 ))
114
- print ('github.com/Vorono4ka/XCoder' .center (console_width ))
115
- print (console_width * '-' )
116
-
117
- print_category (locale .sc_label )
118
- print_feature (' 1 ' + locale .decode_sc , locale .decode_sc_description , console_width )
119
- print_feature (' 2 ' + locale .encode_sc , locale .encode_sc_description , console_width )
120
- print_feature (' 3 ' + locale .decode_by_parts , locale .decode_by_parts_description , console_width )
121
- print_feature (' 4 ' + locale .encode_by_parts , locale .encode_by_parts_description , console_width )
122
- print_feature (' 5 ' + locale .overwrite_by_parts , locale .overwrite_by_parts_description , console_width )
123
- print (console_width * '-' )
124
-
125
- print_category (locale .csv_label )
126
- print_feature (' 11 ' + locale .decompress_csv , locale .decompress_csv_description , console_width )
127
- print_feature (' 12 ' + locale .compress_csv , locale .compress_csv_description , console_width )
128
- print (console_width * '-' )
129
-
130
- print_category (locale .other_features_label )
131
- print_feature (' 101 ' + locale .check_update , locale .version % config .version , console_width )
132
- print_feature (' 102 ' + locale .check_for_outdated )
133
- print_feature (' 103 ' + locale .reinit , locale .reinit_description , console_width )
134
- print_feature (' 104 ' + locale .change_lang , locale .change_lang_description % config .lang , console_width )
135
- print_feature (' 105 ' + locale .clear_dirs , locale .clean_dirs_description , console_width )
136
- print_feature (
137
- ' 106 ' + locale .toggle_update_auto_checking ,
94
+ def create_menu ():
95
+ menu = Menu ()
96
+
97
+ refill_menu (menu )
98
+
99
+ return menu
100
+
101
+
102
+ def refill_menu (menu ):
103
+ menu .categories .clear ()
104
+
105
+ menu .add_category (Menu .Category (0 , locale .sc_label ))
106
+ menu .categories [0 ].add (Menu .Item (
107
+ locale .decode_sc ,
108
+ locale .decode_sc_description ,
109
+ sc_decode
110
+ ))
111
+ menu .categories [0 ].add (Menu .Item (
112
+ locale .encode_sc ,
113
+ locale .encode_sc_description ,
114
+ sc_encode
115
+ ))
116
+ menu .categories [0 ].add (Menu .Item (
117
+ locale .decode_by_parts ,
118
+ locale .decode_by_parts_description ,
119
+ sc1_decode
120
+ ))
121
+ menu .categories [0 ].add (Menu .Item (
122
+ locale .encode_by_parts ,
123
+ locale .encode_by_parts_description ,
124
+ sc1_encode
125
+ ))
126
+ menu .categories [0 ].add (Menu .Item (
127
+ locale .overwrite_by_parts ,
128
+ locale .overwrite_by_parts_description ,
129
+ lambda : sc1_encode (True )
130
+ ))
131
+
132
+ menu .add_category (Menu .Category (1 , locale .csv_label ))
133
+ menu .categories [1 ].add (Menu .Item (
134
+ locale .decompress_csv ,
135
+ locale .decompress_csv_description ,
136
+ decompress_csv
137
+ ))
138
+ menu .categories [1 ].add (Menu .Item (
139
+ locale .compress_csv ,
140
+ locale .compress_csv_description ,
141
+ compress_csv
142
+ ))
143
+
144
+ menu .add_category (Menu .Category (10 , locale .other_features_label ))
145
+ menu .categories [2 ].add (Menu .Item (
146
+ locale .check_update ,
147
+ locale .version % config .version ,
148
+ check_update
149
+ ))
150
+ menu .categories [2 ].add (Menu .Item (
151
+ locale .check_for_outdated ,
152
+ None ,
153
+ check_for_outdated
154
+ ))
155
+ menu .categories [2 ].add (Menu .Item (
156
+ locale .reinit ,
157
+ locale .reinit_description ,
158
+ init
159
+ ))
160
+ menu .categories [2 ].add (Menu .Item (
161
+ locale .change_lang ,
162
+ locale .change_lang_description % config .lang ,
163
+ lambda : (select_lang (), refill_menu (menu ))
164
+ ))
165
+ menu .categories [2 ].add (Menu .Item (
166
+ locale .clear_dirs ,
167
+ locale .clean_dirs_description ,
168
+ lambda : clear_dirs () if Console .question (locale .clear_qu ) else - 1
169
+ ))
170
+ menu .categories [2 ].add (Menu .Item (
171
+ locale .toggle_update_auto_checking ,
138
172
locale .enabled if config .auto_update else locale .disabled ,
139
- console_width
140
- )
141
- print_feature (' 107 ' + locale .exit )
142
- print (console_width * '-' )
143
-
144
- choice = input (locale .choice )
145
- print (console_width * '-' )
146
- return choice
173
+ lambda : (toggle_auto_update (), refill_menu (menu ))
174
+ ))
175
+ menu .categories [2 ].add (Menu .Item (locale .exit , None , lambda : (clear (), exit ())))
147
176
148
177
149
178
def get_pip_info (outdated : bool = False ) -> list :
@@ -173,6 +202,59 @@ def get_tags(owner: str, repo: str):
173
202
return tags
174
203
175
204
205
+ def select_lang ():
206
+ config .lang = locale .change ()
207
+ config .dump ()
208
+
209
+ locale .load_from (config .lang )
210
+
211
+
212
+ def init (first_init = False ):
213
+ if first_init :
214
+ clear ()
215
+
216
+ Console .info (locale .detected_os % platform .system ())
217
+ Console .info (locale .installing )
218
+
219
+ required_packages = [pkg .rstrip ('\n ' ).lower () for pkg in open ('requirements.txt' ).readlines ()]
220
+ installed_packages = [pkg [0 ].lower () for pkg in get_pip_info ()]
221
+ for package in required_packages :
222
+ if package in installed_packages :
223
+ continue
224
+
225
+ if run (f'pip3 install { package } ' ) == 0 :
226
+ Console .info (locale .installed % package )
227
+ else :
228
+ Console .info (locale .not_installed % package )
229
+ Console .info (locale .crt_workspace )
230
+ [[make_dirs (f'SC/{ i } -{ k } ' ) for k in ['Compressed' , 'Decompressed' , 'Sprites' ]] for i in ['In' , 'Out' ]]
231
+ [[make_dirs (f'CSV/{ i } -{ k } ' ) for k in ['Compressed' , 'Decompressed' ]] for i in ['In' , 'Out' ]]
232
+ Console .info (locale .verifying )
233
+
234
+ config .initialized = True
235
+ config .version = get_tags ('vorono4ka' , 'xcoder' )[0 ]['name' ][1 :]
236
+ config .dump ()
237
+
238
+ if first_init :
239
+ input (locale .to_continue )
240
+
241
+
242
+ def clear_dirs ():
243
+ for i in ['In' , 'Out' ]:
244
+ for k in ['Compressed' , 'Decompressed' , 'Sprites' ]:
245
+ folder = f'SC/{ i } -{ k } '
246
+ if os .path .isdir (folder ):
247
+ shutil .rmtree (folder )
248
+ make_dirs (folder )
249
+
250
+ for i in ['In' , 'Out' ]:
251
+ for k in ['Compressed' , 'Decompressed' ]:
252
+ folder = f'CSV/{ i } -{ k } '
253
+ if os .path .isdir (folder ):
254
+ shutil .rmtree (folder )
255
+ make_dirs (folder )
256
+
257
+
176
258
def toggle_auto_update ():
177
259
config .auto_update = not config .auto_update
178
260
config .dump ()
@@ -523,10 +605,6 @@ def compile_sc(_dir, from_memory=None, img_data=None, folder_export=None):
523
605
write_sc (f'{ folder_export } /{ name } .sc' , sc .getvalue (), use_lzham )
524
606
525
607
526
- def ceil (integer ) -> int :
527
- return round (integer + 0.5 )
528
-
529
-
530
608
class SupercellSWF :
531
609
def __init__ (self ):
532
610
self .filename = None
@@ -544,7 +622,7 @@ def __init__(self):
544
622
self .exports = {}
545
623
546
624
self .shapes = []
547
- self .movie_clips = []
625
+ self .movieclips = []
548
626
self .textures = []
549
627
550
628
self .matrices = []
@@ -572,7 +650,7 @@ def load_internal(self, filepath: str, is_texture: bool):
572
650
self .color_transformation_count = self .reader .read_uint16 ()
573
651
574
652
self .shapes = [_class () for _class in [Shape ] * self .shape_count ]
575
- self .movie_clips = [_class () for _class in [MovieClip ] * self .movie_clips_count ]
653
+ self .movieclips = [_class () for _class in [MovieClip ] * self .movie_clips_count ]
576
654
self .textures = [_class () for _class in [SWFTexture ] * self .textures_count ]
577
655
578
656
self .reader .read_uint32 ()
@@ -592,7 +670,7 @@ def load_tags(self):
592
670
has_texture = True
593
671
594
672
texture_id = 0
595
- loaded_movie_clips = 0
673
+ loaded_movieclips = 0
596
674
loaded_shapes = 0
597
675
598
676
while True :
@@ -628,8 +706,8 @@ def load_tags(self):
628
706
self .shapes [loaded_shapes ].load (self , tag )
629
707
loaded_shapes += 1
630
708
elif tag in [3 , 10 , 12 , 14 , 35 ]: # MovieClip
631
- self .movie_clips [ loaded_movie_clips ].load (self , tag )
632
- loaded_movie_clips += 1
709
+ self .movieclips [ loaded_movieclips ].load (self , tag )
710
+ loaded_movieclips += 1
633
711
elif tag == 8 : # Matrix
634
712
scale_x = self .reader .read_int32 () / 1024
635
713
rotation_x = self .reader .read_int32 () / 1024
@@ -768,8 +846,3 @@ def place_sprites(xcod, folder, overwrite=False):
768
846
print ()
769
847
770
848
return sheet_image , sheet_image_data
771
-
772
-
773
- # Testing TIME!
774
- if __name__ == '__main__' :
775
- welcome_text ()
0 commit comments