Browse Source

Only allow modifiers on sensible objects.

This means you can't add VisRegions to your GUI pages. You also can't
make an empty object be a panic link region. Those kinds of things just
don't make sense.
pull/373/head
Adam Johnson 8 months ago
parent
commit
bc81e8c5e5
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 45
      korman/operators/op_modifier.py
  2. 21
      korman/properties/modifiers/__init__.py
  3. 4
      korman/properties/modifiers/anim.py
  4. 15
      korman/properties/modifiers/base.py
  5. 12
      korman/properties/modifiers/game_gui.py
  6. 2
      korman/properties/modifiers/gui.py
  7. 1
      korman/properties/modifiers/logic.py
  8. 1
      korman/properties/modifiers/physics.py
  9. 4
      korman/properties/modifiers/region.py
  10. 15
      korman/properties/modifiers/render.py
  11. 1
      korman/properties/modifiers/sound.py
  12. 4
      korman/properties/modifiers/water.py

45
korman/operators/op_modifier.py

@ -23,17 +23,7 @@ import time
from typing import *
from ..properties import modifiers
def _fetch_modifiers():
items = []
mapping = modifiers.modifier_mapping()
for i in sorted(mapping.keys()):
items.append(("", i, ""))
items.extend(mapping[i])
#yield ("", i, "")
#yield mapping[i]
return items
from ..helpers import find_modifier
class ModifierOperator:
def _get_modifier(self, context) -> modifiers.PlasmaModifierProperties:
@ -55,10 +45,41 @@ class ModifierAddOperator(ModifierOperator, bpy.types.Operator):
bl_label = "Add Modifier"
bl_description = "Adds a Plasma Modifier"
def _fetch_modifiers(self, context):
items = []
def filter_mod_name(mod):
# The modifier might include the cateogry name in its name, so we'll strip that.
if mod.bl_label != mod.bl_category:
if mod.bl_label.startswith(mod.bl_category):
return mod.bl_label[len(mod.bl_category)+1:]
if mod.bl_label.endswith(mod.bl_category):
return mod.bl_label[:-len(mod.bl_category)-1]
return mod.bl_label
sorted_modifiers = sorted(
modifiers.PlasmaModifierProperties.__subclasses__(),
key=lambda x: f"{x.bl_category} - {filter_mod_name(x)}"
)
last_category = None
for i, mod in enumerate(sorted_modifiers):
# Some modifiers aren't permissible in certain situations. Hide them.
if not find_modifier(context.object, mod.pl_id).allowed:
continue
if mod.bl_category != last_category:
items.append(("", mod.bl_category, ""))
last_category = mod.bl_category
items.append(
(mod.pl_id, filter_mod_name(mod), mod.bl_description,
getattr(mod, "bl_icon", ""), i)
)
return items
types = EnumProperty(
name="Modifier Type",
description="The type of modifier we add to the list",
items=_fetch_modifiers()
items=_fetch_modifiers
)
def execute(self, context):

21
korman/properties/modifiers/__init__.py

@ -75,24 +75,3 @@ class PlasmaModifiers(bpy.types.PropertyGroup):
class PlasmaModifierSpec(bpy.types.PropertyGroup):
pass
def modifier_mapping():
"""This returns a dict mapping Plasma Modifier categories to names"""
d = {}
sorted_modifiers = sorted(PlasmaModifierProperties.__subclasses__(), key=lambda x: x.bl_label)
for i, mod in enumerate(sorted_modifiers):
pl_id, category, label, description = mod.pl_id, mod.bl_category, mod.bl_label, mod.bl_description
icon = getattr(mod, "bl_icon", "")
# The modifier might include the cateogry name in its name, so we'll strip that.
if label != category:
if label.startswith(category):
label = label[len(category)+1:]
if label.endswith(category):
label = label[:-len(category)-1]
tup = (pl_id, label, description, icon, i)
d_cat = d.setdefault(category, [])
d_cat.append(tup)
return d

4
korman/properties/modifiers/anim.py

@ -53,6 +53,7 @@ class ActionModifier:
class PlasmaAnimationModifier(ActionModifier, PlasmaModifierProperties):
pl_id = "animation"
pl_page_types = {"gui", "room"}
bl_category = "Animation"
bl_label = "Animation"
@ -170,6 +171,7 @@ class AnimGroupObject(idprops.IDPropObjectMixin, bpy.types.PropertyGroup):
class PlasmaAnimationFilterModifier(PlasmaModifierProperties):
pl_id = "animation_filter"
pl_page_types = {"gui", "room"}
bl_category = "Animation"
bl_label = "Filter Transform"
@ -214,6 +216,7 @@ class PlasmaAnimationFilterModifier(PlasmaModifierProperties):
class PlasmaAnimationGroupModifier(ActionModifier, PlasmaModifierProperties):
pl_id = "animation_group"
pl_depends = {"animation"}
pl_page_types = {"gui", "room"}
bl_category = "Animation"
bl_label = "Group Master"
@ -272,6 +275,7 @@ class LoopMarker(bpy.types.PropertyGroup):
class PlasmaAnimationLoopModifier(ActionModifier, PlasmaModifierProperties):
pl_id = "animation_loop"
pl_depends = {"animation"}
pl_page_types = {"gui", "room"}
bl_category = "Animation"
bl_label = "Loop Markers"

15
korman/properties/modifiers/base.py

@ -20,7 +20,20 @@ import abc
import itertools
from typing import Any, Dict, FrozenSet, Optional
from ... import helpers
class PlasmaModifierProperties(bpy.types.PropertyGroup):
@property
def allowed(self) -> bool:
"""Returns if this modifier is allowed to be enabled on the owning Object"""
allowed_page_types = getattr(self, "pl_page_types", {"room"})
allowed_object_types = getattr(self, "bl_object_types", set())
page_name = self.id_data.plasma_object.page
if not allowed_object_types or self.id_data.type in allowed_object_types:
if helpers.get_page_type(page_name) in allowed_page_types:
return True
return False
@property
def copy_material(self):
"""Materials MUST be single-user"""
@ -53,7 +66,7 @@ class PlasmaModifierProperties(bpy.types.PropertyGroup):
@property
def enabled(self) -> bool:
return self.display_order >= 0
return self.display_order >= 0 and self.allowed
@enabled.setter
def enabled(self, value: bool) -> None:

12
korman/properties/modifiers/game_gui.py

@ -102,10 +102,12 @@ class _GameGuiMixin:
class PlasmaGameGuiControlModifier(PlasmaModifierProperties, _GameGuiMixin):
pl_id = "gui_control"
pl_page_types = {"gui"}
bl_category = "GUI"
bl_label = "Ex: Game GUI Control"
bl_label = "GUI Control (ex)"
bl_description = "XXX"
bl_object_types = {"FONT", "MESH"}
tag_id = IntProperty(
name="Tag ID",
@ -310,10 +312,12 @@ class GameGuiAnimationGroup(bpy.types.PropertyGroup):
class PlasmaGameGuiButtonModifier(PlasmaModifierProperties, _GameGuiMixin):
pl_id = "gui_button"
pl_depends = {"gui_control"}
pl_page_types = {"gui"}
bl_category = "GUI"
bl_label = "Ex: Game GUI Button"
bl_label = "GUI Button (ex)"
bl_description = "XXX"
bl_object_types = {"FONT", "MESH"}
def _update_notify_type(self, context):
# It doesn't make sense to have no notify type at all selected, so
@ -392,10 +396,12 @@ class PlasmaGameGuiButtonModifier(PlasmaModifierProperties, _GameGuiMixin):
class PlasmaGameGuiDialogModifier(PlasmaModifierProperties, _GameGuiMixin):
pl_id = "gui_dialog"
pl_page_types = {"gui"}
bl_category = "GUI"
bl_label = "Ex: Game GUI Dialog"
bl_label = "GUI Dialog (ex)"
bl_description = "XXX"
bl_object_types = {"FONT", "MESH"}
camera_object: bpy.types.Object = PointerProperty(
name="GUI Camera",

2
korman/properties/modifiers/gui.py

@ -687,7 +687,7 @@ class PlasmaNotePopupModifier(PlasmaModifierProperties, PlasmaModifierLogicWiz):
pl_id = "note_popup"
bl_category = "GUI"
bl_label = "Ex: Note Popup"
bl_label = "Note Popup (ex)"
bl_description = "XXX"
bl_icon = "MATPLANE"

1
korman/properties/modifiers/logic.py

@ -82,6 +82,7 @@ class PlasmaSpawnPoint(PlasmaModifierProperties):
bl_category = "Logic"
bl_label = "Spawn Point"
bl_description = "Point at which avatars link into the Age"
bl_object_types = {"EMPTY"}
def export(self, exporter, bo, so):
# Not much to this modifier... It's basically a flag that tells the engine, "hey, this is a

1
korman/properties/modifiers/physics.py

@ -68,6 +68,7 @@ class PlasmaCollider(PlasmaModifierProperties):
bl_label = "Collision"
bl_icon = "MOD_PHYSICS"
bl_description = "Simple physical collider"
bl_object_types = {"MESH", "FONT"}
bounds = EnumProperty(name="Bounds Type",
description="",

4
korman/properties/modifiers/region.py

@ -67,6 +67,7 @@ class PlasmaCameraRegion(PlasmaModifierProperties):
bl_label = "Camera Region"
bl_description = "Camera Region"
bl_icon = "CAMERA_DATA"
bl_object_types = {"MESH"}
camera_type = EnumProperty(name="Camera Type",
description="What kind of camera should be used?",
@ -133,6 +134,7 @@ class PlasmaFootstepRegion(PlasmaModifierProperties, PlasmaModifierLogicWiz):
bl_category = "Region"
bl_label = "Footstep"
bl_description = "Footstep Region"
bl_object_types = {"MESH"}
surface = EnumProperty(name="Surface",
description="What kind of surface are we walking on?",
@ -177,6 +179,7 @@ class PlasmaPanicLinkRegion(PlasmaModifierProperties):
bl_category = "Region"
bl_label = "Panic Link"
bl_description = "Panic Link Region"
bl_object_types = {"MESH"}
play_anim = BoolProperty(name="Play Animation",
description="Play the link-out animation when panic linking",
@ -313,6 +316,7 @@ class PlasmaSubworldRegion(PlasmaModifierProperties):
bl_category = "Region"
bl_label = "Subworld Region"
bl_description = "Subworld transition region"
bl_object_types = {"MESH"}
subworld = PointerProperty(name="Subworld",
description="Subworld to transition into",

15
korman/properties/modifiers/render.py

@ -39,10 +39,12 @@ class PlasmaBlendOntoObject(bpy.types.PropertyGroup):
class PlasmaBlendMod(PlasmaModifierProperties):
pl_id = "blend"
pl_page_types = {"gui", "room"}
bl_category = "Render"
bl_label = "Blending"
bl_description = "Advanced Blending Options"
bl_object_types = {"MESH", "FONT"}
render_level = EnumProperty(name="Render Pass",
description="Suggested render pass for this object.",
@ -150,6 +152,7 @@ class PlasmaDecalPrintMod(PlasmaDecalMod, PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Print Decal"
bl_description = "Prints a decal onto an object"
bl_object_types = {"MESH", "FONT"}
decal_type = EnumProperty(name="Decal Type",
description="Type of decal to print onto another object",
@ -201,6 +204,7 @@ class PlasmaDecalReceiveMod(PlasmaDecalMod, PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Receive Decal"
bl_description = "Allows this object to receive dynamic decals"
bl_object_types = {"MESH", "FONT"}
managers = CollectionProperty(type=PlasmaDecalManagerRef)
active_manager_index = IntProperty(options={"HIDDEN"})
@ -220,6 +224,7 @@ class PlasmaFadeMod(PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Opacity Fader"
bl_description = "Fades an object based on distance or line-of-sight"
bl_object_types = {"MESH", "FONT"}
fader_type = EnumProperty(name="Fader Type",
description="Type of opacity fade",
@ -281,6 +286,7 @@ class PlasmaFollowMod(idprops.IDPropObjectMixin, PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Follow"
bl_description = "Follow the movement of the camera, player, or another object"
bl_object_types = {"MESH", "FONT"}
follow_mode = EnumProperty(name="Mode",
description="Leader's movement to follow",
@ -357,6 +363,7 @@ class PlasmaGrassShaderMod(PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Grass Shader"
bl_description = "Applies waving grass effect at run-time"
bl_object_types = {"MESH", "FONT"}
wave1 = PointerProperty(type=PlasmaGrassWave)
wave2 = PointerProperty(type=PlasmaGrassWave)
@ -404,6 +411,7 @@ class PlasmaLightMapGen(idprops.IDPropMixin, PlasmaModifierProperties, PlasmaMod
bl_category = "Render"
bl_label = "Bake Lighting"
bl_description = "Auto-Bake Static Lighting"
bl_object_types = {"MESH", "FONT"}
deprecated_properties = {"render_layers"}
@ -551,10 +559,12 @@ class PlasmaLightMapGen(idprops.IDPropMixin, PlasmaModifierProperties, PlasmaMod
class PlasmaLightingMod(PlasmaModifierProperties):
pl_id = "lighting"
pl_page_types = {"gui", "room"}
bl_category = "Render"
bl_label = "Lighting Info"
bl_description = "Fine tune Plasma lighting settings"
bl_object_types = {"MESH", "FONT"}
force_rt_lights = BoolProperty(name="Force RT Lighting",
description="Unleashes satan by forcing the engine to dynamically light this object",
@ -640,11 +650,13 @@ _LOCALIZED_TEXT_PFM = (
class PlasmaLocalizedTextModifier(PlasmaModifierProperties, PlasmaModifierLogicWiz, TranslationMixin):
pl_id = "dynatext"
pl_page_types = {"gui", "room"}
bl_category = "Render"
bl_label = "Localized Text"
bl_description = ""
bl_icon = "TEXT"
bl_object_types = {"MESH", "FONT"}
translations = CollectionProperty(name="Translations",
type=PlasmaJournalTranslation,
@ -769,6 +781,7 @@ class PlasmaShadowCasterMod(PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Cast RT Shadow"
bl_description = "Cast runtime shadows"
bl_object_types = {"MESH", "FONT"}
blur = IntProperty(name="Blur",
description="Blur factor for the shadow map",
@ -809,6 +822,7 @@ class PlasmaViewFaceMod(idprops.IDPropObjectMixin, PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Swivel"
bl_description = "Swivel object to face the camera, player, or another object"
bl_object_types = {"MESH", "FONT"}
preset_options = EnumProperty(name="Type",
description="Type of Facing",
@ -952,6 +966,7 @@ class PlasmaVisibilitySet(PlasmaModifierProperties):
bl_category = "Render"
bl_label = "Visibility Set"
bl_description = "Defines areas where this object is visible"
bl_object_types = {"MESH", "LAMP"}
regions = CollectionProperty(name="Visibility Regions",
type=VisRegion)

1
korman/properties/modifiers/sound.py

@ -515,6 +515,7 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup):
class PlasmaSoundEmitter(PlasmaModifierProperties):
pl_id = "soundemit"
pl_page_types = {"gui", "room"}
bl_category = "Logic"
bl_label = "Sound Emitter"

4
korman/properties/modifiers/water.py

@ -29,6 +29,7 @@ class PlasmaSwimRegion(idprops.IDPropObjectMixin, PlasmaModifierProperties, bpy.
bl_label = "Swimming Surface"
bl_description = "Surface that the avatar can swim on"
bl_icon = "MOD_WAVE"
bl_object_types = {"MESH"}
_CURRENTS = {
"NONE": plSwimRegionInterface,
@ -179,6 +180,7 @@ class PlasmaWaterModifier(idprops.IDPropMixin, PlasmaModifierProperties, bpy.typ
bl_category = "Water"
bl_label = "Basic Water"
bl_description = "Basic water properties"
bl_object_types = {"MESH"}
wind_object = PointerProperty(name="Wind Object",
description="Object whose Y axis represents the wind direction",
@ -327,6 +329,7 @@ class PlasmaWaterShoreModifier(PlasmaModifierProperties):
bl_category = "Water"
bl_label = "Water Shore"
bl_description = ""
bl_object_types = {"MESH"}
# The basic modifier may want to export a default copy of us
_shore_tint_default = (0.2, 0.4, 0.4)
@ -395,6 +398,7 @@ class PlasmaWaterShoreModifier(PlasmaModifierProperties):
class PlasmaWaveState:
pl_depends = {"water_basic"}
bl_object_types = {"MESH"}
def convert_wavestate(self, state):
state.minLength = self.min_length

Loading…
Cancel
Save