Skip to content

Commit

Permalink
Reload script on selection
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
JDeeth committed Nov 8, 2023
1 parent 1031de1 commit aca71c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ For controls like instrument brightness knobs which take a number between
point number. DCSZap converts these into into integers - `0.0` to `0`, `1.0`
to `65535`.

Presently the scripts are loaded into memory at the time they are displayed
for selection, so if you've edited a script with DCSZap waiting for a selection
and then you run it, you'll run the old version. To reload the list, enter a
number that doesn't correspond to any script e.g. 0.
To reload the list, enter a number that doesn't correspond to any script e.g. 0.

For more guidance on DCS-BIOS commands, please see:
- [the DCS-BIOS documentation](https://github.com/DCS-Skunkworks/dcs-bios/blob/master/Scripts/DCS-BIOS/doc/developerguide.adoc#the-dcs-bios-import-protocol)
Expand All @@ -156,7 +153,6 @@ scripts in human language e.g. `Landing lights: Extend` rather than
labelled to the virtual pilot and the identifiers and values used in DCS-BIOS.

- command line option to specify a specific script rather than select from directory, allowing the script to run completely silent
- load scripts on selection, not when the selection list is displayed
- more obvious selection list reload action
- Make the tests better, largely for the sake of better tests
- 2-way comms with DCS-BIOS to, e.g., select a script automatically on loading
Expand Down
11 changes: 6 additions & 5 deletions dcszap.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,21 @@ def run(self):
"""Repeatedly prompt to select and run a script"""
while True:
print(f"Scripts located in {self._script_dir}:")
scripts = []
filenames = []
for filename in os.listdir(self._script_dir):
full_filename = os.path.join(self._script_dir, filename)
if os.path.isfile(full_filename) and filename.endswith(".txt"):
scripts.append(Script.load(full_filename))
for i, script in enumerate(scripts, start=1):
filenames.append(full_filename)
for i, filename in enumerate(filenames, start=1):
script = Script.load(filename)
print(f"{i:2} {script.name:32}{script.description}")
try:
selection = int(input("> ")) - 1
except (KeyboardInterrupt, ValueError):
sys.exit()
if selection not in range(0, len(scripts)):
if selection not in range(0, len(filenames)):
continue
scripts[selection].run(self, self._quiet)
Script.load(filenames[selection]).run(self, self._quiet)
if not self._quiet:
print("Script complete!\n")

Expand Down

0 comments on commit aca71c5

Please sign in to comment.