Ejemplo n.º 1
0
    def __init__(self, file_path):

        self.file_path = Path(file_path)

        if self.file_path.suffix != ".mrg":
            raise ValueError("Menu only supports .mrg files")

        global_palette_path = Palette.getGlobalPalettePath(file_path)
        self.palette = Palette.fullPalette(
            global_palette_path, global_palette_path
        )  # todo: This is certainly the wrong local pallette.

        self.offsets = []
        self.images = []

        self._read()
Ejemplo n.º 2
0
def background(input_path, palette_path=None):

    palette_path = Palette.getGlobalPalettePath(input_path, palette_path)
    global_palette = Palette.singlePalette(palette_path)

    f = File.File(input_path)
    local_palette = Palette.readSinglePalette(f)
    palette = Palette.combinePalettes(local_palette, global_palette)

    image = Image.Image(WIDTH, HEIGHT)
    image.name = input_path.name + ".png"

    n_pixels = WIDTH * HEIGHT
    for pixel in range(n_pixels):
        colour_index = f.readUInt8()
        image.set(palette[colour_index], pixel)

    return {
        "name": input_path.name,
        "image": image,
    }
Ejemplo n.º 3
0
def cursor(file_path, palette_path=None):
    f = File.File(file_path)

    palette_path = Palette.getGlobalPalettePath(file_path, palette_path)
    palette = Palette.fullPalette(palette_path, palette_path)

    cursors = []
    try:
        while True:
            width = f.readUInt16()
            height = f.readUInt16()
            cursor_image = Image.Image(width, height)
            cursor_image.name = "{}.{}".format(file_path.name, len(cursors))
            for y in range(height):
                for x in range(width):
                    cursor_image.set(palette[f.readUInt8()], x, y)
            cursors.append(cursor_image)
    except EOFError:
        pass

    return cursors
Ejemplo n.º 4
0
	def __init__(self, input_file = None):
		try:
			self.palette = Palette.FullPalette()
			self.palette.setGlobalPalette( Palette.standard() )
		except(RuntimeError):
			self.palette = None

		self.width = 640
		self.height = 480
		self.file_name = ""

		if( input_file != None ):
			self.read(input_file)
Ejemplo n.º 5
0
def main():
	
	import sys
	if( len(sys.argv) != 3 ):
		print("[USAGE]",__file__,"<spritefile.spr> <palettefile.rm>")
		return 0
	
	import AFU.File as File
	f = File.File(sys.argv[1])
	
	import AFU.Palette as Palette
	p = Palette.FullPalette()
	p.setGlobalPalette( Palette.standard() )
	p.setLocalPalette( Palette.Palette( File.File(sys.argv[2]) ) )
	
	s = Sprite(p, f)
	print(s)
Ejemplo n.º 6
0
def main():
	
	import sys
	if( len(sys.argv) != 3 ):
		print("[USAGE]",__file__,"<filename.fon> <user palette file>")
		return 0
	
	import AFU.File as File
	f = File.File(sys.argv[1])
	
	import AFU.Palette as Palette
	p = Palette.FullPalette()
	p.setGlobalPalette( Palette.standard() )
	p.setLocalPalette( Palette.Palette(File.File(sys.argv[2])) )
	
	fon = Font(p, f)
	print(fon)
Ejemplo n.º 7
0
def sprite(sprite_path, background_path, palette_path=None):

    palette_path = Palette.getGlobalPalettePath(sprite_path, palette_path)
    global_palette = Palette.singlePalette(palette_path)
    local_palette = Palette.singlePalette(background_path)
    palette = Palette.combinePalettes(local_palette, global_palette)

    f = File(sprite_path)

    spr = {
        "name": sprite_path.name,
        "blocks": [],
        "images": {},
    }

    block = _readBlockHeader(f)
    assert (block["name"] == "SPRT")
    assert (f.readUInt32() == 0x100)
    eof = block["offset"] + block["length"]

    block_offsets = []

    while f.pos() < eof:
        block = _readBlockHeader(f)

        if block["name"] == "LIST":
            block["entries"] = []
            length = f.readUInt32()
            for i in range(length):
                offset = f.readUInt32()
                block["entries"].append({"offset": block["offset"] + offset})

        elif block["name"] == "SETF":
            block["flag"] = f.readUInt32()  # 0, 1, 2, 3 or 4

        elif block["name"] == "POSN":
            block["x"] = f.readUInt32()
            block["y"] = f.readUInt32()

        elif block["name"] == "COMP":
            image = _readImage(f, block, palette)
            offset = image.pop("offset")
            block["image_offset"] = offset
            if image["image"] is not None:
                image["image"].name = _imageName(sprite_path, offset)
                spr["images"][offset] = image

        elif block["name"] == "TIME":
            block["time"] = f.readUInt32()

        elif block["name"] == "MARK":
            pass

        elif block["name"] == "MASK":
            pass

        elif block["name"] == "SCOM":
            image = _readImage(f, block, palette)
            offset = image.pop("offset")
            block["image_offset"] = offset
            if image["image"] is not None:
                image["image"].name = _imageName(sprite_path, offset)
                spr["images"][offset] = image

        elif block["name"] == "RAND":
            rand_extra = f.readUInt32()
            block["min"] = f.readUInt32()
            block["max"] = block["min"] + rand_extra

        elif block["name"] == "JUMP":
            block["index"] = f.readUInt32()

        elif block["name"] == "RPOS":
            block["dx"] = f.readSInt32()
            block["dy"] = f.readSInt32()

        elif block["name"] == "SNDF":
            sound_volume = f.readUInt32()  # 75, 95 or 100. volume?
            assert (f.readUInt32() == 0)
            sound_file = str(f.read(16))
            block["volume"] = sound_volume
            block["file"] = sound_file

        elif block["name"] == "MPOS":
            block["x"] = f.readUInt32()
            block["y"] = f.readUInt32()

        elif block["name"] == "PAUS":
            pass

        elif block["name"] == "EXIT":
            pass

        elif block["name"] == "STAT":
            pass

        elif block["name"] == "RGBP":
            palette = Palette.readFullPalette(f)

        else:
            raise ValueError("Unknown block {} at {:#x}".format(
                block["name"], block["start"]))

        block_offsets.append(block["offset"])
        block.pop("length")  # we don't need this any more
        spr["blocks"].append(block)

    for block in spr["blocks"]:
        if block["name"] == "LIST":
            for entry in block["entries"]:
                entry["index"] = block_offsets.index(entry["offset"])

    return spr