Skip to content

Commit

Permalink
COnstruct from file path instead of file object
Browse files Browse the repository at this point in the history
  • Loading branch information
discully committed Dec 23, 2016
1 parent 46ed3b1 commit 61f6165
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
3 changes: 3 additions & 0 deletions AFU/Menu.py
Expand Up @@ -11,6 +11,9 @@ def __init__(self, file_path):

self.file_path = Path(file_path)

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

standard_palette = Palette(File(self.file_path.with_name("standard.pal")))
self.palette = FullPalette()
self.palette.setGlobalPalette(standard_palette)
Expand Down
26 changes: 12 additions & 14 deletions AFU/Texture.py
@@ -1,37 +1,35 @@
from pathlib import PurePath
from pathlib import Path
from AFU.Image import Image
import PIL.Image
import AFU.Image



class Texture:

def __init__(self, input_file = None):
def __init__(self, file_path):
self.file_path = Path(file_path)
self.width = None
self.height = None
self.image = None
self.file_name = ""

if( input_file != None ):
self.read(input_file)
self._read()


def __str__(self):
return "Texture ({0} {1})".format(self.file_name, {
return "Texture ({0} {1})".format(self.file_path.name, {
"width":self.width,
"height":self.height,
})


def read(self, f):
self.file_name = PurePath(f.name()).name
pil_image = PIL.Image.open(f.file_name)
def _read(self):

pil_image = PIL.Image.open(str(self.file_path))
pil_image = pil_image.convert(mode="RGB")
pil_pixels = pil_image.load()
afu_image = AFU.Image.Image(pil_image.width, pil_image.height)

self.image = Image(pil_image.width, pil_image.height)
for x in range(pil_image.width):
for y in range(pil_image.height):
afu_image.set(pil_pixels[x,y], x, y)
self.image = afu_image
self.image.set(pil_pixels[x,y], x, y)
self.width = pil_image.width
self.height = pil_image.height
46 changes: 28 additions & 18 deletions AFU/World.py
@@ -1,35 +1,45 @@
from pathlib import PurePath
from pathlib import Path
from AFU.File import File



class World:

def __init__(self, input_file = None):
self.world_id = None
self.file_name = ""
self.screens = []

if( input_file != None ):
self.read(input_file)
def __init__(self, file_path):

self.file_path = Path(file_path)

if( self.file_path.suffix != ".scr" or self.file_path.name[:2] != "sl" ):
raise ValueError("World only supports sl*.scr files")

self.id = int(self.file_path.stem[2:])
self._screens = []

self._read()


def __getitem__(self, item):
return self._screens[item]


def __len__(self):
return len(self._screens)


def __str__(self):
s = "World {0}:\n".format(self.world_id)
s += " File: {0}\n".format(self.file_name)
s += " Screens ({0}):\n".format(len(self.screens))
for screen in self.screens:
s = "World {0}:\n".format(self.id)
s += " File: {0}\n".format(self.file_path.name)
s += " Screens ({0}):\n".format(len(self))
for screen in self._screens:
s += " Screen {0}:\n".format(screen["screen_id"])
s += " Background: {0}\n".format(screen["background"])
s += " Polygons: {0}\n".format(screen["polygons"])
s += " Entrances: {0}\n".format(len(screen["entrances"]))
return s


def read(self, f):
fname = PurePath(f.name())
self.file_name = fname.name
if( fname.suffix == ".scr" and len(fname.stem) == 5 and fname.stem[:2] == "sl" ):
self.world_id = int(fname.stem[2:])
def _read(self):
f = File(self.file_path)

n_screens = f.readUInt16()

Expand Down Expand Up @@ -75,4 +85,4 @@ def read(self, f):

screen["entrances"] = entrances

self.screens = screens
self._screens = screens
4 changes: 2 additions & 2 deletions afu_identify.py
Expand Up @@ -31,9 +31,9 @@ def main():
elif( file_type == "database" ):
afu_object = AFU.Database.Database(afu_file)
elif( file_type == "texture" ):
afu_object = AFU.Texture.Texture(afu_file)
afu_object = AFU.Texture.Texture(file_path)
elif( file_type == "world" ):
afu_object = AFU.World.World(afu_file)
afu_object = AFU.World.World(file_path)
elif( file_type == "list" ):
afu_object = AFU.List.List(afu_file)
elif( file_type == "menu" ):
Expand Down
3 changes: 3 additions & 0 deletions afu_to_png.py
Expand Up @@ -119,6 +119,9 @@ def main():
image = afu_menu.images[i]
output_file_name = "{}_{}".format(path.stem, offset)
export(output_file_name, image)

else:
print("Unsupported file type: {}".format(file_type))



Expand Down

0 comments on commit 61f6165

Please sign in to comment.