Skip to content

Commit

Permalink
DCS World switched to ProfileCollection, initial working ProfileColle…
Browse files Browse the repository at this point in the history
…ction model
  • Loading branch information
Rexeh committed Dec 30, 2023
1 parent 5c461a4 commit 60117bf
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 204 deletions.
12 changes: 0 additions & 12 deletions .github/FUNDING.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ poetry.lock
tests/__pycache__
tests/*/__pycache__/

# Folders
*__pycache__/

# Folders
*__pycache__/
/build/
Expand All @@ -26,6 +23,9 @@ temp/
/logs/*
/src/joystick_diagrams/logs*
*.egg-info/
htmlcov
.mypy*
.pytest*

# IDE
*.code-workspace
Expand Down
6 changes: 3 additions & 3 deletions docs/development/plugins.md → docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class ParserPlugin(PluginInterface):
self.path = None
self.settings = settings

def process(self) -> InputCollection():
## Parse things into an InputCollection()
## Return
def process(self) -> ProfileCollection():
## Parse things into an ProfileCollection()
## Return ProfileCollection()
return None

def set_path(self, path: Path) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md → docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ This will build the standalone binary package, as well as the installer package
## Developer Documentation

- Plugins [(LINK)](./development/plugins.md)
- Plugins [(LINK)](./plugins.md)
49 changes: 40 additions & 9 deletions joystick_diagrams/adaptors/dcs/dcs_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import joystick_diagrams.adaptors.dcs.dcs_world_lex # pylint: disable=unused-import
import joystick_diagrams.adaptors.dcs.dcs_world_yacc # pylint: disable=unused-import
import joystick_diagrams.adaptors.joystick_diagram_interface as jdi
from joystick_diagrams.input.device import Device_
from joystick_diagrams.input.profile_collection import ProfileCollection

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -99,7 +101,7 @@ def convert_button_format(self, button) -> str:
_logger.warning(f"Button format not found for {split}")
return f"{button}"

def process_profiles(self, profile_list: list | None = None) -> dict:
def process_profiles(self, profile_list: list | None = None) -> ProfileCollection:
if isinstance(profile_list, list) and len(profile_list) > 0:
self.profiles_to_process = profile_list
else:
Expand All @@ -109,28 +111,32 @@ def process_profiles(self, profile_list: list | None = None) -> dict:
len(self.profiles_to_process) != 0
), "DCS: There are no valid profiles to process" ## Replace with exception type

collection = ProfileCollection()

for profile in self.profiles_to_process:
prof = collection.create_profile(profile_name=profile)
self.fq_path = os.path.join(self.path, "Config", "Input", profile, "joystick")
self.profile_devices = os.listdir(os.path.join(self.fq_path))
self.joystick_listing = {}
for item in self.profile_devices:
self.joystick_listing.update({item[:-48]: item})
for joystick_device, joystick_file in self.joystick_listing.items():
if os.path.isdir(os.path.join(self.fq_path, joystick_file)):
guid, name = item[-46:-11], item[:-48]
active_profile = prof.add_device(guid, name)

if os.path.isdir(os.path.join(self.fq_path, item)):
_logger.info("Skipping as Folder")
else:
try:
_logger.debug(f"Obtaining file data for {joystick_file}")
_logger.debug(f"Obtaining file data for {item}")
file_data = (
Path(os.path.join(self.fq_path, joystick_file))
Path(os.path.join(self.fq_path, item))
.read_text(encoding="utf-8")
.replace("local diff = ", "")
.replace("return diff", "")
)

except FileNotFoundError as err:
_logger.error(
f"DCS: File {joystick_file} no longer found - \
f"DCS: File {item} no longer found - \
It has been moved/deleted from directory. {err}"
)
raise
Expand All @@ -141,10 +147,29 @@ def process_profiles(self, profile_list: list | None = None) -> dict:
if parsed_config is None:
break

self.assign_to_inputs(parsed_config, active_profile)

button_map = self.create_joystick_map(parsed_config)

self.update_joystick_dictionary(joystick_device, profile, False, button_map)
return self.joystick_dictionary
#self.update_joystick_dictionary(name, profile, False, button_map)

return collection
# return self.joystick_dictionary

def assign_to_inputs(self, config: dict, profile: Device_):
if "keyDiffs" in config.keys():
for data in config["keyDiffs"].values():
operation = data["name"]
if data.get("added"):
for binding in data["added"].values():
profile.create_input(binding["key"], operation)

if binding.get("reformers"):
reform_set = self.reformers_to_set(binding.get("reformers"))
profile.add_modifier_to_input(binding["key"], reform_set, operation)

def reformers_to_set(self, reformers: dict) -> set:
return {x for x in reformers.values()}

def parse_config(self, file: str):
try:
Expand Down Expand Up @@ -288,3 +313,9 @@ def p_error(t): # pylint: disable=invalid-name
_logger.error(error)
raise
return data


if __name__ == "__main__":
instance = DCSWorldParser("C:\\Users\\RCox\\Saved Games\\DCS.openbeta")
data = instance.process_profiles()
print(data)
2 changes: 1 addition & 1 deletion joystick_diagrams/classes/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, joystick_listing, parser_id="UNKNOWN"): # pylint disable=too
self.file_name_divider = "_"
self.joystick_listing = joystick_listing
self.export_progress = None
self.no_bind_text = settings.noBindText | ""
self.no_bind_text = settings.noBindText
self.executor = parser_id
self.error_bucket = []

Expand Down
153 changes: 0 additions & 153 deletions joystick_diagrams/classes/input.py

This file was deleted.

3 changes: 0 additions & 3 deletions joystick_diagrams/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
settings = Dynaconf(
settings_files=["settings.json"],
)

# `envvar_prefix` = export envvars with `export DYNACONF_FOO=bar`.
# `settings_files` = Load these files in the order.
Empty file.
52 changes: 52 additions & 0 deletions joystick_diagrams/input/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import logging

from joystick_diagrams.input.input import Input_

_logger = logging.getLogger("__name__")


class Device_:
def __init__(self, guid: str, name: str):
self.guid = guid.strip().lower()
self.name = name.strip().lower()
self.inputs: dict[str, Input_] = {}

def create_input(self, input_id: str, command: str) -> None:
input = self.inputs.get(input_id)

if input:
input.command = command
_logger.debug(f"Input {input_id} already exists and will be overwritten")
else:
self.inputs[input_id] = Input_(input_id, command)

def add_modifier_to_input(self, input_id, modifier: set, command: str) -> None:
"""
Adds a modifier to an input if it exists
"""

_logger.debug(f"Adding modifier {modifier} to input {input_id}")
input = self.inputs.get(input_id)

if input is None:
_logger.warning(f"Modifier attempted to be added to {input_id} but input does not exist")
else:
input.add_modifier(modifier, command)


if __name__ == "__main__":
dev = Device_("guid1", "Potato")

dev.create_input("button_1", "shoot")

print(dev.inputs)

dev.add_modifier_to_input("button_1", {"ctrl", "alt"}, "pickup")
dev.add_modifier_to_input("button_2", {"ctrl", "alt"}, "pickup")
dev.add_modifier_to_input("button_1", {"alt", "ctrl"}, "pickup")
dev.add_modifier_to_input("button_1", {"spacebar", "ctrl"}, "dunk")

for i in dev.inputs.values():
print(i.identifier)
print(i.command)
print(i.modifiers)
Loading

0 comments on commit 60117bf

Please sign in to comment.