Exemplo n.º 1
0
 def _output2():
     json_ver = '/Users/joli/Downloads/fy/assets/game/resource/1_00.58_version.json'
     conf_src = '/Users/joli/Downloads/fy/assets/game/resource/config'
     conf_dst = '/Users/joli/Downloads/fy/assets/game/resource/config'
     ver_dict = {}
     for k, v in json.loads(FS.read_text(json_ver)).items():
         ver_dict[v] = k
     for f in FS.walk_files(conf_src, ewhites=['.json']):
         # f = '/Users/joli/Downloads/fy/assets/game/resource/config/4643a093.json'
         config = demjson.decode_file(f)
         if not config:
             print('empty config:' + f)
             continue
         vf = ver_dict[FS.filename(f)]
         df = os.path.join(conf_dst, vf[0:vf.rfind('.')] + '.xlsx')
         print(f)
         print(vf)
         print(df)
         wb = openpyxl.Workbook()
         if vf.startswith('global/') or 'error_code_data' in vf:
             print(config)
             _build_sheet1(wb.active, config, FS.filename(df), flat=True)
         else:
             _build_book1(wb, config, FS.filename(df))
         FS.make_parent(df)
         wb.save(df)
Exemplo n.º 2
0
 def fullpath(parent, info):
     for key in info:
         obj = info[key]
         if isinstance(obj, dict):
             fullpath('%s/%s' % (parent, key), obj)
         else:
             ext = FS.extensions(key)
             isetc = False
             if ext == '.etc':
                 isetc = True
                 ext = '.png'
             filename = '%s_%s%s' % (FS.filename(key), obj, ext)
             if not _httpload(parent, filename):
                 if isetc:
                     filename = '%s_%s%s' % (FS.filename(key), obj,
                                             '.jpg')
                     if not _httpload(parent, filename):
                         filename = '%s_%s%s' % (FS.filename(key), obj,
                                                 '.etc')
                         if not _httpload(parent, filename):
                             failurl = parent + '/' + filename
                             log.e('fail', failurl)
                             errors.append(failurl)
                 else:
                     failurl = parent + '/' + filename
                     log.e('fail', failurl)
                     errors.append(failurl)
Exemplo n.º 3
0
def test_split_images():
    from com.arts import SplitImages
    # SplitImages.tp('/Users/joli/Desktop/snsgz/effect/effect_beifa_2/effect_beifa_2.plist')
    pro = '/Users/joli/Desktop/test/rob/1'
    src = os.path.join(pro, 'snxyj')
    for f in FS.walk_files(src, ewhites=['.plist'], cut=len(src) + 1):
        d = os.path.join(pro, 'snxyj_ef', os.path.dirname(f), FS.filename(f))
        SplitImages.tp(os.path.join(src, f), outputdir=d)
Exemplo n.º 4
0
 def _dump_fileinfo(self, pkgfile):
     if not self._filemap:
         return
     path = os.path.join(os.path.dirname(pkgfile),
                         FS.filename(pkgfile) + '.txt')
     with open(path, 'w') as fp:
         for hashcode in self._filemap:
             tag = self._filemap[hashcode]
             fp.writelines('%d\t%s\n' % (hashcode, tag))
Exemplo n.º 5
0
def laya_sk(skpath, imagepath=None, outputdir=None):
    from jonlin.utils import Bit
    with open(skpath, 'rb') as fp:
        ba = Bit.ByteArray().init_buffer(fp.read())
        ani_version = ba.read_utf8()
        ani_classname = ba.read_utf8()
        ani_names = ba.read_utf8()
        ani_count = ba.read_u8()
        pub_data_pos = ba.read_u32()
        ext_data_pos = ba.read_u32()
        # print(pub_data_pos, ext_data_pos)
        ba.set_position(ext_data_pos)
        ext_buffer = ba.read_bytes(ba.get_available())
        ba = Bit.ByteArray().init_buffer(ext_buffer)
        tex_count = ba.read_int()
        tex_array = ba.read_utf8().split('\n')
        tex_books = {}
        tex_frames = []
        for i in range(tex_count):
            tex_name = tex_array[i * 2 + 1]
            tex_books[tex_name] = tex_array[i * 2]
            x = ba.read_float()
            y = ba.read_float()
            w = ba.read_float()
            h = ba.read_float()
            fx = ba.read_float()
            fy = ba.read_float()
            fw = ba.read_float()
            fh = ba.read_float()
            # print(tex_name, x, y, w, h, fx, fy, fw, fh)
            tex_frames.append((tex_name, x, y, w, h, fx, fy, fw, fh))
        # crop images
        atlas_root = os.path.dirname(skpath)
        if outputdir is None:
            imagesdir = os.path.join(atlas_root,
                                     FS.filename(skpath) + '_images')
        else:
            imagesdir = outputdir
        # if not os.path.isdir(imagesdir):
        #     os.makedirs(imagesdir)
        image_map = {}
        for src in set(tex_books.values()):
            image_map[src] = Image.open(os.path.join(atlas_root, src))
        for frame in tex_frames:
            tex_name = frame[0]
            x = frame[1]
            y = frame[2]
            w = frame[3]
            h = frame[4]
            rect = (x, y, x + w, y + h)
            image = image_map[tex_books[tex_name]]
            item_img = image.crop(rect)
            item_src = os.path.join(imagesdir, tex_name + '.png')
            FS.make_parent(item_src)
            item_img.save(item_src)
Exemplo n.º 6
0
 def _batch_refactor(root_dir, version=2):
     for root, dirs, _ in os.walk(root_dir):
         for dn in dirs:
             if version == 2 and dn != 'package':
                 continue
             # print(os.path.join(root, dn))
             plists = FS.walk_files(os.path.join(root, dn),
                                    ewhites=['.plist'])
             for pp in plists:
                 if version == 2:
                     if pp.endswith('copyright.plist'):
                         continue
                     if pp.endswith('yzadmin.plist'):
                         FS.moveto(
                             pp,
                             pp.replace('yzadmin.plist', 'copyright.plist'))
                         continue
                     if FS.parentname(pp) != FS.filename(pp):
                         continue
                 elif version == 1:
                     if not FS.parentname(pp).endswith(FS.filename(pp)):
                         continue
                 _refactor_xcode_plist(pp)
Exemplo n.º 7
0
 def _output1():
     src = '/Users/joli/Downloads/configIOS_json190731'
     dst = '/Users/joli/Downloads/configIOS_excel'
     for filename in FS.walk_files(src, ewhites=['.json'],
                                   cut=len(src) + 1):
         print('------------------------------------', filename)
         name = FS.filename(filename)
         conf = demjson.decode_file(os.path.join(src, filename))
         if not conf:
             print('empty config')
             continue
         wb = openpyxl.Workbook()
         # print(wb.get_sheet_names())
         _build_book2(wb, conf, name)
         wb.save(os.path.join(dst, name + '.xlsx'))
Exemplo n.º 8
0
 def edit_end(self, build_look_map, is_force):
     lualist = FS.walk_files(self._out_root, ewhites=['.lua'])
     for i in range(len(lualist) - 1, -1, -1):
         tag = lualist[i]
         removed = False
         excel_name = FS.parentname(tag)
         if excel_name in build_look_map:
             book_look_map = build_look_map[excel_name]
             if book_look_map != _Fmt.NO_DIFF_FLAG:  # 这个表没有修改
                 if FS.filename(tag) not in book_look_map:
                     removed = True
         else:
             removed = True
         if removed:
             luafile = os.path.join(self._out_root, tag)
             log.w('删除表文件:', luafile)
             os.remove(luafile)
             lualist.pop(i)
     FS.rm_empty_dirs(self._out_root)
     return len(lualist)
Exemplo n.º 9
0
 def _out_pkg(self, build_look_map):
     if not os.path.isdir(self._ulo_path):
         os.makedirs(self._ulo_path)
     for excel_name, sheet_dict in self._new_dict.items():
         ba = Bit.ByteArray().init_capacity(1024 * 1024 * 8)
         ba.set_position(2)
         sheet_nums = self._build_buf(excel_name, sheet_dict, ba)
         ba.set_position(0).write_u16(sheet_nums)  # 写入表的数量
         with open(os.path.join(self._ulo_path, excel_name + '.ulo'),
                   'wb') as fp:
             fp.write(ba.slim_buffer())
     total_nums = 0
     for name in os.listdir(self._ulo_path):
         ulofile = os.path.join(self._ulo_path, name)
         if FS.filename(name) not in build_look_map:
             log.w('删除表文件:', ulofile)
             os.remove(ulofile)
         else:
             with open(ulofile, 'rb') as fp:
                 total_nums += Bit.u16_from(fp.read(2))
     return total_nums
Exemplo n.º 10
0
def spine(atlaspath, imagepath=None, outputdir=None, fixwhite=True):
    with open(atlaspath, 'r') as fp:
        atlases, atlas, header, frames, frame = [], None, None, None, None
        for line in fp.readlines():
            if line.isspace():
                header, frames = {}, []
                atlas = {'header': header, 'frames': frames}
                atlases.append(atlas)
                continue
            line = ''.join(line.split())  # 去除空格
            if not line:
                continue
            pos = line.find(':')
            if header is not None:
                if -1 == pos:
                    header['image'] = line
                else:
                    pos += 1
                    if line.startswith('size'):
                        header['size'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('format'):
                        header['format'] = line[pos:]
                    elif line.startswith('filter'):
                        header['filter'] = tuple(
                            [x for x in line[pos:].split(',')])
                    elif line.startswith('repeat'):
                        header['repeat'] = line[pos:]
                        header = None
            else:
                if -1 == pos:
                    frame = {'name': line}
                    frames.append(frame)
                else:
                    pos += 1
                    if line.startswith('rotate'):
                        frame['rotate'] = False if line[
                            pos:] == 'false' else True
                    elif line.startswith('xy'):
                        frame['xy'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('size'):
                        frame['size'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('orig'):
                        frame['orig'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('offset'):
                        frame['offset'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('index'):
                        frame['index'] = int(line[pos:])
    for atlas in atlases:
        if not atlas['frames']:
            continue
        image_name = atlas['header']['image']
        atlas_dir = os.path.dirname(atlaspath)
        if imagepath is None:
            imagepath = os.path.join(atlas_dir, image_name)
        if not os.path.isfile(imagepath):
            continue
        if outputdir is None:
            outputdir = os.path.join(atlas_dir,
                                     FS.filename(image_name) + '_images')
        image = Image.open(imagepath)
        for frame in atlas['frames']:
            if 'xy' not in frame:
                continue
            x, y = frame['xy']
            w, h = frame['size']
            if frame['rotate']:
                w, h = h, w
            rect = (x, y, x + w, y + h)
            item_img = image.crop(rect)
            if frame['rotate']:
                # item_img = item_img.rotate(270)
                item_img = item_img.transpose(Image.ROTATE_270)
            if fixwhite:
                x, y = frame['offset']
                y = frame['orig'][1] - y - item_img.size[1]
                rect = (x, y, x + item_img.size[0], y + item_img.size[1])
                item_box = Image.new('RGBA', size=frame['orig'])
                item_box.paste(item_img, rect)
                item_img = item_box
            item_path = os.path.join(outputdir, frame['name'] + '.png')
            FS.make_parent(item_path)
            item_img.save(item_path)
Exemplo n.º 11
0
 def __init__(self, path, sheets, errors):
     self.path = path
     self.name = FS.filename(path)
     self.sheets = sheets
     self.errors = errors
     self.epxort_sheets = {}