Skip to content

Commit

Permalink
Pay down some technical debt wrt cube regions.
Browse files Browse the repository at this point in the history
the `pre_export_optional_cube_region` function is a decent idea, but it
predates the ability to do things like `foo = yield bar()` in
`pre_export()` generator methods. So, we remove it in favor of yielding
and assigning in one line. This should clean up some noisy warnings from
Blender after the export is over.
  • Loading branch information
Hoikas committed Jan 7, 2024
1 parent 9339b29 commit 6e2c032
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
13 changes: 0 additions & 13 deletions korman/exporter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,6 @@ def create_cube_region(name: str, size: float, owner_object: bpy.types.Object) -
)
return region_object.release()

@contextmanager
def pre_export_optional_cube_region(source, attr: str, name: str, size: float, owner_object: bpy.types.Object) -> Optional[bpy.types.Object]:
if getattr(source, attr) is None:
region_object = create_cube_region(name, size, owner_object)
setattr(source, attr, region_object)
try:
yield region_object
finally:
source.property_unset(attr)
else:
# contextlib.contextmanager requires for us to yield. Sad.
yield

@contextmanager
def temporary_camera_object(scene: bpy.types.Scene, name: str) -> bpy.types.Object:
try:
Expand Down
28 changes: 14 additions & 14 deletions korman/properties/modifiers/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ def pre_export(self, exporter, bo):
return

# Generate the clickable region if it was not provided
yield utils.pre_export_optional_cube_region(
self, "clickable_region",
f"{bo.name}_Journal_ClkRgn", 6.0, bo
)
if self.clickable_region is None:
self.clickable_region = yield utils.create_cube_region(
f"{bo.name}_Journal_ClkRgn", 6.0,
bo
)

# Generate the logic nodes
yield self.convert_logic(bo, age_name=exporter.age_name, version=version)
Expand Down Expand Up @@ -471,16 +472,15 @@ def pre_export(self, exporter, bo):
return

# Auto-generate a six-foot cube region around the clickable if none was provided.
yield utils.pre_export_optional_cube_region(
self, "clickable_region",
f"{self.key_name}_LinkingBook_ClkRgn", 6.0,
self.clickable
)
if self.clickable_region is None:
self.clickable_region = yield utils.create_cube_region(
f"{self.key_name}_LinkingBook_ClkRgn", 6.0,
self.clickable
)

# Auto-generate a ten-foot cube region around the clickable if none was provided.
if self.shareable:
yield utils.pre_export_optional_cube_region(
self, "share_region",
if self.shareable and self.share_region is None:
self.share_region = yield utils.create_cube_region(
f"{self.key_name}_LinkingBook_ShareRgn", 10.0,
self.clickable
)
Expand Down Expand Up @@ -816,8 +816,8 @@ def pre_export(self, exporter: Exporter, bo: bpy.types.Object):
click_plane_object.plasma_modifiers.gui_control.tag_id = 99

# Auto-generate a six-foot cube region around the clickable if none was provided.
yield utils.pre_export_optional_cube_region(
self, "clickable_region",
if self.clickable_region is None:
self.clickable_region = yield utils.create_cube_region(
f"{self.key_name}_DialogToggle_ClkRgn", 6.0,
self.clickable_object
)
Expand Down
10 changes: 5 additions & 5 deletions korman/properties/modifiers/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ def sanity_check(self):

def pre_export(self, exporter, bo):
# Generate a six-foot cube region if none was provided.
yield utils.pre_export_optional_cube_region(
self, "clickable_region",
f"{self.key_name}_Telescope_ClkRgn", 6.0,
bo
)
if self.clickable_region is None:
self.clickable_region = yield utils.create_cube_region(
f"{self.key_name}_Telescope_ClkRgn", 6.0,
bo
)

# Generate the logic nodes
yield self.convert_logic(bo)
Expand Down

0 comments on commit 6e2c032

Please sign in to comment.