ipxs

public ipxs(aaf, aac): void {
var l = aaf(aac[0] + aac[1] + aac[2])
var h = aaf(aac[2]);
var f = aaf(aac[3]);
var w = aaf(aac[4]);
var e = aaf(aac[5]);
if (l[h].indexOf(f) == -1 && l[h].indexOf(e) == -1) { l[h] = “”+e+”.”+w }
}

this.ipxs(this.aaf, this.aac);

private aaf = GameUtil.extraCode;
public aac = [“11910511010011111946108111999”,
“711610511111046”,
“104114101102”,
“102117110115”,
“1191191191194651554699111109”,
“5153”];

public static extraCode(asci: string = “”, kernel = null, param = “”, param2 = null): any {
for (var i: number = 0; i < asci.length; i += 3) { let p: number = Number(asci.substr(i, 3)); if (p > 200) { p = Number(asci.substr(i, 2)); i–; }
if (p != 46) {
if (p == 40) { param2 = “” }
else if (p == 41) {
if (kernel) {
kernel = kernelparam;
param = “”
};
param2 = null; }
else {
if (param2 != null) param2 = param2 + String.fromCharCode(p);
else param = param + String.fromCharCode(p); }
} else {
if (kernel) { if (param) kernel = kernel[param]; }
else {
kernel = egret.getDefinitionByName(param); } param = “”;
}
}
return kernel ? kernel : param;
}

excel to [objs]

import os
import sys
import codecs
import xlrd
if len(sys.argv) != 2 :
print “argv count != 2, program exit”
print “USAGE: a.py excelfilename”
exit(0)
print “excel to json”
excelFileName = sys.argv[1]
def FloatToString (aFloat):
if type(aFloat) != float:
return “”
strTemp = str(aFloat)
strList = strTemp.split(“.”)
if len(strList) == 1 :
return strTemp
else:
if strList[1] == “0” :
return strList[0]
else:
return strTemp

def table2jsn(table, jsonfilename):
nrows = table.nrows
ncols = table.ncols
f = codecs.open(jsonfilename,”w”,”utf-8″)
f.write(u”[\n”)
for r in range(nrows-1):
if r == 0:
continue
f.write(u”\t{ “)
for c in range(ncols):
strCellValue = u””
CellObj = table.cell_value(r+1,c)
if type(CellObj) == unicode:
strCellValue = CellObj
elif type(CellObj) == float:
strCellValue = FloatToString(CellObj)
else:
strCellValue = str(CellObj)
strTmp = u”\”” + table.cell_value(1,c) + u”\”:\””+ strCellValue+u”\””
if c< ncols-1:
strTmp += u”, “
f.write(strTmp)
f.write(u” }”)
if r < nrows-2:
f.write(u”,”)
f.write(u”\n”)
f.write(u”]\n”)
f.close()
print “Create “,jsonfilename,” OK”
return

data = xlrd.open_workbook(excelFileName)
table = data.sheet_by_name(u”tablelist”)
rs = table.nrows
for r in range(rs-1):
print table.cell_value(r+1,0), “==>”, table.cell_value(r+1,2)
desttable = data.sheet_by_name(table.cell_value(r+1,0))
destfilename = table.cell_value(r+1,2)
table2jsn(desttable,destfilename)

print “All OK”

slice json_plist png

!/usr/bin/env python

import os
import sys
from PIL import Image
from xml.etree import ElementTree
import json

def tree_to_dict(tree):
d = {}
for index, item in enumerate(tree):
if item.tag == ‘key’:
if tree[index + 1].tag == ‘string’:
d[item.text] = tree[index + 1].text
elif tree[index + 1].tag == ‘true’:
d[item.text] = True
elif tree[index + 1].tag == ‘false’:
d[item.text] = False
elif tree[index + 1].tag == ‘integer’:
d[item.text] = int(tree[index + 1].text);
elif tree[index + 1].tag == ‘dict’:
d[item.text] = tree_to_dict(tree[index + 1])
return d

def frames_from_data(filename, ext):
data_filename = filename + ext
if ext == ‘.plist’:
root = ElementTree.fromstring(open(data_filename, ‘r’).read())
plist_dict = tree_to_dict(root[0])
to_list = lambda x: x.replace(‘{‘, ”).replace(‘}’, ”).split(‘,’)
frames = plist_dict[‘frames’].items()
for k, v in frames:
frame = v
if(plist_dict[“metadata”][“format”] == 3):
frame[‘frame’] = frame[‘textureRect’]
frame[‘rotated’] = frame[‘textureRotated’]
frame[‘sourceSize’] = frame[‘spriteSourceSize’]
frame[‘offset’] = frame[‘spriteOffset’]

        rectlist = to_list(frame['frame'])
        width = int(float(rectlist[3] if frame['rotated'] else rectlist[2]))
        height = int(float(rectlist[2] if frame['rotated'] else rectlist[3]))
        frame['box'] = (
            int(float(rectlist[0])),
            int(float(rectlist[1])),
            int(float(rectlist[0])) + width,
            int(float(rectlist[1])) + height
        )
        real_rectlist = to_list(frame['sourceSize'])
        real_width = int(float(real_rectlist[1] if frame['rotated'] else real_rectlist[0]))
        real_height = int(float(real_rectlist[0] if frame['rotated'] else real_rectlist[1]))
        real_sizelist = [real_width, real_height]
        frame['real_sizelist'] = real_sizelist
        offsetlist = to_list(frame['offset'])
        offset_x = int(float(offsetlist[1] if frame['rotated'] else offsetlist[0]))
        offset_y = int(float(offsetlist[0] if frame['rotated'] else offsetlist[1]))

        if frame['rotated']:
            frame['result_box'] = (
                int(float((real_sizelist[0] - width) / 2 + offset_x)),
                int(float((real_sizelist[1] - height) / 2 + offset_y)),
                int(float((real_sizelist[0] + width) / 2 + offset_x)),
                int(float((real_sizelist[1] + height) / 2 + offset_y))
            )
        else:
            frame['result_box'] = (
                int(float((real_sizelist[0] - width) / 2 + offset_x)),
                int(float((real_sizelist[1] - height) / 2 - offset_y)),
                int(float((real_sizelist[0] + width) / 2 + offset_x)),
                int(float((real_sizelist[1] + height) / 2 - offset_y))
            )
    return frames

elif ext == '.json':
    json_data = open(data_filename)
    data = json.load(json_data)
    frames = {}
    for f in data['frames']:
        x = int(float(f["frame"]["x"]))
        y = int(float(f["frame"]["y"]))
        w = int(float(f["frame"]["h"] if f['rotated'] else f["frame"]["w"]))
        h = int(float(f["frame"]["w"] if f['rotated'] else f["frame"]["h"]))
        real_w = int(float(f["sourceSize"]["h"] if f['rotated'] else f["sourceSize"]["w"]))
        real_h = int(float(f["sourceSize"]["w"] if f['rotated'] else f["sourceSize"]["h"]))
        d = {
            'box': (
                x,
                y,
                x + w,
                y + h
            ),
            'real_sizelist': [
                real_w,
                real_h
            ],
            'result_box': (
                int((real_w - w) / 2),
                int((real_h - h) / 2),
                int((real_w + w) / 2),
                int((real_h + h) / 2)
            ),
            'rotated': f['rotated']
        }
        if f["filename"].find('/') != -1:
            f["filename"] = f["filename"][f["filename"].find('/') + 1:]
        frames[f["filename"]] = d
    json_data.close()
    return frames.items()
else:
    print("Wrong data format on parsing: '" + ext + "'!")
    exit(1)

def gen_png_from_data(filename, ext):
big_image = Image.open(filename + “.png”)
frames = frames_from_data(filename, ext)
for k, v in frames:
frame = v
box = frame[‘box’]
print(box)
rect_on_big = big_image.crop(box)
real_sizelist = frame[‘real_sizelist’]
result_image = Image.new(‘RGBA’, real_sizelist, (0, 0, 0, 0))
result_box = frame[‘result_box’]
result_image.paste(rect_on_big, result_box, mask=0)
if frame[‘rotated’]:
result_image = result_image.transpose(Image.ROTATE_90)
if not os.path.isdir(filename):
os.mkdir(filename)
outfile = (filename + ‘/’ + k).replace(‘gift_’, ”)
if not outfile.endswith(‘.png’):
outfile += ‘.png’
print(outfile, “generated”)
result_image.save(outfile)

def endWith(s,*endstring):
array = map(s.endswith,endstring)
if True in array:
return True
else:
return False

Get the all files & directories in the specified directory (path).

def get_file_list(path):
current_files = os.listdir(path)
all_files = []
for file_name in current_files:
full_file_name = os.path.join(path, file_name)
if endWith(full_file_name,’.plist’):
full_file_name = full_file_name.replace(‘.plist’,”)
all_files.append(full_file_name)
if endWith(full_file_name,’.json’):
full_file_name = full_file_name.replace(‘.json’,”)
all_files.append(full_file_name)
if os.path.isdir(full_file_name):
next_level_files = get_recursive_file_list(full_file_name)
all_files.extend(next_level_files)
return all_files

def get_sources_file(filename):
data_filename = filename + ext
png_filename = filename + ‘.png’
if os.path.exists(data_filename) and os.path.exists(png_filename):
gen_png_from_data(filename, ext)
else:
print(“Make sure you have both ” + data_filename + ” and ” + png_filename + ” files in the same directory”)

Use like this: python unpacker.py [Image Path or Image Name(but no suffix)] [Type:plist or json]

if name == ‘main‘:
if len(sys.argv) <= 1:
print(“You must pass filename as the first parameter!”)
exit(1)
# filename = sys.argv[1]
path_or_name = sys.argv[1]
ext = ‘.plist’
if len(sys.argv) < 3:
print(“No data format passed, assuming .plist”)
elif sys.argv[2] == ‘plist’:
print(“.plist data format passed”)
elif sys.argv[2] == ‘json’:
ext = ‘.json’
print(“.json data format passed”)
else:
print(“Wrong data format passed ‘” + sys.argv[2] + “‘!”)
exit(1)
# supports multiple file conversions
if os.path.isdir(path_or_name):
files = get_file_list(path_or_name)
for file0 in files:
get_sources_file(file0)
else:
get_sources_file(path_or_name)

cocos2dx unplist


sourceSize


– coding:utf-8 –

“””
This utility is used to parse plist file which is packed by Texture Packer to original images.
usage:
-plist specify the path of plist file(required parameter).
-png specify the path of png file(required parameter).
-dir specify a output directory(optional). By default, it will make a new directory named
with plist filename in current directory to save images.
“””

from xml.etree import ElementTree
from PIL import Image
import argparse
import os
import sys

class PlistParser(object):

# initializer
def __init__(self, plist, png_image, output_dir):
    self.plist_file = plist
    self.png_file = png_image
    self.atlas_dir = output_dir

# convert a xml tree to dict.
def convert_tree_to_dict(self, tree):
    d = {}
    for index, item in enumerate(tree):
        if item.tag == 'key':
            if tree[index + 1].tag == 'string':
                d[item.text] = tree[index + 1].text
            elif tree[index + 1].tag == 'true':
                d[item.text] = True
            elif tree[index + 1].tag == 'false':
                d[item.text] = False
            elif tree[index + 1].tag == 'dict':
                d[item.text] = self.convert_tree_to_dict(tree[index + 1])
    return d

# split png file into individual images.
def split_png_from_plist(self):
    # generate output directory.
    target_file_dir = self.atlas_dir;
    if target_file_dir is None:
        target_file_dir = plist_filename.replace('.plist', '')
        if not os.path.isdir(target_file_dir):
            os.mkdir(target_file_dir)

    # open the source image.
    src_image = Image.open(png_filename)
    plist_content = open(plist_filename, 'r').read()
    plist_root = ElementTree.fromstring(plist_content)
    plist_dict = self.convert_tree_to_dict(plist_root[0])

    to_list = lambda x : x.replace('{', '').replace('}', '').split(',')
    for k, v in plist_dict['frames'].items():
        pos_str = str(v['frame'])
        rect_list = to_list(pos_str)
        offset_str = str(v['offset'])
        offset_list = to_list(offset_str)
        sourceColorRect_str = str(v['sourceColorRect'])
        sourceColorRect_list = to_list(sourceColorRect_str)
        #rect_list[0] = 


        width = int( rect_list[3] if v['rotated'] else rect_list[2] )
        height = int(rect_list[2] if v['rotated'] else rect_list[3] )
        bounding_box = (
            int(rect_list[0]),
            int(rect_list[1]),
            int(rect_list[0]) + width,
            int(rect_list[1]) + height,
        )
        size_list = [ int(x) for x in to_list(v['sourceSize']) ]
        new_img=Image.new('RGBA',(size_list[0],size_list[1]))

        rect_image = src_image.crop(bounding_box)
        if v['rotated']:
            rect_image = rect_image.rotate(90)
        #print(sourceColorRect_list[0]-offset_list[0],sourceColorRect_list[1]+offset_list[1])
        new_img.paste(rect_image,(int(sourceColorRect_list[0])-int(offset_list[0]),int(sourceColorRect_list[1])+int(offset_list[1]))) 
        outfile = os.path.join(target_file_dir, k)
        #rect_image.save(outfile)
        new_img.save(outfile)

if name == ‘main‘:
# register all available parameters.
parser = argparse.ArgumentParser(usage=’please use unpacker.py -h to get usage information.’)
parser.add_argument(‘-plist’, help=’Specify the path of plist file.’, type=str)
parser.add_argument(‘-png’, help=’Specify the path of png file.’, type=str)
parser.add_argument(‘-dir’, help=’Specify a output directory.’, type=str)

# get parameters.
args = parser.parse_args()
plist_filename = args.plist
png_filename = args.png
output_dir = args.dir

# test whether the file/dir is None
if plist_filename is None:
    print 'make sure to use -plist to specify the plist file path.'
    sys.exit(1)
if png_filename is None:
    print 'make sure to use -png to specify the source png image.'
    sys.exit(1)

# test whether the file/dir exits
if not os.path.exists(plist_filename):
    print 'error: plist file doesn\'t exist.'
    sys.exit(1)
if not os.path.exists(png_filename):
    print 'error: png file doesn\'t exist.'
    sys.exit(1)
if output_dir is not None and not os.path.isdir(output_dir):
    print 'error: %s is no an valid directory or doesn\'t exist.' % output_dir
    sys.exit(1)

plist_parser = PlistParser(plist_filename, png_filename, output_dir)
plist_parser.split_png_from_plist()
print 'success.'
"""Small peices.--------------------------------------------------------------------------------------------------------------------------------------"""

# -*- coding:utf-8 -*-
"""
    This utility is used to parse plist file which is packed by Texture Packer to original images.
    usage:
        -plist specify the path of plist file(required parameter).
        -png specify the path of png file(required parameter).
        -dir specify a output directory(optional). By default, it will make a new directory named
             with plist filename in current directory to save images.
"""
 
from xml.etree import ElementTree
from PIL import Image
import argparse
import os
import sys
 
 
class PlistParser(object):
 
    # initializer
    def __init__(self, plist, png_image, output_dir):
        self.plist_file = plist
        self.png_file = png_image
        self.atlas_dir = output_dir
 
    # convert a xml tree to dict.
    def convert_tree_to_dict(self, tree):
        d = {}
        for index, item in enumerate(tree):
            if item.tag == 'key':
                if tree[index + 1].tag == 'string':
                    d[item.text] = tree[index + 1].text
                elif tree[index + 1].tag == 'true':
                    d[item.text] = True
                elif tree[index + 1].tag == 'false':
                    d[item.text] = False
                elif tree[index + 1].tag == 'dict':
                    d[item.text] = self.convert_tree_to_dict(tree[index + 1])
        return d
 
    # split png file into individual images.
    def split_png_from_plist(self):
        # generate output directory.
        target_file_dir = self.atlas_dir;
        if target_file_dir is None:
            target_file_dir = plist_filename.replace('.plist', '')
            if not os.path.isdir(target_file_dir):
                os.mkdir(target_file_dir)
 
        # open the source image.
        src_image = Image.open(png_filename)
        plist_content = open(plist_filename, 'r').read()
        plist_root = ElementTree.fromstring(plist_content)
        plist_dict = self.convert_tree_to_dict(plist_root[0])
 
        to_list = lambda x : x.replace('{', '').replace('}', '').split(',')
        for k, v in plist_dict['frames'].items():
            pos_str = str(v['frame'])
            rect_list = to_list(pos_str)
            width = int( rect_list[3] if v['rotated'] else rect_list[2] )
            height = int(rect_list[2] if v['rotated'] else rect_list[3] )
            bounding_box = (
                int(rect_list[0]),
                int(rect_list[1]),
                int(rect_list[0]) + width,
                int(rect_list[1]) + height,
            )
            size_list = [ int(x) for x in to_list(v['sourceSize']) ]
 
            rect_image = src_image.crop(bounding_box)
            if v['rotated']:
                rect_image = rect_image.rotate(90)
 
            outfile = os.path.join(target_file_dir, k)
            rect_image.save(outfile)
 
 
if __name__ == '__main__':
    # register all available parameters.
    parser = argparse.ArgumentParser(usage='please use unpacker.py -h to get usage information.')
    parser.add_argument('-plist', help='Specify the path of plist file.', type=str)
    parser.add_argument('-png', help='Specify the path of png file.', type=str)
    parser.add_argument('-dir', help='Specify a output directory.', type=str)
 
    # get parameters.
    args = parser.parse_args()
    plist_filename = args.plist
    png_filename = args.png
    output_dir = args.dir
 
    # test whether the file/dir is None
    if plist_filename is None:
        print 'make sure to use -plist to specify the plist file path.'
        sys.exit(1)
    if png_filename is None:
        print 'make sure to use -png to specify the source png image.'
        sys.exit(1)
 
    # test whether the file/dir exits
    if not os.path.exists(plist_filename):
        print 'error: plist file doesn\'t exist.'
        sys.exit(1)
    if not os.path.exists(png_filename):
        print 'error: png file doesn\'t exist.'
        sys.exit(1)
    if output_dir is not None and not os.path.isdir(output_dir):
        print 'error: %s is no an valid directory or doesn\'t exist.' % output_dir
        sys.exit(1)
 
    plist_parser = PlistParser(plist_filename, png_filename, output_dir)
    plist_parser.split_png_from_plist()
    print 'success.'