c1_unity/Tools/tranexcel2/old_to_new.py
2023-04-03 11:04:31 +08:00

81 lines
2.3 KiB
Python

# -*- coding: UTF-8 -*-
"""
name_list: ["*id", "price", ...]
type_list: ["int", "string", "reward", ...]
type_mapping: {"reward": ["type:int", "id:int", "num:int"], ...}
export_color: [(r, g, b), (r, g, b), ...]
lang_color: [(r, g, b), (r, g, b), ...]
return:
["*id#r:int", "price#s:string", ...]
"""
def type_change(name_list, type_list, type_mapping, export_color, lang_color):
length = len(name_list)
new_type = []
for i in range(length):
required = get_required(export_color[i])
lang = get_lang(lang_color[i])
new_type.append('%s#%s' % (required, lang))
return new_type
def gen_type(type_str, type_mapping):
if type_str.startswith('[') and type_str.endswith(']'):
return "[%s]" % gen_type(type_str[1:-1], type_mapping)
elif type_str.startswith('['):
raise TypeError(type_str)
elif type_str in type_mapping:
return "%s@{%s}" % (type_str, ','.join(type_mapping[type_str]))
else:
return type_str
class TypeError(BaseException):
def __init__(self, ss):
self._ss = ss
def __str__(self):
return "type format error: %s" % self._ss
class ColorError(BaseException):
def __init__(self, rgb, usage):
self._rgb = rgb
self._usage = usage
def __str__(self):
return "unknown color(%s) for %s" % (self._rgb, self._usage)
def get_required(rgb):
if rgb in ((221, 8, 6), (255, 0, 0), (255, 153, 204)):
return 'required'
elif rgb in ((0, 100, 17), (255, 255, 255), (0, 0, 0), (0, 128, 0), (0, 128, 128), (150, 150, 150)):
return 'optional'
else:
raise ColorError(rgb, "required")
def get_lang(rgb):
if rgb in ((252, 243, 5), (255, 255, 0), (255, 255, 204)):
return 'both'
elif rgb in ((204, 255, 204), ):
return 'server'
elif rgb in ((162, 189, 144), (0, 0, 212), (0, 0, 255), (204, 204, 255)):
return 'client'
elif rgb in ((0, 0, 0), (255, 255, 255), (150, 150, 150)):
return 'none'
else:
raise ColorError(rgb, "language")
if __name__ == '__main__':
print type_change(["*id", "price", "else", "price2"], ["int", "[reward]", "[int]", "reward"], {
"reward": ["id:int", "type:int"],
},
[(255, 0, 0), (0, 100, 17), (221, 8, 6), (0, 0, 0)],
[(252, 243, 5), (204, 255, 204), (162, 189, 144), (255, 255, 255)])