def parse_player_detail_2(self, response, response_json): results = merge_dicts(*response_json[u'PlayerProfile']) # self.log(pprint.pformat(results)) details_dict = results[u'PlayerBio'][0] yield PlayerItem( nba_id = details_dict.get(u'Person_ID'), birth_date = dateutil.parser.parse(details_dict.get(u'Birthdate')).date(), school = details_dict.get(u'School'), )
def execute(graph, args, kwargs, distribute=False): unsatisfied = list(graph.nodes()) completed = [] while unsatisfied: satisfied = [node for node in unsatisfied if all(x in completed for x in graph.predecessors(node))] unsatisfied = [x for x in unsatisfied if x not in satisfied] for node in satisfied: preds = graph.predecessors(node) node_kwargs = merge_dicts(*([pred.result for pred in preds]+[kwargs])) res = node.func(**node_kwargs) node.result = res completed.extend(satisfied) return {x.name: x.result for x in completed if len(list(graph.successors(x))) == 0}
def step(self, update_dict): self.update_results(update_dict) satisfied = [node for node in self.unsatisfied if all(x in self.completed for x in self.graph.predecessors(node))] self.unsatisfied = [x for x in self.unsatisfied if x not in satisfied] for node in satisfied: preds = self.graph.predecessors(node) for pred in preds: print("task: {}, predecessor: {}, result: {}".format(node.name, pred.name, pred.result)) preds = self.graph.predecessors(node) node_kwargs = merge_dicts(*([pred.result for pred in preds] + [self.kwargs])) node.job_id = self.job_id yield (node, node_kwargs) self.completed.extend(satisfied)
def parse_team_detail_2(self, response, response_json): norm_response_json = merge_dicts(*response_json[u'TeamDetails']) details_dict = norm_response_json[u'Details'][0] yield TeamItem( nba_id = details_dict.get(u'Team_Id'), abbr = details_dict.get(u'Abbreviation'), city = details_dict.get(u'City'), nickname = details_dict.get(u'Nickname'), file_urls = [ 'http://stats.nba.com/media/img/teams/logos/{Abbreviation}_logo.svg'.format(**details_dict) ], arena = ArenaItem( name = details_dict.get(u'Arena'), capacity = details_dict.get(u'ArenaCapacity'), ) )
import os, sys from ast import literal_eval sys.path.append(os.path.join(os.path.dirname(__file__), 'common')) from common import utils, tilesets output_file = sys.argv[1] input_file = sys.argv[2] version_suffix = sys.argv[3] prefix = "." + os.path.splitext(os.path.basename(input_file))[0] char_table = utils.reverse_dict( utils.merge_dicts([ tilesets.get_tileset("MainSpecial"), tilesets.get_tileset("MainDialog"), tilesets.get_tileset("dakuten", override_offset=0x0) ])) try: with open(input_file, 'r', encoding="utf-8") as i, open(output_file, 'w') as o: term, prefixlen = literal_eval(i.readline().strip()) ptrs = [] version_check = "[{}]".format(version_suffix) for n, line in enumerate(i): if not line.startswith("[") or line.startswith(version_check): line = line.replace( version_check, "") # Not the best way to do it, but it's good enough
[True, False], None, None), 'Unknown10': ((0x20, 0x4EA4), 1, [None], [(35, 0x00)], [True], None, None), 'Terrain': ((0x23, 0x7A23), 1, [0xCB], [(None, None)], [False], None, None), 'Attacks': ((0x23, 0x7A80), 1, [0xCB], [(None, None)], [False], None, None), 'CharacterNames': ((0x21, 0x4000), 1, [0xCB], [(None, None)], [False], None, None), 'Unknown14': ((0x21, 0x461B), 1, [None], [(11, 0x00)], [True], None, None), 'Medarots': ((0x23, 0x4000), 1, [0xCB], [(None, None)], [False], None, None), }) tileset = utils.merge_dicts([ tilesets.get_tileset("MainDialog1", override_offset=0x0), tilesets.get_tileset("MainDialog2", override_offset=0x80), tilesets.get_tileset("Special", override_offset=0xE0) ]) kanji = tilesets.get_tileset("Kanji", override_offset=0x0) with open("./game/src/version/ptrlist_data.asm", "w") as datafile: datafile.write( f'INCLUDE "build/ptrlists/ptrlist_data_constants_{{GAMEVERSION}}.asm"\n\n' ) for l in list_map: addr, spp, term, fix_len, print_hex, null_indicator, data_prefix = list_map[ l] if isinstance(addr, tuple): bank = addr[0] addr = utils.rom2realaddr(addr)
if len(txt): result.append(0x4F) result.append(endcode) return result if __name__ == '__main__': # TODO: Set this up to take these as an argument arg1 = 'build' #output directory trans_dir = 'text/credits' output_dir = 'build' char_table = utils.merge_dicts([ utils.read_table( "scripts/res/medarot.tbl", reverse=True ), # FIXME: There are missing tileset mappings, for now just read medarot.tbl #utils.read_table("scripts/res/tileset_MainDialog.tbl", reverse=True), #utils.read_table("scripts/res/tileset_MainSpecial.tbl", reverse=True), #utils.read_table("scripts/res/dakuten.tbl", reverse=True), ]) char_table['\\'] = 0x4A if not os.path.exists(output_dir): os.makedirs(output_dir) #Reads from the text_tables.asm file to determine banks sections = ['Credits'] bank_size_max = 0x7FFF bank_map = {} with open('game/src/story/credits.asm', 'r') as txt_file: for line in txt_file: if line.startswith('SECTION'):
import os, sys from ast import literal_eval sys.path.append(os.path.join(os.path.dirname(__file__), 'common')) from common import utils if __name__ == '__main__': input_file = sys.argv[1] output_file = sys.argv[2] version_suffix = sys.argv[3] # This is actually a hack with how lists work # TODO: Tilesets are probably going to vary between lists, so this may break in the future char_table = utils.merge_dicts([ utils.read_table("scripts/res/tileset_MainDialog.tbl", reverse=True), utils.read_table("scripts/res/tileset_MainSpecial.tbl", reverse=True), utils.read_table("scripts/res/tileset_MenuText.tbl", reverse=True), utils.read_table("scripts/res/dakuten.tbl", reverse=True), ]) char_table2 = utils.merge_dicts([ char_table, utils.read_table("scripts/res/tileset_BoldLetters.tbl", reverse=True) ]) with open(output_file, 'wb') as o, open(input_file, 'r', encoding="utf-8") as i: length, term, padbyte = (int(x) if x.isdigit() else literal_eval(x) for x in i.readline().split("|")) char_table['\n'] = term char_table2['\n'] = term
#!/bin/python import os, sys from shutil import copyfile sys.path.append(os.path.join(os.path.dirname(__file__), 'common')) from common import utils, tilemaps if __name__ == '__main__': input_file = sys.argv[1] output_file = sys.argv[2] fname = os.path.splitext(os.path.basename(input_file))[0] char_table = utils.merge_dicts([ utils.read_table(tbl, reverse=True) for tbl in filter( None, utils.read_table("scripts/res/tilemap_tilesets.tbl", keystring=True)[fname].split(",")) ]) # 0xFE is a special character indicating a new line for tilemaps, it doesn't really belong in the tileset table but for this specifically it makes sense char_table['\n'] = 0xFE prebuilt = "game/tilemaps/{}.tmap".format(fname) if os.path.isfile(prebuilt): print("\tUsing prebuilt {}".format(prebuilt)) copyfile(prebuilt, output_file) os.utime(output_file, None) quit() with open(input_file, 'r', encoding='utf-8-sig') as f: mode = f.readline().strip()
import sys from collections import OrderedDict sys.path.append(os.path.join(os.path.dirname(__file__), 'common')) from common import utils, tilesets MAX_LENGTH = 0xffff rom_info = ([ ("baserom_kabuto.gbc", "kabuto", 0x20a0, 0x20c6, 0x20c6-0x20a0), ("baserom_kuwagata.gbc", "kuwagata", 0x20a0, 0x20c6, 0x20c6-0x20a0) ]) # [ROM File, Version Suffix, Text Table Bank Ptr, Address Ptr, Count] ptrs = open("./scripts/res/ptrs.tbl", "a+") table = utils.merge_dicts([ tilesets.get_tileset("MainDialog1", override_offset=0x0), tilesets.get_tileset("MainDialog2", override_offset=0x80), tilesets.get_tileset("Special", override_offset=0xE0) ]) kanji = tilesets.get_tileset("Kanji", override_offset=0x0) default_suffix = rom_info[0][1] ptrs.seek(0) name_table = {} for line in ptrs: n, p = line.strip().split("=") name_table[int(p, 16)] = n text_table_ptrs = {} texts = {} text_version_specific = {}
from common import utils list_map = ({ # 'Type' : (Start of Pointers, Terminator, Number of Items, Prefix Length) 'PartTypes': ((0x1, 0x750b), 0x50, 4, 0), 'Attributes': ((0x2, 0x7f03), 0x50, 28, 0), 'PartDescriptions': (0x7F234, 0x50, 50, 0), 'Skills': ((0x2, 0x7fc0), 0x50, 8, 0), 'Attacks': ((0x17, 0x76d2), 0x50, 19, 0), # Medarotters have a 3-byte prefix before the names 'Medarotters': ((0x17, 0x64e6), 0x50, 85, 3), }) tileset = utils.merge_dicts([ utils.read_table("scripts/res/tileset_MainDialog.tbl"), utils.read_table("scripts/res/tileset_MainSpecial.tbl"), utils.read_table("scripts/res/dakuten.tbl") ]) with open("baserom_kabuto.gb", "rb") as rom: for l in list_map: addr, term, n, prefixlen = list_map[l] if isinstance(addr, tuple): bank = addr[0] addr = utils.rom2realaddr(addr) else: bank = utils.real2romaddr(addr)[0] rom.seek(addr) with open('text/ptrlists/{}.txt'.format(l), 'w', encoding="utf-8") as output: output.write("{}\n".format(term)) ptrs = [utils.read_short(rom) for i in range(0, n)]
import os, sys from ast import literal_eval sys.path.append(os.path.join(os.path.dirname(__file__), 'common')) from common import utils if __name__ == '__main__': input_file = sys.argv[1] output_file = sys.argv[2] version_suffix = sys.argv[3] prefix = "." + os.path.splitext(os.path.basename(input_file))[0] char_table = utils.merge_dicts([ utils.read_table("scripts/res/tileset_MainSpecial.tbl", reverse=True), utils.read_table("scripts/res/dakuten.tbl", reverse=True), utils.read_table("scripts/res/tileset_MainDialog.tbl", reverse=True), ]) with open(input_file, 'r', encoding="utf-8") as i, open(output_file, 'w') as o: term, = (int(x) if x.isdigit() else literal_eval(x) for x in i.readline().strip().split("|")) char_table['\n'] = term ptrs = [] version_check = "[{}]".format(version_suffix) for n, line in enumerate(i): if not line.startswith("[") or line.startswith(version_check): line = line.replace( version_check,
#!/bin/python import csv import os import sys from collections import OrderedDict sys.path.append(os.path.join(os.path.dirname(__file__), 'common')) from common import utils, tilesets rom_info = [ ("baserom_parts_collection.gb", "parts_collection", 0x1e14, 0x1e24, 0x10) ] # [ROM File, Version Suffix, Text Table Bank Ptr, Address Ptr, Count] ptrs = open("./scripts/res/ptrs.tbl", "a+") table = utils.merge_dicts([ tilesets.get_tileset("MainSpecial"), tilesets.get_tileset("MainDialog"), tilesets.get_tileset("dakuten", override_offset=0x0) ]) ptrs.seek(0) name_table = {} for line in ptrs: n, p = line.strip().split("=") name_table[int(p, 16)] = n for info in rom_info: filename = info[0] suffix = info[1] txt_bank_ptr = info[2] txt_tbl_ptr = info[3] entry_count = info[4]
ptrfile = None ptrtable = {} tileset_file = None tileset_table = {} tiletables = {} if os.path.exists("scripts/res/meta_tilemap_files.tbl"): ptrtable = utils.read_table("scripts/res/meta_tilemap_files.tbl") else: ptrfile = open("scripts/res/meta_tilemap_files.tbl", "w") # Load previously generated/manually written tilemap <-> tileset mapping tileset_default = utils.merge_dicts([ tilesets.get_tileset("MainDialog"), tilesets.get_tileset("MainSpecial"), ]) tileset_default[ 0xFE] = '\n' # 0xFE is a special control code for a new line, not really a tile if os.path.exists("scripts/res/meta_tilemap_tilesets.tbl"): tileset_table = utils.read_table( "scripts/res/meta_tilemap_tilesets.tbl", keystring=True) for fname in tileset_table: if tileset_table[fname] not in tiletables: tiletables[tileset_table[fname]] = utils.merge_dicts([ utils.merge_dicts([ tilesets.get_tileset(tbl) for tbl in filter( None, tileset_table[fname].split(",")) ]) ])
ptrfile = None if os.path.exists("scripts/res/tilemap_files.tbl"): ptrtable = utils.read_table("scripts/res/tilemap_files.tbl") else: ptrfile = open("scripts/res/tilemap_files.tbl","w") # Load previously generated/manually written tilemap <-> tileset mapping tileset_file = None tilesets = {} tiletables = {} tileset_default = utils.read_table("scripts/res/tileset_MainDialog.tbl") if os.path.exists("scripts/res/tilemap_tilesets.tbl"): tilesets = utils.read_table("scripts/res/tilemap_tilesets.tbl", keystring=True) for fname in tilesets: if tilesets[fname] not in tiletables: tiletables[tilesets[fname]] = utils.merge_dicts([utils.read_table(tbl) for tbl in filter(None, tilesets[fname].split(","))]) tiletables[tilesets[fname]][0xFE] = '\n' # 0xFE is a special control code for a new line, not really a tile else: tileset_file = open("scripts/res/tilemap_tilesets.tbl","w") try: for i in sorted(tilemap_ptr): ptr = tilemap_ptr[i] addr = BASE_ADDR + ptr - BANK_SIZE rom.seek(addr) compressed = utils.read_byte(rom) assert compressed in [0x0, 0x1], "Unexpected compression byte 0x{:02x}".format(compressed) print("{:02x} @ [{:04X} / {:08X}] {} | ".format(i, ptr, rom.tell()-1, "Compressed" if compressed else "Uncompressed"), end="") tilemap_bytes[i] = list(iter(partial(utils.read_byte, rom), 0xFF)) # Read ROM until 0xFF # tilemaps are all adjacent to each other, so we don't need to do anything more than make sure they're sorted fname = "Tilemap_{:04X}".format(ptr) if i not in ptrtable else ptrtable[i]