def dumpItemLocs(locsItems, sqlFile): for (location, item) in locsItems.items(): if item == 'Boss': continue # we can't have special chars in columns names location = removeChars(location, " ,()-") sql = "insert into item_locs (ext_id, item, {}) values (@last_id, '%s', 1) on duplicate key update {} = {} + 1;\n".format(location, location, location) sqlFile.write(sql % (item,))
def loadMusics(self): musics = self.cache.ram('musics', lambda: dict(), time_expire=None) if musics: return musics hiddenGroups = [ "Vanilla Soundtrack - Sound Effects", "Memory Violation" ] musicDir = 'music/_metadata' dropdown = defaultdict(list) metadatas = sorted(os.listdir(musicDir), key=lambda v: v.upper()) for metadata in metadatas: with open(os.path.join(musicDir, metadata), 'r', encoding='utf-8') as jsonFile: data = json.load(jsonFile) defaultGroup = os.path.splitext(metadata)[0] musics.update(data) # check if there's group for musics for song, songData in data.items(): group = songData.get("group", defaultGroup) if group in hiddenGroups: continue dropdown[group].append(song) musics["_dropdown"] = dropdown with open('music/_metadata/vanilla.json', 'r', encoding='utf-8') as jsonFile: vanilla = json.load(jsonFile) with open('music/_constraints/vanilla.json', 'r', encoding='utf-8') as jsonFile: constraints = json.load(jsonFile) musics["_list"] = [(song, removeChars(song, " ,()-/")) for song in vanilla.keys() if song not in constraints["preserve"] and song not in constraints["discard"]] return musics
def apNameInternal2Web(self, apName): return apName[0].lower() + removeChars(apName[1:], " ")
def locNameInternal2Web(self, locName): return removeChars(locName, " ,()-")
def transition2isolver(self, transition): transition = str(transition) return transition[0].lower() + removeChars(transition[1:], " ,()-")
def name4isolver(self, locName): # remove space and special characters # sed -e 's+ ++g' -e 's+,++g' -e 's+(++g' -e 's+)++g' -e 's+-++g' return removeChars(locName, " ,()-")
def readRooms(romFileName): romFile = RealROM(romFileName) for roomInfo in rooms: romFile.seek(roomInfo['Address']) data = romFile.read(RoomHeader.Size) roomInfo['RoomIndex'] = data[RoomHeader.RoomIndex] roomInfo['Area'] = data[RoomHeader.Area] roomInfo['MapX'] = data[RoomHeader.MapX] roomInfo['MapY'] = data[RoomHeader.MapY] roomInfo['Width'] = data[RoomHeader.Width] roomInfo['Height'] = data[RoomHeader.Height] roomInfo['UpScroller'] = data[RoomHeader.UpScroller] roomInfo['DownScroller'] = data[RoomHeader.DownScroller] roomInfo['SpecialGfxBitflag'] = data[RoomHeader.SpecialGfxBitflag] roomInfo['DoorsPtr'] = snes_to_pc( concatBytes(data[RoomHeader.DoorsPtr1], data[RoomHeader.DoorsPtr2], 0x8F)) #print("") #print("{} ({}) ({} x {}) in area: {}".format(roomInfo['Name'], hex(roomInfo['Address']), hex(roomInfo['Width']), hex(roomInfo['Height']), Areas.id2name[roomInfo['Area']])) readDoorsPtrs(romFile, roomInfo) readDoorsData(romFile, roomInfo) roomsGraph = {} for roomInfo in rooms: nodeName = removeChars(roomInfo['Name'], "][ '-") address = roomInfo['Address'] & 0xFFFF roomsGraph[address] = { 'Name': nodeName, 'Area': roomInfo['Area'], 'Width': roomInfo['Width'], 'Height': roomInfo['Height'], 'Doors': {} } for doorData in roomInfo["DoorData"]: roomsGraph[address]['Doors'][doorData['doorPtr']] = { 'roomPtr': doorData['roomPtr'], 'exitScreenX': doorData['screenX'], 'exitScreenY': doorData['screenY'], 'exitDirection': doorData['direction'] } # get screen data from corresponding door for (entryRoomAddress, entryRoom) in roomsGraph.items(): for entryDoorData in entryRoom["Doors"].values(): exitRoomAddress = entryDoorData['roomPtr'] exitRoom = roomsGraph[exitRoomAddress] found = False for exitDoorData in exitRoom['Doors'].values(): #if entryRoom['Name'] in ['GrappleTutorialRoom1', 'GrappleBeamRoom']: #print("entry doors count: {} exit doors count: {}".format(len(entryRoom["Doors"]), len(exitRoom['Doors']))) #print("{}/{} -> {}/{} ({})".format(entryRoom['Name'], hex(entryRoomAddress), exitRoom['Name'], hex(exitDoorData['roomPtr']), roomsGraph[exitDoorData['roomPtr']]['Name'])) if exitDoorData['roomPtr'] == entryRoomAddress: #if entryRoom['Name'] in ['GrappleTutorialRoom1', 'GrappleBeamRoom']: #print("exitDoorData['roomPtr'] {} == entryRoomAddress {}".format(hex(exitDoorData['roomPtr']), hex(entryRoomAddress))) for entryDoorData in entryRoom['Doors'].values(): if entryDoorData['roomPtr'] == exitRoomAddress: entryDoorData['entryScreenX'] = exitDoorData[ 'exitScreenX'] entryDoorData['entryScreenY'] = exitDoorData[ 'exitScreenY'] entryDoorData['entryDirection'] = exitDoorData[ 'exitDirection'] found = True #else: #if entryRoom['Name'] in ['GrappleTutorialRoom1', 'GrappleBeamRoom']: #print("exitDoorData['roomPtr'] {} != entryRoomAddress {}".format(hex(exitDoorData['roomPtr']), hex(entryRoomAddress))) #if found == False: #print("door not found ({} -> {})".format(entryRoom['Name'], exitRoom['Name'])) #print("-----------------------------------------------------------------------------") #print(roomsGraph) print("""digraph { size="30,30!"; graph [overlap=orthoxy, splines=false, nodesep="1"]; node [shape="plaintext",fontsize=30]; edge [color="#0025fa80"]; """) for (address, roomInfo) in roomsGraph.items(): if roomInfo['Area'] == Areas.Tourian: src = roomInfo['Name'] print("{} [label = {}];".format( roomInfo['Name'], genLabel(roomInfo['Name'], roomInfo["Width"], roomInfo["Height"]))) for doorData in roomInfo["Doors"].values(): dstInfo = roomsGraph[doorData['roomPtr']] dst = dstInfo['Name'] print("{}:x{}{}:{} -> {}:x{}{}:{};".format( src, doorData.get('entryScreenX'), doorData.get('entryScreenY'), getDir(doorData.get('entryDirection')), dst, doorData.get('exitScreenX'), doorData.get('exitScreenY'), getDir(doorData.get('exitDirection')))) print("}")
def locName4isolver(locName): # remove space and special characters # sed -e 's+ ++g' -e 's+,++g' -e 's+(++g' -e 's+)++g' -e 's+-++g' locName = str(locName) return locName[0].lower() + removeChars(locName[1:], " ,()-")
tracksTable[addr]["nspc_md5sum"] = [md5sum] if nspcData[1] is not None: md5sum = getMd5Sum(nspcData[1]) tracksTable[addr]["nspcData"].append(nspcData[1]) tracksTable[addr]["nspc_md5sum"].append(md5sum) # index by md5sum allTracksMd5 = {} for songName, data in allTracks.items(): allTracksMd5[nspcMeta[data["nspc_path"]]["md5sum"]] = songName playlist = {} for data in tracksTable.values(): md5sums = data["nspc_md5sum"] if md5sums[0] in allTracksMd5 or (len(md5sums) > 1 and md5sums[1] in allTracksMd5): md5sum = md5sums[0] if md5sums[0] in allTracksMd5 else md5sums[1] #print("$%02x %s replaced with: %s" % (data["dataId"], data["trackName"], allTracksMd5[md5sum])) playlist[removeChars(data["trackName"], ' ,()-/')] = allTracksMd5[md5sum] else: print(" Warning: replacement not found for {} - {} - {}".format( hex(data["dataId"]), data["trackName"], data["nspc_md5sum"])) playlistName = sys.argv[1][:-4] + '.json' with open(playlistName, 'w') as f: json.dump(playlist, f, indent=4) print("playlist generated: {}".format(playlistName))