def readFromProject(self, resourceOpener):
     for logo in self._logos:
         logo.readFromProject(resourceOpener)
         updateProgress(self._pct)
     for map in self._townmaps:
         map.readFromProject(resourceOpener)
         updateProgress(self._pct)
Exemple #2
0
 def writeToRom(self, rom):
     self._ptrTbl.clear(32*40)
     destWriteLoc = 0xF0000
     destRangeEnd = 0xF58EE # TODO Is this correct? Can we go more?
     destLocs = dict()
     emptyEntryPtr = EbModule.toSnesAddr(rom.writeToFree([0, 0]))
     pct = 45.0/(40*32)
     i=0
     for entry in self._entries:
         if (entry == None) or (not entry):
             self._ptrTbl[i,0].setVal(emptyEntryPtr)
         else:
             entryLen = len(entry)
             writeLoc = rom.getFreeLoc(2 + entryLen*5)
             self._ptrTbl[i,0].setVal(EbModule.toSnesAddr(writeLoc))
             rom[writeLoc] = entryLen & 0xff
             rom[writeLoc+1] = entryLen >> 8
             writeLoc += 2
             for door in entry:
                 destWriteLoc += door.writeToRom(rom, writeLoc, destWriteLoc,
                         destRangeEnd, destLocs)
                 writeLoc += 5
         i += 1
         updateProgress(pct)
     self._ptrTbl.writeToRom(rom)
     # Mark any remaining space as free
     if destWriteLoc < destRangeEnd:
         rom.addFreeRanges([(destWriteLoc, destRangeEnd)])
     updateProgress(5)
Exemple #3
0
    def readFromRom(self, rom):
        for f in self._fonts:
            f.readFromRom(rom)
            updateProgress(self._pct)

        self.readCreditsFontFromRom(rom)
        updateProgress(self._pct)
    def writeToRom(self, rom):
        if self._data["Enable Skip"]:
            rom[0x1faae] = 0x5c
            loc = rom.getFreeLoc(10 + 4*5*5 + 3*6*5)
            rom.writeMulti(0x1faaf, EbModule.toSnesAddr(loc), 3)
            rom.write(loc, [0x48, 0x08, 0xe2, 0x20])
            loc += 4

            loc = self.writeLoaderAsm(rom, loc, self._data["Name1"], 5, 0xce,
                    0x99)
            loc = self.writeLoaderAsm(rom, loc, self._data["Name2"], 5, 0x2d,
                    0x9a)
            loc = self.writeLoaderAsm(rom, loc, self._data["Name3"], 5, 0x8c,
                    0x9a)
            loc = self.writeLoaderAsm(rom, loc, self._data["Name4"], 5, 0xeb,
                    0x9a)
            loc = self.writeLoaderAsm(rom, loc, self._data["Pet"], 6, 0x19, 0x98)
            loc = self.writeLoaderAsm(rom, loc, self._data["Food"], 6, 0x1f,
                    0x98)
            loc = self.writeLoaderAsm(rom, loc, self._data["Thing"], 6, 0x29,
                    0x98)

            if self._data["Enable Summary"]:
                rom.write(loc, [0x28, 0x68, 0x5c, 0xc0, 0xfa, 0xc1])
            else:
                rom.write(loc, [0x28, 0x68, 0x5c, 0x05, 0xfd, 0xc1])
        updateProgress(50)
 def writeToProject(self, resourceOpener):
     for logo in self._logos:
         logo.writeToProject(resourceOpener)
         updateProgress(self._pct)
     for map in self._townmaps:
         map.writeToProject(resourceOpener)
         updateProgress(self._pct)
Exemple #6
0
 def writeToRom(self, rom):
     map_ptrs_addr = \
         EbModule.toRegAddr(rom.readMulti(self._MAP_PTRS_PTR_ADDR, 3))
     map_addrs = map(lambda x: \
         EbModule.toRegAddr(rom.readMulti(map_ptrs_addr+x*4,4)), \
         range(8))
     for i in range(self._MAP_HEIGHT):
         rom.write(map_addrs[i%8] + ((i>>3)<<8), map(lambda x: x & 0xff,
             self._tiles[i]))
     k = self._LOCAL_TSET_ADDR
     for i in range(self._MAP_HEIGHT>>3):
         for j in range(self._MAP_WIDTH):
             c = ((self._tiles[i<<3][j] >> 8)
                     | ((self._tiles[(i<<3)|1][j] >> 8) << 2)
                     | ((self._tiles[(i<<3)|2][j] >> 8) << 4)
                     | ((self._tiles[(i<<3)|3][j] >> 8) << 6))
             rom.write(k, c)
             c = ((self._tiles[(i<<3)|4][j] >> 8)
                     | ((self._tiles[(i<<3)|5][j] >> 8) << 2)
                     | ((self._tiles[(i<<3)|6][j] >> 8) << 4)
                     | ((self._tiles[(i<<3)|7][j] >> 8) << 6))
             rom.write(k+0x3000, c)
             k += 1
     updateProgress(25)
     # Write sector data
     self._mapSecTsetPalsTbl.writeToRom(rom)
     updateProgress(25.0/4)
     self._mapSecMusicTbl.writeToRom(rom)
     updateProgress(25.0/4)
     self._mapSecMiscTbl.writeToRom(rom)
     updateProgress(25.0/4)
     self._mapSecTownMapTbl.writeToRom(rom)
     updateProgress(25.0/4)
 def writeToProject(self, resourceOpener):
     out = dict()
     x = y = 0
     rowOut = dict()
     pct = 45.0/(40*32)
     for entry in self._entries:
         if entry != None:
             rowOut[x%32] = map(
                     lambda sp: {
                         "NPC ID": sp.npcID,
                         "X": sp.x,
                         "Y": sp.y },
                     entry)
         else:
             rowOut[x%32] = None
         if (x % 32) == 31:
             # Start next row
             out[y] = rowOut
             x = 0
             y += 1
             rowOut = dict()
         else:
             x += 1
         updateProgress(pct)
     with resourceOpener("map_sprites", "yml") as f:
         yaml.dump(out, f, Dumper=yaml.CSafeDumper)
     updateProgress(5)
Exemple #8
0
    def writeToRom(self, rom):
        for ipsDescFname in [s for s in os.listdir(
            'resources/ips/' + rom.type()) if s.lower().endswith(".yml")]:
            patchName = ipsDescFname[:-4]
            with open('resources/ips/' + rom.type() + '/' + ipsDescFname) as ipsDescFile:
                ipsDesc = yaml.load(ipsDescFile, Loader=yaml.CSafeLoader)
                if ((ipsDesc["Title"] in self._patches) and
                        (self._patches[ipsDesc["Title"]].lower() == "enabled")):
                    ranges = map(lambda y: tuple(map(lambda z: int(z, 0),
                        y[1:-1].split(','))), ipsDesc["Ranges"])

                    # First, check that we can apply this
                    for range in ranges:
                        if not rom.isRangeFree(range):
                            # Range is not free, can't apply
                            raise RuntimeError("Can't apply patch \"" +
                                ipsDesc["Title"] + "\", range (" +
                                hex(range[0]) + "," +  hex(range[1]) +
                                ") is not free")
                    # Now apply the patch
                    patchName = ipsDescFname[:-4]
                    ips = Ips()
                    offset = 0
                    if "Header" in ipsDesc:
                        offset = ipsDesc["Header"]
                    ips.load('resources/ips/' + rom.type() + '/' + patchName + '.ips',
                            offset)
                    ips.apply(rom)
                    # Mark the used ranges as used
                    for range in ranges:
                        rom.markRangeAsNotFree(range)
        updateProgress(50)
Exemple #9
0
 def readFromProject(self, resourceOpener):
     # Read map data
     with resourceOpener("map_tiles", "map") as f:
         self._tiles = map(lambda y:
                 map(lambda x: int(x, 16), y.split(" ")),
                 f.readlines())
     updateProgress(25)
     # Read sector data
     self._mapSecTsetPalsTbl.clear(2560)
     self._mapSecMusicTbl.clear(2560)
     self._mapSecMiscTbl.clear(2560)
     self._mapSecTownMapTbl.clear(2560)
     pct = (25.0/2560)
     with resourceOpener("map_sectors", "yml") as f:
         input = yaml.load(f, Loader=yaml.CSafeLoader)
         for i in input:
             entry = input[i]
             self._mapSecTsetPalsTbl[i,0].setVal(
                     (entry["Tileset"] << 3) | entry["Palette"])
             self._mapSecMusicTbl[i,0].load(entry["Music"])
             self._mapSecMiscTbl[i,1].load(entry["Item"])
             self.teleport.load(entry["Teleport"])
             self.townmap.load(entry["Town Map"])
             self.setting.load(entry["Setting"])
             self._mapSecMiscTbl[i,0].setVal((self.teleport.val() << 7)
                     | (self.townmap.val() << 3) | self.setting.val())
             self.townmap_image.load(entry["Town Map Image"])
             self.townmap_arrow.load(entry["Town Map Arrow"])
             self._mapSecTownMapTbl[i,0].setVal(
                     (self.townmap_arrow.val() << 4) |
                     (self.townmap_image.val() & 0xf))
             self._mapSecTownMapTbl[i,1].load(entry["Town Map X"])
             self._mapSecTownMapTbl[i,2].load(entry["Town Map Y"])
             updateProgress(pct)
    def readFromProject(self, resourceOpener):
        self._grPalTbl.readFromProject(resourceOpener)
        updateProgress(5)
        input = yaml.load(resourceOpener("sprite_groups", "yml"),
                Loader=yaml.CSafeLoader)
        numGroups = len(input)
        self._groups = []
        pct = 45.0/numGroups
        for i in range(numGroups):
            g = SpriteGroup(16)
            g.load(input[i])
            img = Image.open(
                    resourceOpener("SpriteGroups/" + str(i).zfill(3), "png"))
            g.fromImage(img)
            palData = img.getpalette()
            del(img)
            self._groups.append(g)
            pal = [ ]

            # Read the palette from the image
            for i in range(1, 16):
                pal.append((palData[i*3], palData[i*3+1], palData[i*3+2]))
            # Assign the palette number to the sprite
            for i in range(8):
                if pal == self._grPalTbl[i,0].val()[1:]:
                    g.setPalette(i)
                    break
            else:
                # Error, this image uses an invalid palette
                raise RuntimeException("Sprite Group #" + i
                        + "uses an invalid palette.")
            updateProgress(pct)
Exemple #11
0
 def writeToProject(self, resourceOpener):
     out = dict()
     x = y = 0
     rowOut = dict()
     pct = 45.0/(40*32)
     for entry in self._entries:
         if not entry:
             rowOut[x%32] = None
         else:
             rowOut[x%32] = map(lambda z: z.dump(), entry)
         if (x % 32) == 31:
             # Start new row
             out[y] = rowOut
             x = 0
             y += 1
             rowOut = dict()
         else:
             x += 1
         updateProgress(pct)
     with resourceOpener("map_doors", "yml") as f:
         s = yaml.dump(out, default_flow_style=False, Dumper=yaml.CSafeDumper)
         s = sub("Event Flag: (\d+)",
                 lambda i: "Event Flag: " + hex(int(i.group(0)[12:])), s)
         f.write(s)
     updateProgress(5)
Exemple #12
0
 def writeToRom(self, rom):
     self._ptrTbl.clear(20)
     blockSize = 0
     for entry in self._entries:
         for (flag, set) in entry:
             blockSize += 4 + 4*len(set)
         blockSize += 2
     if blockSize > 0xffff:
         raise RuntimeError("Too many map changes")
     loc = rom.getFreeLoc(blockSize)
     rom[self._PTR_BANK_LOC] = (loc >> 16) + 0xc0
     i = 0
     for entry in self._entries:
         self._ptrTbl[i,0].setVal(loc & 0xffff)
         for (flag, set) in entry:
             rom.writeMulti(loc, flag, 2)
             rom.writeMulti(loc+2, len(set), 2)
             loc += 4
             for (before, after) in set:
                 rom.writeMulti(loc, before, 2)
                 rom.writeMulti(loc+2, after, 2)
                 loc += 4
         rom[loc] = 0
         rom[loc+1] = 0
         loc += 2
         i += 1
         updateProgress(45.0/20)
     ptrTblLoc = self._ptrTbl.writeToFree(rom)
     rom.writeMulti(self._PTR_LOC, EbModule.toSnesAddr(ptrTblLoc), 3)
     updateProgress(5)
 def writeToRom(self, rom):
     for logo in self._logos:
         logo.writeToRom(rom)
         updateProgress(self._pct)
     for map in self._townmaps:
         map.writeToRom(rom)
         updateProgress(self._pct)
Exemple #14
0
 def readFromRom(self, rom):
     for (cat, items) in self.ENTRY_LOCS:
         catDict = {}
         for (desc, loc, size) in items:
             catDict[desc] = SmbModule.readText(rom, loc, size)
         self._data[cat] = catDict
         updateProgress(self._pct)
Exemple #15
0
 def readFromProject(self, resourceOpener):
     i=0
     pct = 45.0/len(self._tsets)
     for tset in self._tsets:
         with resourceOpener('Tilesets/' + str(i).zfill(2), 'fts') as f:
             tset.readFromFTS(f)
         i += 1
         updateProgress(pct)
     with resourceOpener('map_palette_settings', 'yml') as f:
         input = yaml.load(f, Loader=yaml.CSafeLoader)
         for mtset in input: # For each map tileset
             # Get the draw (normal) tileset
             tset = None
             for ts in self._tsets:
                 if ts.hasMapTileset(mtset):
                     tset = ts
                     break
             # For each map palette
             mtset_pals = [(mp,p) for (mt,mp,p) in tset.pals if mt == mtset]
             for (pN,mtset_pal) in mtset_pals:
                 entry = input[mtset][pN]
                 mtset_pal.flag = entry["Event Flag"]
                 mtset_pal.flashEffect = entry["Flash Effect"]
                 mtset_pal.spritePalNum = entry["Sprite Palette"]
                 if mtset_pal.flag != 0:
                     mtset_pal.flagPal = MapPalette()
                     mtset_pal.flagPal.setFromString(entry["Event Palette"])
                     mtset_pal.flagPal.spritePalNum = entry["Sprite Palette"]
             updateProgress(5.0/32)
 def readFromRom(self, rom):
     for logo in self._logos:
         logo.readFromRom(rom)
         updateProgress(self._pct)
     for map in self._townmaps:
         map.readFromRom(rom)
         updateProgress(self._pct)
Exemple #17
0
    def writeToProject(self, resourceOpener):
        # Dump an additional YML with color0 data
        out = dict()
        for i in range(0,32): # For each map tset
            entry = dict()
            tset = None
            for ts in self._tsets:
                if ts.hasMapTileset(i):
                    tset = ts
                    break
            for (pN,p) in [(mp,p) for (mt,mp,p) in tset.pals if mt == i]:
                entry[pN] = p.dump()
            out[i] = entry
        with resourceOpener('map_palette_settings', 'yml') as f:
            s = yaml.dump(out, default_flow_style=False,
                    Dumper=yaml.CSafeDumper)
            s = sub("Event Flag: (\d+)",
                    lambda i: "Event Flag: " + hex(int(i.group(0)[12:])), s)
            f.write(s)
        updateProgress(5)

        # Dump the FTS files
        pct=45.0/len(self._tsets)
        i=0
        for tset in self._tsets:
            with resourceOpener('Tilesets/' + str(i).zfill(2), 'fts') as f:
                tset.writeToFTS(f)
            i += 1
            updateProgress(pct)
    def readFromProject(self, resourceOpener):
        # Clear the labels dict
        EbModule.labelsDict.clear()
        # Read the summary file
        sumFile = resourceOpener('ccscript/summary', 'txt')
        summary = sumFile.readlines()
        sumFile.close()
        # Only do anything if the summary file is not empty
        if len(summary) > 0:
            self._usedRange = (EbModule.toRegAddr(int(summary[7][30:36], 16)),
                    EbModule.toRegAddr(int(summary[8][30:36], 16)))

            modName = None
            inModuleSection = False # False = before section, True = in section
            for line in summary:
                line = line.rstrip()
                if inModuleSection:
                    if line.startswith('-'):
                        inModuleSection = False
                    else:
                        labelKey = modName + "." + line.split(' ',1)[0]
                        labelVal = int(line[-6:],16)
                        EbModule.labelsDict[labelKey] = labelVal
                elif line.startswith("-") and modName != None:
                    inModuleSection = True
                elif line.startswith("Labels in module "):
                    modName = line[17:]
        updateProgress(50)
Exemple #19
0
 def readFromRom(self, rom):
     # Read map tiles
     map_ptrs_addr = \
         EbModule.toRegAddr(rom.readMulti(self._MAP_PTRS_PTR_ADDR, 3))
     map_addrs = map(lambda x: \
         EbModule.toRegAddr(rom.readMulti(map_ptrs_addr+x*4,4)), \
         range(8))
     self._tiles = map(
             lambda y: rom.readList(map_addrs[y%8] + ((y>>3)<<8),
                 self._MAP_WIDTH).tolist(),
             range(self._MAP_HEIGHT))
     k = self._LOCAL_TSET_ADDR
     for i in range(self._MAP_HEIGHT>>3):
         for j in range(self._MAP_WIDTH):
             self._tiles[i<<3][j] |= (rom[k] & 3) << 8
             self._tiles[(i<<3)|1][j] |= ((rom[k] >> 2) & 3) << 8
             self._tiles[(i<<3)|2][j] |= ((rom[k] >> 4) & 3) << 8
             self._tiles[(i<<3)|3][j] |= ((rom[k] >> 6) & 3) << 8
             self._tiles[(i<<3)|4][j] |= (rom[k+0x3000] & 3) << 8
             self._tiles[(i<<3)|5][j] |= ((rom[k+0x3000] >> 2) & 3) << 8
             self._tiles[(i<<3)|6][j] |= ((rom[k+0x3000] >> 4) & 3) << 8
             self._tiles[(i<<3)|7][j] |= ((rom[k+0x3000] >> 6) & 3) << 8
             k += 1
     updateProgress(25)
     # Read sector data
     self._mapSecTsetPalsTbl.readFromRom(rom)
     updateProgress(25.0/4)
     self._mapSecMusicTbl.readFromRom(rom)
     updateProgress(25.0/4)
     self._mapSecMiscTbl.readFromRom(rom)
     updateProgress(25.0/4)
     self._mapSecTownMapTbl.readFromRom(rom)
     updateProgress(25.0/4)
Exemple #20
0
    def readFromProject(self, resourceOpener):
        # First, read the Enemy Configuration Table
        self._enemyCfgTable.readFromProject(resourceOpener)
        pct = 40.0/(self._enemyCfgTable.height())

        # Second, read the Battle Sprites
        bsHashes = dict()
        bsNextNum = 1
        palNextNum = 0
        for i in range(self._enemyCfgTable.height()):
            bs = EbBattleSprite()
            pal = EbPalettes(1,16)
            try:
                bs.readFromProject(resourceOpener, i, pal)
                # Add the battle sprite
                try:
                    #self._enemyCfgTable[i,4].set(self._bsprites.index(bs))
                    bsNum = bsHashes[bs._sprite._spriteHash]
                    self._enemyCfgTable[i,4].setVal(bsNum)
                except KeyError:
                    self._bsprites.append(bs)
                    self._enemyCfgTable[i,4].setVal(bsNextNum)
                    bsHashes[bs._sprite._spriteHash] = bsNextNum
                    bsNextNum += 1
                # Add the palette
                # TODO should probably use hash table here too?
                #      then again, I don't think it's actually a bottleneck
                try:
                    self._enemyCfgTable[i,14].setVal(self._bsPals.index(pal))
                except ValueError:
                    self._bsPals.append(pal)
                    self._enemyCfgTable[i,14].setVal(palNextNum)
                    palNextNum += 1
            except IOError:
                # No battle sprite PNG
                self._enemyCfgTable[i,4].setVal(0)
                self._enemyCfgTable[i,14].setVal(0)
            updateProgress(pct)

        # Third, read the groups
        self._enemyGroupTbl.readFromProject(resourceOpener, "enemy_groups")
        updateProgress(2)
        self._enemyGroupBgTbl.readFromProject(resourceOpener, "enemy_groups")
        updateProgress(2)
        self._enemyGroups = [ ]
        pct = 4.0/484
        with resourceOpener("enemy_groups", "yml") as f:
            input = yaml.load(f, Loader=yaml.CSafeLoader)
            updateProgress(2)
            for group in input:
                tmp1 = input[group]["Enemies"]
                enemyList = [ ]
                i = 0
                for enemy in tmp1:
                    tmp2 = tmp1[i]
                    enemyList.append((tmp2["Enemy"], tmp2["Amount"]))
                    i += 1
                self._enemyGroups.append(enemyList)
                updateProgress(pct)
Exemple #21
0
 def writeToRom(self, rom):
     for (cat, items) in self.ENTRY_LOCS:
         catDict = self._data[cat]
         for (desc, loc, size) in items:
             EbModule.writeStandardText(rom, loc, catDict[desc], size)
             if (cat == "Status Window") and (len(catDict[desc]) < size):
                 rom.write(loc+len(catDict[desc]),
                         [00] * (size-len(catDict[desc])))
         updateProgress(self._pct)
    def upgradeProject(self, oldVersion, newVersion, rom, resourceOpenerR,
            resourceOpenerW):
        def replaceField(fname, oldField, newField, valueMap):
            if newField == None:
                newField = oldField
            valueMap = dict((k, v) for k,v in valueMap.iteritems())
            with resourceOpenerR(fname, 'yml') as f:
                data = yaml.load(f, Loader=yaml.CSafeLoader)
                for i in data:
                    if data[i][oldField] in valueMap:
                        data[i][newField] = valueMap[data[i][oldField]].lower()
                    else:
                        data[i][newField] = data[i][oldField]
                    if newField != oldField:
                        del data[i][oldField]
            with resourceOpenerW(fname, 'yml') as f:
                yaml.dump(data, f, Dumper=yaml.CSafeDumper)
        def replaceFieldName(fname, oldField, newField):
            if newField == None:
                newField = oldField
            with resourceOpenerR(fname, 'yml') as f:
                data = yaml.load(f, Loader=yaml.CSafeLoader)
                for i in data:
                    data[i][newField] = data[i][oldField]
                    del data[i][oldField]
            with resourceOpenerW(fname, 'yml') as f:
                yaml.dump(data, f, Dumper=yaml.CSafeDumper)

        if oldVersion == newVersion:
            updateProgress(100)
            return
        elif oldVersion == 2:
            replaceField("sprite_groups",
                    "Unknown A", "Size",
                    { 0: "16x16",
                        1: "16x16 2",
                        2: "24x16",
                        3: "32x16",
                        4: "48x16",
                        5: "16x24",
                        6: "24x24",
                        7: "16x32",
                        8: "32x32",
                        9: "48x32",
                        10: "24x40",
                        11: "16x48",
                        12: "32x48",
                        13: "48x48",
                        14: "64x48",
                        15: "64x64",
                        16: "64x80" })
            replaceFieldName("sprite_groups", "Unknown B", "Collision Settings")
            self.upgradeProject(oldVersion+1, newVersion, rom, resourceOpenerR,
                    resourceOpenerW)
        elif oldVersion == 1:
            self.upgradeProject(oldVersion+1, newVersion, rom, resourceOpenerR,
                    resourceOpenerW)
Exemple #23
0
 def readFromProject(self, resourceOpener):
     with resourceOpener("map_music", "yml") as f:
         input = yaml.load(f, Loader=yaml.CSafeLoader)
         for i in input:
             entry = []
             for subEntry in input[i]:
                 entry.append((subEntry["Event Flag"],
                     subEntry["Music"]))
             self._entries.append(entry)
     updateProgress(50)
Exemple #24
0
 def readFromProject(self, resourceOpener):
     i = 0
     for font in self._fonts:
         with resourceOpener("Fonts/" + str(i), "png") as imgFile:
             img = Image.open(imgFile)
             font.fromImage(img)
         with resourceOpener("Fonts/" + str(i) + "_widths", "yml") as f:
             input = yaml.load(f, Loader=yaml.CSafeLoader)
             font.loadWidths(input)
         i += 1
         updateProgress(self._pct)
Exemple #25
0
    def writeToRom(self, rom):
        for f in self._fonts:
            f.writeToRom(rom)
            updateProgress(self._pct)

        self._cpal.writeToBlock(rom, loc=self._ADDR_CREDITS_PAL)
        with EbCompressedData(self._cfont.sizeBlock()) as cb:
            self._cfont.writeToBlock(cb)
            EbModule.writeAsmPointer(rom, self._ASMPTR_CREDITS_GFX,
                    EbModule.toSnesAddr(cb.writeToFree(rom)))
        updateProgress(self._pct)
Exemple #26
0
 def readFromProject(self, resourceOpener):
     with resourceOpener("map_changes", "yml") as f:
         input = yaml.load(f, Loader=yaml.CSafeLoader)
         for mtset in input:
             entry = []
             entryIn = input[mtset]
             if (entryIn != None):
                 for csetIn in entryIn:
                     entry.append((csetIn["Event Flag"],
                         csetIn["Changes"]))
             self._entries.append(entry)
             updateProgress(50.0/20)
Exemple #27
0
 def upgradeProject(self, oldVersion, newVersion, rom, resourceOpenerR,
         resourceOpenerW):
     if oldVersion == newVersion:
         updateProgress(100)
         return
     elif oldVersion <= 2:
         self.readCreditsFontFromRom(rom)
         self.writeCreditsFontToProject(resourceOpenerW)
         self.upgradeProject(3, newVersion, rom, resourceOpenerR,
                                     resourceOpenerW)
     else:
         self.upgradeProject(oldVersion+1, newVersion, rom, resourceOpenerR,
                                     resourceOpenerW)
Exemple #28
0
    def upgradeProject(self, oldVersion, newVersion, rom, resourceOpenerR,
            resourceOpenerW):
        global updateProgress
        def replaceField(fname, oldField, newField, valueMap):
            if newField == None:
                newField = oldField
            valueMap = dict((k, v) for k,v in valueMap.iteritems())
            with resourceOpenerR(fname, 'yml') as f:
                data = yaml.load(f, Loader=yaml.CSafeLoader)
                for i in data:
                    if data[i][oldField] in valueMap:
                        data[i][newField] = valueMap[data[i][oldField]].lower()
                    else:
                        data[i][newField] = data[i][oldField]
                    if newField != oldField:
                        del data[i][oldField]
            with resourceOpenerW(fname, 'yml') as f:
                yaml.dump(data, f, Dumper=yaml.CSafeDumper,
                        default_flow_style=False)

        if oldVersion == newVersion:
            updateProgress(100)
            return
        elif oldVersion <= 2:
            replaceField("map_sectors", "Town Map", None,
                    { "scummers": "summers" })

            # Need to add the Town Map Image/Arrow/X/Y fields
            tmp = updateProgress
            updateProgress = lambda x: None
            self.readFromRom(rom)
            updateProgress = tmp

            with resourceOpenerR("map_sectors", 'yml') as f:
                data = yaml.load(f, Loader=yaml.CSafeLoader)
                for i in data:
                    self.townmap_image.setVal(self._mapSecTownMapTbl[i,0].val() & 0xf)
                    self.townmap_arrow.setVal(self._mapSecTownMapTbl[i,0].val() >> 4)
                    data[i]["Town Map Image"] = self.townmap_image.dump()
                    data[i]["Town Map Arrow"] = self.townmap_arrow.dump()
                    data[i]["Town Map X"] = self._mapSecTownMapTbl[i,1].dump()
                    data[i]["Town Map Y"] = self._mapSecTownMapTbl[i,2].dump()
            with resourceOpenerW("map_sectors", 'yml') as f:
                yaml.dump(data, f, Dumper=yaml.CSafeDumper,
                        default_flow_style=False)

            self.upgradeProject(3, newVersion, rom, resourceOpenerR,
                    resourceOpenerW)
        else:
            self.upgradeProject(oldVersion+1, newVersion, rom, resourceOpenerR,
                                                            resourceOpenerW)
    def writeToRom(self, rom):
        self._mapEnemyTbl.writeToRom(rom)
        updateProgress(2.5)
        self._mapGroupPtrTbl.clear(len(self._mapGroups))
        updateProgress(2.5)

        pct = 42.5 / len(self._mapGroups)
        i = 0
        for (flag, rate1, rate2, subg1, subg2) in self._mapGroups:
            size = 4
            if rate1 > 0:
                size += len(subg1) * 3
            if rate2 > 0:
                size += len(subg2) * 3
            loc = rom.getFreeLoc(size)
            self._mapGroupPtrTbl[i, 0].setVal(EbModule.toSnesAddr(loc))

            rom.writeMulti(loc, flag, 2)
            rom[loc + 2] = rate1
            rom[loc + 3] = rate2
            loc += 4
            for prob, egroup in subg1:
                rom[loc] = prob
                rom.writeMulti(loc + 1, egroup, 2)
                loc += 3
            for prob, egroup in subg2:
                rom[loc] = prob
                rom.writeMulti(loc + 1, egroup, 2)
                loc += 3
            i += 1
            updateProgress(pct)
        self._mapGroupPtrTbl.writeToRom(rom)
        updateProgress(2.5)
    def writeToProject(self, resourceOpener):
        self._mapEnemyTbl.writeToProject(resourceOpener)
        updateProgress(2.5)

        # Write the groups
        pct = 42.5 / len(self._mapGroups)
        out = dict()
        i = 0
        for (flag, rate1, rate2, group1, group2) in self._mapGroups:
            # Generate first enemy/prob list
            g1out = dict()
            j = 0
            for prob, enemy in group1:
                g1out[j] = {"Enemy Group": enemy, "Probability": prob}
                j += 1
            g2out = dict()
            j = 0
            for prob, enemy in group2:
                g2out[j] = {"Enemy Group": enemy, "Probability": prob}
                j += 1
            out[i] = {
                "Event Flag": flag,
                "Sub-Group 1 Rate": rate1,
                "Sub-Group 1": g1out,
                "Sub-Group 2 Rate": rate2,
                "Sub-Group 2": g2out,
            }
            i += 1
            updateProgress(pct)
        s = yaml.dump(out, Dumper=yaml.CSafeDumper)
        updateProgress(2.5)
        s = sub("Event Flag: (\d+)", lambda i: "Event Flag: " + hex(int(i.group(0)[12:])), s)
        with resourceOpener("map_enemy_groups", "yml") as f:
            f.write(s)
        updateProgress(2.5)