Skip to content

Commit

Permalink
Working in UI - temporarily added to built plugins. Work still requir…
Browse files Browse the repository at this point in the history
…ed to refactor/add tests
  • Loading branch information
Rexeh committed Mar 22, 2024
1 parent a305540 commit 82da481
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions joystick_diagrams/plugins/fs2020_plugin/ms_flight_simulator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import xml.etree.ElementTree as eT
from dataclasses import dataclass
from pathlib import Path
Expand All @@ -7,6 +8,8 @@
from joystick_diagrams.input.hat import Hat, HatDirection
from joystick_diagrams.input.profile_collection import ProfileCollection

_logger = logging.getLogger(__name__)

AXIS_TO_AXIS_TYPES = {
"R-Axis X-": Axis(AxisDirection.RX),
"R-Axis X+": Axis(AxisDirection.RX),
Expand Down Expand Up @@ -36,14 +39,19 @@ def __init__(self, folder_path):
self.data = list()

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

_logger.debug(f"Folders detected {folders}")

pc = ProfileCollection()
pc.create_profile(default_profile_name)

xml_files = check_folders(folders)

_logger.debug(f"XMLs detected {xml_files}")

for xml in xml_files:
_logger.debug(f"Processing {xml}")
process_xml_file(xml, pc)

return pc
Expand Down Expand Up @@ -86,7 +94,11 @@ def process_device(device_xml: eT.Element, collection: ProfileCollection):

# Update the command to prevent overwrite
if existing_input and not control.modifiers:
existing_input.command = f"{existing_input.command} | {control.action}"
if existing_input.command:
existing_input.command = f"{existing_input.command} | {control.action}"
else:
existing_input.command = f"{control.action}"
continue

# Handle modifiers being added to existing controls (where we have overlapping base)
if existing_input and control.modifiers:
Expand Down Expand Up @@ -182,7 +194,11 @@ def split_action_name(name_key: str):


def file_check(file):
import os

_logger.debug(f"File access: {os.stat(file).st_mode}")
with open(file, "rb") as b:
_logger.debug("File opened")
if b.read(5) == b"<?xml":
return True
return False
Expand All @@ -195,6 +211,7 @@ def check_folders(folders):
continue

for file in folder.iterdir():
_logger.debug(f"Processing file {file}")
valid_files.append(file) if file_check(file) else None

return valid_files
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ includes = [
"joystick_diagrams.plugins.dcs_world_plugin",
"joystick_diagrams.plugins.star_citizen_plugin",
"joystick_diagrams.plugins.joystick_gremlin_plugin",
"joystick_diagrams.plugins.fs2020_plugin",
]
packages = [
"joystick_diagrams.plugins.dcs_world_plugin",
"joystick_diagrams.plugins.star_citizen_plugin",
"joystick_diagrams.plugins.joystick_gremlin_plugin",
"joystick_diagrams.plugins.fs2020_plugin",
]
include_files = [
"./img",
Expand Down

0 comments on commit 82da481

Please sign in to comment.