OpenNaja / cobra-tools

A suite of GUI tools for extracting and modifying OVL and OVS archives, as well as editing the associated in-house file formats. Also includes a model plugin for Blender. For downloads, guides, and FAQs visit:
https://opennaja.github.io/cobra-tools/
GNU General Public License v3.0
98 stars 26 forks source link

Decoupling the OVL reporter in a more abstract class, and definitely decoupling UI code from tools core code. #339

Closed ilodev closed 1 year ago

ilodev commented 1 year ago

This one is for Hex since I know you are working on this.

Currently the ovl creation is highly linked to the UI due to the system connecting the signals in the different loading/saving process. This is really breaking any attempt to integrate the main ovl file code into any other tool that doesn't have an UI (requiring QT5 even if not used at all).

from ovl_util.widgets import OvlReporter

# create an ovl file
ovl_data = OvlReporter()

The dependency is so clear that the Ovl class required to create an ovl file is inside Widgets.py, and is defined as:

class OvlReporter(OvlFile, QtCore.QObject, metaclass=CombinedMeta):

There are a few more problems after this, when the OvlFile class is loading, more and more dependencies start showing up, like this one:

ERROR:root:Could not load MS2
Traceback (most recent call last):
  File "C:\Users\lehen\OneDrive\Desktop\cobra-tools-master\modules\formats\formats_dict.py", line 18, in __init__
    module = import_module(f"modules.formats.{module_name}")
  File "./python3.8/importlib/__init__.py", line 127, in import_module
...
  File "C:\Users\lehen\OneDrive\Desktop\cobra-tools-master\modules\formats\MS2.py", line 15, in <module>
    from ovl_util import interaction
  File "C:\Users\lehen\OneDrive\Desktop\cobra-tools-master\ovl_util\interaction.py", line 3, in <module>
    from PyQt5 import QtWidgets

a part of the error handling is done directly in the MS2.py module instead of propagated back properly. Additionally we could just not force pyqt5 here at all.

After some struggles I was able to remove the QT5 dependencies to build a basic Init.ovl from a diff tool just reusing the tools classes.

            from generated.formats.ovl import OvlFile
            from generated.formats.ovl import set_game
            from ovl_util.config import get_version_str, get_commit_str
            logging.info(f"Running cobra-tools {get_version_str()}, {get_commit_str()}")

            gamestr = cobraConfigGetValue('current_game', None)

            ovl_data = OvlFile()
            ovl_data.load_hash_table()
            ovl_data.clear()

            set_game(ovl_data, gamestr)

            ovl_data.create(ovl_dir)

            ovl_data.save(path)

            logging.warning(f"OVL file created {path}")

This is the same sublime command: image

There is another alternative, where I can use 'external executables' as a building tool, however when I read the input provided by the tool it really comes formatted for a terminal (even if not running in a terminal anymore).

image

Since Hex is working on refactoring the whole UI stuff, maybe these things can be considered as a decoupling exercise so we can make additional tools faster (without having to deal with a whole set of dependencies).

HENDRIX-ZT2 commented 1 year ago

The ms2 code that imports pyqt (material check) is currently unused. It could be moved to the validate function instead and just raise a warning there, instead of a question.

HENDRIX-ZT2 commented 1 year ago

OvlFile and OvlReporter are totally interchangeable.

HENDRIX-ZT2 commented 1 year ago

Done that, but the logic for ms2 material checking itself may need changing. It might be too annoying as is.

ilodev commented 1 year ago

Awesome! Can’t touch the code again until Monday, I’ll do some testing there!

On Sat, 22 Jul 2023 at 14:15, HENDRIX-ZT2 @.***> wrote:

Done that, but the logic for ms2 material checking itself may need changing. It might be too annoying as is.

— Reply to this email directly, view it on GitHub https://github.com/OpenNaja/cobra-tools/issues/339#issuecomment-1646570076, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG42R73ESGZPL7RL5SJ5BODXRO75XANCNFSM6AAAAAA2RPPYYU . You are receiving this because you authored the thread.Message ID: @.***>

HENDRIX-ZT2 commented 1 year ago

Also done