Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow an exporter to be opened without an object selected #620

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion MCprep_addon/mcprep_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,11 @@ def draw(self, context):
row = col.row(align=True)
row.prop(addon_prefs, "MCprep_exporter_type", expand=True)
row = col.row(align=True)
exporter = world_tools.get_exporter(context)

compliant_exporter = world_tools.get_exporter(context)
exporter = compliant_exporter if compliant_exporter is not None else world_tools.get_explicit_exporter_legacy(context)
del compliant_exporter

if exporter is None:
row.operator(
"mcprep.open_jmc2obj", text=env._("Select exporter!"), icon='ERROR')
Expand Down
13 changes: 12 additions & 1 deletion MCprep_addon/world_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,25 @@ def get_exporter(context: Context) -> Optional[WorldExporter]:
# This section will be placed behind a legacy
# option in MCprep 4.0, once CommonMCOBJ becomes
# more adopted in exporters
return get_explicit_exporter_legacy(context)

def get_explicit_exporter_legacy(context: Context) -> Optional[WorldExporter]:
"""Return the explicit exporter setting set in the MCPrep UI (Warning: Not CommonMCOBJ Compliant!)

Unlike get_exporter, this doesn't depend on an object being selected, but
as a result is not CommonMCOBJ compliant (as this is based on an explicit
setting for the world exporter and not giving the OBJ the chance to declare
its exporter explicitly. This is meant for a few edge cases where the user might
want to do something that depends on an exporter being known, but without selecting
an object, such as in a startup file and having the ability to open Mineways or jmc2OBJ.
"""
prefs = util.get_user_preferences(context)
if prefs.MCprep_exporter_type == "Mineways":
return WorldExporter.ClassicMW
elif prefs.MCprep_exporter_type == "jmc2obj":
return WorldExporter.ClassicJmc
return None


def detect_world_exporter(filepath: Path) -> Union[CommonMCOBJ, ObjHeaderOptions]:
"""Detect whether Mineways or jmc2obj was used, based on prefix info.

Expand Down