Browse Source

Add page types.

This adds a page type distinction. It will primarily be geared toward
things like GUIs and avatar animations. However, for now, we can abuse
it to allow externally created pages, such as those created by PRPShop
hacking (for particles) or from 3dsMax (avatar animations, GUIs, etc.)
to coexist more easily with our Korman-generated .age files.
pull/369/head
Adam Johnson 2 years ago
parent
commit
697b932198
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 9
      korman/exporter/convert.py
  2. 2
      korman/exporter/explosions.py
  3. 37
      korman/exporter/manager.py
  4. 2
      korman/properties/prop_object.py
  5. 8
      korman/properties/prop_world.py
  6. 8
      korman/ui/ui_object.py
  7. 20
      korman/ui/ui_world.py

9
korman/exporter/convert.py

@ -156,11 +156,15 @@ class Exporter:
# Grab a naive listing of enabled pages
age = scene.world.plasma_age
pages_enabled = frozenset((page.name for page in age.pages if page.enabled and self._op.version in page.version))
external_pages = frozenset((page.name for page in age.pages if page.page_type == "external"))
pages_enabled -= external_pages
all_pages = frozenset((page.name for page in age.pages))
# Because we can have an unnamed or a named default page, we need to see if that is enabled...
for page in age.pages:
if page.seq_suffix == 0:
if page.page_type != "room":
raise explosions.ExportError(f"Default page '{page.name}' must be a Room page!")
default_enabled = page.enabled
default_inited = True
break
@ -185,7 +189,7 @@ class Exporter:
if (default_enabled and not page) or (page in pages_enabled):
self._objects.append(obj)
elif page not in all_pages:
elif page not in all_pages or page in external_pages:
error.add(page, obj.name)
inc_progress()
error.raise_if_error()
@ -217,7 +221,8 @@ class Exporter:
ver = self._op.version
for page in age_info.pages:
if page.enabled and ver in page.version:
mgr.create_page(age_name, page.name, page.seq_suffix)
external = page.page_type == "external"
mgr.create_page(age_name, page.name, page.seq_suffix, external=external)
mgr.create_builtins(age_name, age_info.use_texture_page)
def _export_actor(self, so, bo):

2
korman/exporter/explosions.py

@ -76,7 +76,7 @@ class UndefinedPageError(ExportError):
mistakes = {}
def __init__(self):
super(ExportError, self).__init__("You have objects in pages that do not exist!")
super(ExportError, self).__init__("You have objects in invalid pages!")
def add(self, page, obj):
if page not in self.mistakes:

37
korman/exporter/manager.py

@ -150,7 +150,7 @@ class ExportManager:
# present and valid. They do not have to have any contents. See AvatarCustomization.
# BuiltIn.prp
want_pysdl = bpy.context.scene.world.plasma_age.age_sdl
builtin = self.create_page(age, "BuiltIn", -2, True)
builtin = self.create_page(age, "BuiltIn", -2, builtin=True)
if want_pysdl:
self._pack_agesdl_hook(age)
sdl = self.add_object(plSceneObject, name="AgeSDLHook", loc=builtin)
@ -160,37 +160,44 @@ class ExportManager:
# Textures.prp
# FIXME: unconditional creation will overwrite any existing textures PRP. This should
# be addressed by a successful implementation of #145.
self.create_page(age, "Textures", -1, True)
self.create_page(age, "Textures", -1, builtin=True)
def create_page(self, age, name, id, builtin=False):
def create_page(self, age, name, id, *, builtin=False, external=False):
location = plLocation(self.mgr.getVer())
location.prefix = bpy.context.scene.world.plasma_age.seq_prefix
if builtin:
location.flags |= plLocation.kBuiltIn
location.page = id
self._pages[name] = location
if not external:
self._pages[name] = location
# If the page ID is 0, this is the default page... Any page with an empty string name
# is the default, so bookmark it!
if id == 0:
assert not external, "The default page cannot be external!"
self._pages[""] = location
info = plPageInfo()
info.age = age
info.page = name
info.location = location
self.mgr.AddPage(info)
if not external:
info = plPageInfo()
info.age = age
info.page = name
info.location = location
self.mgr.AddPage(info)
if not builtin:
self._age_info.addPage((name, id, 0))
if self.getVer() <= pvPots:
node = plSceneNode("{}_District_{}".format(age, name))
if not external:
if self.getVer() <= pvPots:
node = plSceneNode(f"{age}_District_{name}")
else:
node = plSceneNode(f"{age}_{name}")
self.mgr.AddObject(location, node)
else:
node = plSceneNode("{}_{}".format(age, name))
self._nodes[location] = node
self.mgr.AddObject(location, node)
node = None
else:
self._nodes[location] = None
node = None
self._nodes[location] = node
return location
@property

2
korman/properties/prop_object.py

@ -33,6 +33,8 @@ class PlasmaObject(bpy.types.PropertyGroup):
for page in age.pages:
if page.seq_suffix > num_layers:
continue
if page.page_type == "external":
continue
if o.layers[page.seq_suffix - 1]:
o.plasma_object.page = page.name
break

8
korman/properties/prop_world.py

@ -136,6 +136,14 @@ class PlasmaPage(bpy.types.PropertyGroup):
items=game_versions,
options={"ENUM_FLAG"},
default=set(list(zip(*game_versions))[0]))
page_type = EnumProperty(name="Page Type",
description="Type of data this page contains",
items=[
("room", "Room", "A standard Plasma Room containing scene objects"),
("external", "External", "A page generated by an external process. Korman will not write to this page, ever."),
],
default="room",
options=set())
# Implementation details...
last_name = StringProperty(description="INTERNAL: Cached page name",

8
korman/ui/ui_object.py

@ -53,9 +53,17 @@ class PlasmaObjectPanel(ObjectButtonsPanel, bpy.types.Panel):
pl_age = context.scene.world.plasma_age
layout.active = pl_obj.enabled
# It is an error to put objects in the wrong types of pages/
active_page = next((i for i in pl_age.pages if i.name == pl_obj.page), None)
is_external_page = active_page.page_type == "external" if active_page else False
# Which page does this object go in?
# If left blank, the exporter puts it in page 0 -- "Default"
layout.alert = is_external_page
layout.prop_search(pl_obj, "page", pl_age, "pages", icon="BOOKMARKS")
layout.alert = False
if is_external_page:
layout.label("Objects cannot be exported to External pages.", icon="ERROR")
class PlasmaNetPanel(ObjectButtonsPanel, bpy.types.Panel):

20
korman/ui/ui_world.py

@ -207,8 +207,8 @@ class PlasmaAgePanel(AgeButtonsPanel, bpy.types.Panel):
layout.separator()
box = layout.box()
split = box.split()
split = box.split()
col = split.column()
col.label("Page Flags:")
col.prop(active_page, "auto_load")
@ -218,7 +218,23 @@ class PlasmaAgePanel(AgeButtonsPanel, bpy.types.Panel):
col.label("Page Info:")
col.prop(active_page, "name", text="")
col.prop(active_page, "seq_suffix")
col.prop_menu_enum(active_page, "version")
split = box.split()
col = split.column()
col.label("Export For:")
col.prop(active_page, "version")
col = split.column()
default_page = active_page.seq_suffix == 0
invalid_page_type = default_page and active_page.page_type != "room"
col.alert = invalid_page_type
col.label("Page Type:")
col.prop(active_page, "page_type", text="")
col.alert = False
if default_page:
col.label("This is the Default Page.", icon="BOOKMARKS")
if invalid_page_type:
col.label("Page must be a Room.", icon="ERROR")
# Age Names should really be legal Python 2.x identifiers for AgeSDLHooks
legal_identifier = korlib.is_legal_python2_identifier(age.age_name)

Loading…
Cancel
Save