Skip to content

Commit

Permalink
Move ammo.py logic to bin/ammo
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberrumor committed Oct 31, 2023
1 parent 665db55 commit 4b6c153
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 94 deletions.
92 changes: 0 additions & 92 deletions ammo/ammo.py

This file was deleted.

92 changes: 90 additions & 2 deletions bin/ammo
Original file line number Diff line number Diff line change
@@ -1,4 +1,92 @@
#!/usr/bin/env python3
from ammo import ammo
import sys
from pathlib import Path
from ammo.mod_controller import (
Game,
ModController,
)
from ammo.ui import UI

exit(ammo.main())

IDS = {
"Skyrim Special Edition": "489830",
"Oblivion": "22330",
"Fallout 4": "377160",
"Skyrim": "72850",
"Enderal": "933480",
"Enderal Special Edition": "976620",
"Starfield": "1716740",
}
DOWNLOADS = Path.home() / "Downloads"
STEAM = Path.home() / ".local/share/Steam/steamapps"


# game selection
games = [game.name for game in (STEAM / "common").iterdir() if game.name in IDS]
if not games:
print("Install a game through steam!")
print("ammo supports:")
for i in IDS:
print(f"- {i}")
print(f"ammo looks for games in {STEAM/'common'}")
print("ammo stores mods in ~/.local/share/ammo")
print("ammo looks for mods to install in ~/Downloads")
sys.exit(1)

if len(games) == 1:
CHOICE = 0
else:
while True:
CHOICE = None
print("Index | Game")
print("----------------")
for index, game in enumerate(games):
print(f"[{index}] {game}")
CHOICE = input("Index of game to manage: ")
if CHOICE.strip().lower() == "exit":
exit()
try:
CHOICE = int(CHOICE)
assert CHOICE in range(len(games))
except ValueError:
print(f"Expected integer 0 through {len(games) - 1} (inclusive)")
continue
except AssertionError:
print(f"Expected integer 0 through {len(games) - 1} (inclusive)")
continue
break

# Get the paths and files associated with our game.
name = games[CHOICE]
app_id = IDS[name]
pfx = STEAM / f"compatdata/{app_id}/pfx"
directory = STEAM / f"common/{name}"
app_data = STEAM / f"{pfx}/drive_c/users/steamuser/AppData/Local"
dlc_file = app_data / f"{name.replace('t 4', 't4')}/DLCList.txt"
plugin_file = app_data / f"{name.replace('t 4', 't4')}/Plugins.txt"
data = directory / "Data"
ammo_mods_dir = Path.home() / f".local/share/ammo/{name}/mods"
ammo_conf_dir = Path.home() / f".local/share/ammo/{name}"
ammo_conf = ammo_conf_dir / "ammo.conf"

# Create expected directories if they don't alrady exist.
for expected_dir in [ammo_mods_dir, ammo_conf_dir]:
Path.mkdir(expected_dir, parents=True, exist_ok=True)

# Get a ammo_configuration for the chosen game
game = Game(
name,
directory,
data,
ammo_conf,
dlc_file,
plugin_file,
ammo_mods_dir,
)

# Create an instance of the controller.
controller = ModController(DOWNLOADS, game)

# Run the UI against the controller.
ui = UI(controller)
ui.repl()

0 comments on commit 4b6c153

Please sign in to comment.