def _load_file(self, file): """ Args: file (str): Returns: dict: """ with open(self.filepath(file), 'r', encoding='utf-8') as f: text = f.read() result = {} matched = re.findall('function \(\)(.*?)end[()]', text, re.S) if matched: # Most files are in this format """ pg = pg or {} slot0 = pg slot0.chapter_template = {} (function () ... end)() """ for func in matched: add = slpp.decode('{' + func + '}') result.update(add) elif text.startswith('pg'): # Old format """ pg = pg or {} pg.item_data_statistics = { ... } """ # or """ pg = pg or {} rawset(pg, "item_data_statistics", rawget(pg, "item_data_statistics") or { ... } """ text = '{' + text.split('{', 2)[2] result = slpp.decode(text) else: # Another format, just bare data """ _G.pg.expedition_data_template[...] = { ... } _G.pg.expedition_data_template[...] = { ... } ... """ text = '{' + text + '}' result = slpp.decode(text) return result
def load_lua(folder, file, prefix): with open(os.path.join(folder, file), 'r', encoding='utf-8') as f: text = f.read() print(f'Loading {file}') result = slpp.decode(text[prefix:]) print(f'{len(result.keys())} items loaded') return result
def load_lua(folder, file): with open(os.path.join(folder, file), 'r', encoding='utf-8') as f: text = f.read() print('Loading technology_data_template') text = '{' + text.split('\n', 2)[2] result = slpp.decode(text) print(f'{len(result.keys())} items loaded') return result
def load_lua_by_function(folder, file): with open(os.path.join(folder, file), 'r', encoding='utf-8') as f: text = f.read() print(f'Loading {file}') matched = re.findall('function \(\)(.*?)end\(\)', text, re.S) result = {} for func in matched: add = slpp.decode('{' + func + '}') result.update(add) print(f'{len(result.keys())} items loaded') return result
def extract(dic, word_list): """ Args: dic (dict): word_list (list[str]): """ global count for word, data in dic.items(): word = str(word) if data.get('this', False): new = word_list + [word] new = ''.join(new) count += 1 print(new) else: new = word_list + [word] extract(data, word_list=new) # CN server for result in re.findall('word_template = (.*?)return', text, re.DOTALL): pg = slpp.decode(result) extract(pg, word_list=[]) # Other server for result in re.findall('uv0\.{0,1}(.*?)end', text, re.DOTALL): pg = slpp.decode('{%s}' % result) extract(pg, word_list=[]) print(f'Total count: {count}')
def __init__(self, file): with open(file, 'r', encoding='utf-8') as f: text = f.read() print('Loading chapter_template') text = re.findall('pg.chapter_template = (.*?)$', text, re.DOTALL) self.data = slpp.decode(text[0])