diff --git a/cli/app.py b/cli/app.py new file mode 100644 index 0000000..2064696 --- /dev/null +++ b/cli/app.py @@ -0,0 +1,38 @@ +from cli.war_menu import war_menu +from cli.utils import choose_from_list + +def app_menu(data): + while True: + print("\n=== Warmachron ===") + print("1. Select war") + print("2. Create war") + print("3. Manage players") + print("0. Exit") + + choice = input("> ").strip() + + if choice == "1": + war = select_war(data) + if war: + war_menu(data, war) + + elif choice == "2": + create_war(data) + + elif choice == "3": + manage_players(data) + + elif choice == "0": + return + +def select_war(data): + wars = data["wars"] + if not wars: + print("No wars available.") + return None + + return choose_from_list( + wars, + lambda w: f"{w['name']} ({w['year']})" + ) + diff --git a/cli/campaign_menu.py b/cli/campaign_menu.py new file mode 100644 index 0000000..c29239e --- /dev/null +++ b/cli/campaign_menu.py @@ -0,0 +1,23 @@ +from cli.round_menu import round_menu + +def campaign_menu(data, war, campaign): + while True: + print(f"\n=== Campaign: {campaign['name']} ===") + print("1. Select round") + print("2. Append round") + print("3. Finish campaign") + print("4. Edit/Delete campaign") + print("0. Back") + + choice = input("> ").strip() + + if choice == "1": + rnd = select_round(campaign) + if rnd: + round_menu(data, war, campaign, rnd) + + elif choice == "2": + append_round(campaign) + + elif choice == "0": + return diff --git a/cli/menu.py b/cli/menu.py deleted file mode 100644 index 91f46ce..0000000 --- a/cli/menu.py +++ /dev/null @@ -1,9 +0,0 @@ -def main_menu(): - print("\n=== Wargame Campaign App ===") - print("1. List wars") - print("2. Start new campaign") - print("3. Start new round") - print("4. Enter battle results") - print("5. Save & exit") - - return input("> ") diff --git a/cli/round_menu.py b/cli/round_menu.py new file mode 100644 index 0000000..6c98c17 --- /dev/null +++ b/cli/round_menu.py @@ -0,0 +1,34 @@ +def round_menu(data, war, campaign, rnd): + while True: + print(f"\n=== Round {rnd['number']} ===") + print("1. Enter choices and pairing") + print("2. Enter battle results") + print("3. Finish round") + print("4. Edit/Delete round") + print("0. Back") + + choice = input("> ").strip() + + if choice == "1": + enter_choices(data, war, campaign, rnd) + + elif choice == "2": + enter_battle_results(data, war, campaign, rnd) + + elif choice == "0": + return + +def enter_choices(data, war, campaign, rnd): + print("Entering choices (placeholder)") + # later: + # - list campaign participants + # - input primary / secondary sector + # - store in rnd["choices"] + +def enter_battle_results(data, war, campaign, rnd): + print("Entering battle results (placeholder)") + # later: + # - list battles + # - select winner + # - apply scoring + diff --git a/cli/utils.py b/cli/utils.py new file mode 100644 index 0000000..32045e7 --- /dev/null +++ b/cli/utils.py @@ -0,0 +1,14 @@ +def choose_from_list(items, label_fn): + for i, item in enumerate(items, start=1): + print(f"{i}. {label_fn(item)}") + print("0. Back") + + choice = input("> ").strip() + if choice == "0": + return None + + try: + return items[int(choice) - 1] + except (ValueError, IndexError): + print("Invalid choice") + return None diff --git a/cli/war_menu.py b/cli/war_menu.py new file mode 100644 index 0000000..8400888 --- /dev/null +++ b/cli/war_menu.py @@ -0,0 +1,33 @@ +from cli.campaign_menu import campaign_menu +from storage.repository import save_data + +def war_menu(data, war): + while True: + print(f"\n=== War: {war['name']} ===") + print("1. Select campaign") + print("2. Append campaign") + print("3. Finish war") + print("4. Edit/Delete war") + print("0. Back") + + choice = input("> ").strip() + + if choice == "1": + campaign = select_campaign(war) + if campaign: + campaign_menu(data, war, campaign) + + elif choice == "2": + append_campaign(war) + + elif choice == "0": + return + +def append_campaign(war, data): + name = input("Campaign name: ") + war["campaigns"].append({ + "name": name, + "rounds": [], + "completed": False + }) + save_data(data) diff --git a/main.py b/main.py index b0f23a0..45047d5 100644 --- a/main.py +++ b/main.py @@ -1,21 +1,10 @@ from storage.repository import load_data, save_data -from cli.menu import main_menu +from cli.app import app_menu def main(): data = load_data() - - while True: - choice = main_menu() - - if choice == "1": - print("Wars:") - for war in data["wars"]: - print(f"- {war['name']}") - - elif choice == "5": - save_data(data) - print("Goodbye.") - break + app_menu(data) + save_data(data) if __name__ == "__main__": main()