Convert some more exceptions to warnings for best-effort renderings.
This commit is contained in:
parent
4c7ac0f744
commit
05a85abce8
@ -30,7 +30,7 @@ class Clip:
|
|||||||
@property
|
@property
|
||||||
def frame(self) -> Frame:
|
def frame(self) -> Frame:
|
||||||
# The current frame object.
|
# The current frame object.
|
||||||
if self.finished:
|
if self.frameno >= len(self.frames):
|
||||||
raise Exception("Logic error!")
|
raise Exception("Logic error!")
|
||||||
return self.frames[self.frameno]
|
return self.frames[self.frameno]
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ class AFPRenderer(VerboseOutput):
|
|||||||
updated = True
|
updated = True
|
||||||
|
|
||||||
if not updated:
|
if not updated:
|
||||||
raise Exception(f"Couldn't find tag {tag.object_id} on depth {tag.depth} to update!")
|
print(f"WARNING: Couldn't find tag {tag.object_id} on depth {tag.depth} to update!")
|
||||||
|
|
||||||
# We finished!
|
# We finished!
|
||||||
return []
|
return []
|
||||||
@ -208,13 +208,14 @@ class AFPRenderer(VerboseOutput):
|
|||||||
self.__placed_objects.append(PlacedObject(parent_clip, tag, new_clip))
|
self.__placed_objects.append(PlacedObject(parent_clip, tag, new_clip))
|
||||||
|
|
||||||
return [new_clip]
|
return [new_clip]
|
||||||
|
|
||||||
if tag.source_tag_id in self.__registered_shapes:
|
if tag.source_tag_id in self.__registered_shapes:
|
||||||
self.vprint(f"{prefix} Placing Shape {tag.source_tag_id} with Object ID {tag.object_id} onto Depth {tag.depth}")
|
self.vprint(f"{prefix} Placing Shape {tag.source_tag_id} with Object ID {tag.object_id} onto Depth {tag.depth}")
|
||||||
self.__placed_objects.append(PlacedObject(parent_clip, tag, self.__registered_shapes[tag.source_tag_id]))
|
self.__placed_objects.append(PlacedObject(parent_clip, tag, self.__registered_shapes[tag.source_tag_id]))
|
||||||
|
|
||||||
return []
|
return []
|
||||||
else:
|
|
||||||
raise Exception(f"Cannot find a shape or sprite with Tag ID {tag.source_tag_id}!")
|
raise Exception(f"Cannot find a shape or sprite with Tag ID {tag.source_tag_id}!")
|
||||||
elif isinstance(tag, AP2RemoveObjectTag):
|
elif isinstance(tag, AP2RemoveObjectTag):
|
||||||
self.vprint(f"{prefix} Removing Object ID {tag.object_id} from Depth {tag.depth}")
|
self.vprint(f"{prefix} Removing Object ID {tag.object_id} from Depth {tag.depth}")
|
||||||
|
|
||||||
@ -235,6 +236,7 @@ class AFPRenderer(VerboseOutput):
|
|||||||
# Remove the last placed object at this depth. The placed objects list isn't
|
# Remove the last placed object at this depth. The placed objects list isn't
|
||||||
# ordered so much as apppending to the list means the last placed object at a
|
# ordered so much as apppending to the list means the last placed object at a
|
||||||
# depth comes last.
|
# depth comes last.
|
||||||
|
removed_objects = []
|
||||||
for i in range(len(self.__placed_objects)):
|
for i in range(len(self.__placed_objects)):
|
||||||
real_index = len(self.__placed_objects) - (i + 1)
|
real_index = len(self.__placed_objects) - (i + 1)
|
||||||
|
|
||||||
@ -243,22 +245,35 @@ class AFPRenderer(VerboseOutput):
|
|||||||
self.__placed_objects = self.__placed_objects[:real_index] + self.__placed_objects[(real_index + 1):]
|
self.__placed_objects = self.__placed_objects[:real_index] + self.__placed_objects[(real_index + 1):]
|
||||||
break
|
break
|
||||||
|
|
||||||
# We should have removed at least one objct.
|
if not removed_objects:
|
||||||
if len(removed_objects) == 0:
|
print(f"WARNING: Couldn't find object to remove by ID {tag.object_id} and depth {tag.depth}!")
|
||||||
raise Exception(f"Couldn't find object to remove by ID {tag.object_id} and depth {tag.depth}!")
|
|
||||||
|
|
||||||
for obj in removed_objects:
|
# Now, if we removed a sprite, go through and drop all of its children.
|
||||||
if obj.tag.source_tag_id in self.__registered_sprites:
|
while removed_objects:
|
||||||
# This is a sprite placement reference.
|
# Keep track of new clips that we need to drop.
|
||||||
for clip in self.__clips:
|
new_removed_objects = []
|
||||||
if clip is obj.drawable:
|
|
||||||
clip.remove()
|
|
||||||
|
|
||||||
# Kill any objects placed by this clip.
|
for obj in removed_objects:
|
||||||
self.__placed_objects = [
|
if obj.tag.source_tag_id in self.__registered_sprites:
|
||||||
o for o in self.__placed_objects
|
# This is a sprite placement reference, stop the clip.
|
||||||
if not(o.parent_clip is obj.drawable)
|
for clip in self.__clips:
|
||||||
]
|
if clip is obj.drawable:
|
||||||
|
clip.remove()
|
||||||
|
|
||||||
|
# Log what we're killing, schedule child clips for removal as well.
|
||||||
|
for o in self.__placed_objects:
|
||||||
|
if o.parent_clip is obj.drawable:
|
||||||
|
self.vprint(f"{prefix} Removing Object ID {o.tag.object_id} from Depth {o.tag.depth} after removing sprite with ID {tag.object_id} and depth {tag.depth}")
|
||||||
|
new_removed_objects.append(o)
|
||||||
|
|
||||||
|
# Kill any objects placed by this clip.
|
||||||
|
self.__placed_objects = [
|
||||||
|
o for o in self.__placed_objects
|
||||||
|
if not(o.parent_clip is obj.drawable)
|
||||||
|
]
|
||||||
|
|
||||||
|
# Now, do it again.
|
||||||
|
removed_objects = new_removed_objects
|
||||||
|
|
||||||
return []
|
return []
|
||||||
elif isinstance(tag, AP2DoActionTag):
|
elif isinstance(tag, AP2DoActionTag):
|
||||||
@ -393,7 +408,8 @@ class AFPRenderer(VerboseOutput):
|
|||||||
elif blend == 9:
|
elif blend == 9:
|
||||||
imgmap[imgoff] = self.__blend_subtractive(imgmap[imgoff], texmap[texoff], mult_color, add_color)
|
imgmap[imgoff] = self.__blend_subtractive(imgmap[imgoff], texmap[texoff], mult_color, add_color)
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Unsupported blend {blend}")
|
print(f"WARNING: Unsupported blend {blend}")
|
||||||
|
imgmap[imgoff] = self.__blend_normal(imgmap[imgoff], texmap[texoff], mult_color, add_color)
|
||||||
|
|
||||||
img.putdata(imgmap)
|
img.putdata(imgmap)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user