Skip to content

Commit

Permalink
Integrate to work as plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Mar 22, 2024
1 parent fc766d5 commit a305540
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
42 changes: 29 additions & 13 deletions joystick_diagrams/plugins/fs2020_plugin/main.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,67 @@
import json
import logging
from pathlib import Path

from joystick_diagrams.input.profile_collection import ProfileCollection
from joystick_diagrams.plugins.fs2020_plugin.ms_flight_simulator import FS2020Parser
from joystick_diagrams.plugins.plugin_interface import PluginInterface

from .config import settings

_logger = logging.getLogger("__name__")

CONFIG_FILE = "data.json"


class ParserPlugin(PluginInterface):
def __init__(self):
super().__init__()
self.settings = settings
self.settings.validators.register()
self.path = None
self.instance = None | FS2020Parser

def process(self) -> ProfileCollection:
# Process your plugin, to build and return a profile collection instance
return ProfileCollection()
return self.instance.run()

def set_path(self, path: Path) -> bool:
try:
# Handle the Path provided
# Validate the path / file/ folder provided is suitable for your plugin
# Pre-initialise any instances if required
pass
inst = FS2020Parser(path)

if inst:
self.instance = inst
self.path = path
self.save_plugin_state()

except Exception:
return False

return True

def save_plugin_state(self):
# Persist any data changes when they are modified
# self.get_plugin_data_path() - Gets your plugins app data path automatically
pass
with open(
Path.joinpath(self.get_plugin_data_path(), CONFIG_FILE),
"w",
encoding="UTF8",
) as f:
f.write(json.dumps({"path": str(self.path)}))

def load_settings(self) -> None:
# Load any data / initialise your plugin - Automatically called on start up if plugin is enabled
pass
try:
with open(
Path.joinpath(self.get_plugin_data_path(), CONFIG_FILE),
"r",
encoding="UTF8",
) as f:
data = json.loads(f.read())
self.path = Path(data["path"]) if data["path"] else None
except FileNotFoundError:
pass

@property
def path_type(self):
return self.FolderPath(
"This title shows up on the UI select dialog",
Path.joinpath(Path.home(), "Saved Games"),
Path.joinpath(Path.home(), "AppData"),
)

@property
Expand Down
19 changes: 7 additions & 12 deletions joystick_diagrams/plugins/fs2020_plugin/ms_flight_simulator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import xml.etree.ElementTree as eT
from dataclasses import dataclass, field
from dataclasses import dataclass
from pathlib import Path

from joystick_diagrams.input.axis import Axis, AxisDirection
Expand Down Expand Up @@ -30,13 +30,13 @@
default_profile_name = "Default"


@dataclass
class Parser:
path: str
data: list = field(init=False, default_factory=list)
class FS2020Parser:
def __init__(self, folder_path):
self.folder_path = Path(folder_path)
self.data = list()

def run(self):
folders = Path(self.path).iterdir()
folders = Path(self.folder_path).iterdir()

pc = ProfileCollection()
pc.create_profile(default_profile_name)
Expand Down Expand Up @@ -211,9 +211,4 @@ def __repr__(self):


if __name__ == "__main__":
ps = Parser(
r"C:\Users\RCox\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\SystemAppData\wgs\00090000038358E7_00000000000000000000000069F80140"
)
data = ps.run()

print(data)
pass

0 comments on commit a305540

Please sign in to comment.