Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions korman/exporter/locman.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>.

from __future__ import annotations

import bpy
from PyHSPlasma import *

Expand All @@ -21,7 +23,7 @@
import itertools
from pathlib import Path
import re
from typing import NamedTuple, Union
from typing import *
from xml.sax.saxutils import escape as xml_escape
import weakref

Expand Down Expand Up @@ -91,6 +93,24 @@ def add_string(self, set_name, element_name, language, value):

self._strings[set_name][element_name][language] = value

def get_localized_string(self, translations: Dict[str, str]):
# If there's only an English translation, just output this string directly.
if translations.keys() == {"English"}:
return translations["English"]

ignored_translations = frozenset(translations.keys()) - _SP_LANGUAGES
if ignored_translations:
self._report.warn(
f"These translations are not supported in single player: "
f"{', '.join(ignored_translations)}"
)

return "".join(
f"${lang[0:2]}${value}"
for lang, value in translations.items()
if lang in _SP_LANGUAGES
)

@contextmanager
def _generate_file(self, filename, **kwargs):
if self._exporter is not None:
Expand Down Expand Up @@ -234,20 +254,27 @@ def run(self):
def _run_harvest_journals(self):
from ..properties.modifiers import TranslationMixin

def iter_subclasses(cls):
for i in cls.__subclasses__():
yield i
if i.__subclasses__():
yield from iter_subclasses(i)


objects = bpy.context.scene.objects
self._report.progress_advance()
self._report.progress_range = len(objects)
inc_progress = self._report.progress_increment

for i in objects:
for mod_type in filter(None, (getattr(j, "pl_id", None) for j in TranslationMixin.__subclasses__())):
for mod_type in filter(None, (getattr(j, "pl_id", None) for j in iter_subclasses(TranslationMixin))):
modifier = getattr(i.plasma_modifiers, mod_type)
if modifier.enabled:
translations = [j for j in modifier.translations if j.text_id is not None]
translations = [j for j in modifier.translations if j.text]
if not translations:
self._report.error(f"'{i.name}': No content translations available. The localization will not be exported.")
for j in translations:
self.add_string(modifier.localization_set, modifier.key_name, j.language, j.text_id)
self.add_string(modifier.localization_set, modifier.key_name, j.language, j.text)
inc_progress()

def _run_generate(self):
Expand Down
16 changes: 16 additions & 0 deletions korman/idprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ def poll_empty_objects(self, value):
def poll_mesh_objects(self, value):
return value.type == "MESH"

def poll_object_dyntexts(self, value):
if value.type != "IMAGE":
return False
if value.image is not None:
return False
tex_materials = frozenset(value.users_material)
obj_materials = frozenset(filter(None, (i.material for i in self.id_data.material_slots)))
return bool(tex_materials & obj_materials)

def poll_object_image_textures(self, value):
if value.type != "IMAGE":
return False
tex_materials = frozenset(value.users_material)
obj_materials = frozenset(filter(None, (i.material for i in self.id_data.material_slots)))
return bool(tex_materials & obj_materials)

def poll_softvolume_objects(self, value):
return value.plasma_modifiers.softvolume.enabled

Expand Down
18 changes: 18 additions & 0 deletions korman/operators/op_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ def execute(self, context):
return {"FINISHED"}


class PlasmaSelectRadioGroupCheckboxesOperator(bpy.types.Operator):
bl_idname = "object.plasma_select_radio_group"
bl_label = "Select Radio Group"
bl_description = "Selects all checkboxes in a radio group"

def execute(self, context):
active_object = context.active_object
for i in context.scene.objects:
cb_mod = i.plasma_modifiers.gui_checkbox
cb_rg = cb_mod.radio_group
i.select = (
(cb_mod.enabled and cb_rg is not None and cb_rg.name == active_object.name)
or
(i.name == active_object.name)
)
return {"FINISHED"}


class PlasmaToggleAllPlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator):
bl_idname = "object.plasma_toggle_all_objects"
bl_label = "Toggle All Plasma Objects"
Expand Down
11 changes: 11 additions & 0 deletions korman/properties/modifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
from .sound import *
from .water import *

# Check our mixins to ensure that the subclasses have them first in their MRO.
_mod_mixins = [game_gui._GameGuiMixin]
for mixin in _mod_mixins:
for sub in mixin.__subclasses__():
mro = sub.__mro__
if mro.index(mixin) > mro.index(PlasmaModifierProperties):
raise ImportError(
f"{sub.__name__} base class {mixin.__name__} isn't properly "
"overriding PlasmaModifierProperties!"
)

class PlasmaModifiers(bpy.types.PropertyGroup):
def determine_next_id(self):
"""Gets the ID for the next modifier in the UI"""
Expand Down
Loading