Пример #1
0
def LoadOverrides():
    """
    Load overrides
    """
    OverrideBitmap = QtGui.QPixmap('miyamotodata/overrides.png')
    idx = 0
    xcount = OverrideBitmap.width() // globals.TileWidth
    ycount = OverrideBitmap.height() // globals.TileWidth
    globals.Overrides = [None] * (xcount * ycount)
    sourcex = 0
    sourcey = 0

    for y in range(ycount):
        for x in range(xcount):
            bmp = OverrideBitmap.copy(sourcex, sourcey, globals.TileWidth, globals.TileWidth)
            globals.Overrides[idx] = TilesetTile(bmp)

            # Set collisions if it's a brick or question
            if (x < 11 or x == 14) and y == 2: globals.Overrides[idx].setQuestionCollisions()
            elif x < 12 and y == 1: globals.Overrides[idx].setBrickCollisions()

            idx += 1
            sourcex += globals.TileWidth
        sourcex = 0
        sourcey += globals.TileWidth
        if idx % 16 != 0:
            idx -= (idx % 16)
            idx += 16

    # ? Block for Sprite 59
    bmp = OverrideBitmap.copy(14 * globals.TileWidth, 2 * globals.TileWidth, globals.TileWidth, globals.TileWidth)
    globals.Overrides.append(TilesetTile(bmp))
Пример #2
0
def _LoadTileset(idx, name):
    """
    Load in a tileset into a specific slot
    """

    # if this file's not found, return
    if name not in globals.szsData: return

    sarcdata = globals.szsData[name]
    sarc = SarcLib.SARC_Archive()
    sarc.load(sarcdata)

    tileoffset = idx * 256

    # Decompress the textures
    try:
        comptiledata = sarc['BG_tex/%s.gtx' % name].data
        nmldata = sarc['BG_tex/%s_nml.gtx' % name].data
        colldata = sarc['BG_chk/d_bgchk_%s.bin' % name].data

    except KeyError:
        QtWidgets.QMessageBox.warning(
            None, globals.trans.string('Err_CorruptedTilesetData', 0),
            globals.trans.string('Err_CorruptedTilesetData', 1, '[file]', name),
        )

        return False

    # load in the textures
    img = loadGTX(comptiledata)
    nml = loadGTX(nmldata)

    # Divide it into individual tiles and
    # add collisions at the same time
    def getTileFromImage(tilemap, xtilenum, ytilenum):
        return tilemap.copy((xtilenum * 64) + 2, (ytilenum * 64) + 2, 60, 60)

    dest = QtGui.QPixmap.fromImage(img)
    dest2 = QtGui.QPixmap.fromImage(nml)
    sourcex = 0
    sourcey = 0
    for i in range(tileoffset, tileoffset + 256):
        T = TilesetTile(getTileFromImage(dest, sourcex, sourcey), getTileFromImage(dest2, sourcex, sourcey))
        T.setCollisions(struct.unpack_from('<Q', colldata, (i - tileoffset) * 8)[0])
        globals.Tiles[i] = T
        sourcex += 1
        if sourcex >= 32:
            sourcex = 0
            sourcey += 1

    def exists(fn):
        nonlocal sarc

        try:
            sarc[fn]

        except KeyError:
            return False

        return True
    
    # Load the tileset animations, if there are any
    if idx == 0:
        tileoffset = idx * 256

        hatena_anime = None
        block_anime = None
        tuka_coin_anime = None
        belt_conveyor_anime = None

        fn = 'BG_tex/hatena_anime.gtx'
        found = exists(fn)

        if found:
            hatena_anime = loadGTX(sarc[fn].data)

        fn = 'BG_tex/block_anime.gtx'
        found = exists(fn)

        if found:
            block_anime = loadGTX(sarc[fn].data)

        fn = 'BG_tex/tuka_coin_anime.gtx'
        found = exists(fn)

        if found:
            tuka_coin_anime = loadGTX(sarc[fn].data)

        fn = 'BG_tex/belt_conveyor_anime.gtx'
        found = exists(fn)

        if found:
            belt_conveyor_anime = loadGTX(sarc[fn].data, True)

        for i in range(tileoffset, tileoffset + 256):
            if globals.Tiles[i].coreType == 7:
                if hatena_anime:
                    globals.Tiles[i].addAnimationData(hatena_anime)

            elif globals.Tiles[i].coreType == 6:
                if block_anime:
                    globals.Tiles[i].addAnimationData(block_anime)

            elif globals.Tiles[i].coreType == 2:
                if tuka_coin_anime:
                    globals.Tiles[i].addAnimationData(tuka_coin_anime)

            elif globals.Tiles[i].coreType == 17:
                if belt_conveyor_anime:
                    for x in range(2):
                        if i == 144 + x * 16:
                            globals.Tiles[i].addConveyorAnimationData(belt_conveyor_anime, 0, True)

                        elif i == 145 + x * 16:
                            globals.Tiles[i].addConveyorAnimationData(belt_conveyor_anime, 1, True)

                        elif i == 146 + x * 16:
                            globals.Tiles[i].addConveyorAnimationData(belt_conveyor_anime, 2, True)

                        elif i == 147 + x * 16:
                            globals.Tiles[i].addConveyorAnimationData(belt_conveyor_anime, 0)

                        elif i == 148 + x * 16:
                            globals.Tiles[i].addConveyorAnimationData(belt_conveyor_anime, 1)

                        elif i == 149 + x * 16:
                            globals.Tiles[i].addConveyorAnimationData(belt_conveyor_anime, 2)

        for tile in globals.Overrides:
            if tile.coreType == 7:
                if hatena_anime:
                    tile.addAnimationData(hatena_anime)

            elif tile.coreType == 6:
                if block_anime:
                    tile.addAnimationData(block_anime)

    # Load the object definitions
    defs = [None] * 256

    indexfile = sarc['BG_unt/%s_hd.bin' % name].data
    deffile = sarc['BG_unt/%s.bin' % name].data
    objcount = len(indexfile) // 6
    indexstruct = struct.Struct('>HBBH')

    for i in range(objcount):
        data = indexstruct.unpack_from(indexfile, i * 6)
        obj = ObjectDef()
        obj.width = data[1]
        obj.height = data[2]
        obj.randByte = data[3]
        obj.load(deffile, data[0])
        defs[i] = obj

    globals.ObjectDefinitions[idx] = defs

    ProcessOverrides(name)