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. 21
      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 # Grab a naive listing of enabled pages
age = scene.world.plasma_age 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)) 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)) 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... # Because we can have an unnamed or a named default page, we need to see if that is enabled...
for page in age.pages: for page in age.pages:
if page.seq_suffix == 0: 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_enabled = page.enabled
default_inited = True default_inited = True
break break
@ -185,7 +189,7 @@ class Exporter:
if (default_enabled and not page) or (page in pages_enabled): if (default_enabled and not page) or (page in pages_enabled):
self._objects.append(obj) 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) error.add(page, obj.name)
inc_progress() inc_progress()
error.raise_if_error() error.raise_if_error()
@ -217,7 +221,8 @@ class Exporter:
ver = self._op.version ver = self._op.version
for page in age_info.pages: for page in age_info.pages:
if page.enabled and ver in page.version: 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) mgr.create_builtins(age_name, age_info.use_texture_page)
def _export_actor(self, so, bo): def _export_actor(self, so, bo):

2
korman/exporter/explosions.py

@ -76,7 +76,7 @@ class UndefinedPageError(ExportError):
mistakes = {} mistakes = {}
def __init__(self): 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): def add(self, page, obj):
if page not in self.mistakes: if page not in self.mistakes:

21
korman/exporter/manager.py

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

2
korman/properties/prop_object.py

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

8
korman/properties/prop_world.py

@ -136,6 +136,14 @@ class PlasmaPage(bpy.types.PropertyGroup):
items=game_versions, items=game_versions,
options={"ENUM_FLAG"}, options={"ENUM_FLAG"},
default=set(list(zip(*game_versions))[0])) 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... # Implementation details...
last_name = StringProperty(description="INTERNAL: Cached page name", 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 pl_age = context.scene.world.plasma_age
layout.active = pl_obj.enabled 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? # Which page does this object go in?
# If left blank, the exporter puts it in page 0 -- "Default" # 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.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): class PlasmaNetPanel(ObjectButtonsPanel, bpy.types.Panel):

20
korman/ui/ui_world.py

@ -207,8 +207,8 @@ class PlasmaAgePanel(AgeButtonsPanel, bpy.types.Panel):
layout.separator() layout.separator()
box = layout.box() box = layout.box()
split = box.split()
split = box.split()
col = split.column() col = split.column()
col.label("Page Flags:") col.label("Page Flags:")
col.prop(active_page, "auto_load") col.prop(active_page, "auto_load")
@ -218,7 +218,23 @@ class PlasmaAgePanel(AgeButtonsPanel, bpy.types.Panel):
col.label("Page Info:") col.label("Page Info:")
col.prop(active_page, "name", text="") col.prop(active_page, "name", text="")
col.prop(active_page, "seq_suffix") 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 # Age Names should really be legal Python 2.x identifiers for AgeSDLHooks
legal_identifier = korlib.is_legal_python2_identifier(age.age_name) legal_identifier = korlib.is_legal_python2_identifier(age.age_name)

Loading…
Cancel
Save