Add basic selection and navigation systems

Create and connect locations
Select options and render menus
This commit is contained in:
2022-08-04 17:18:23 +02:00
parent 5afa066a79
commit 0549dc6f2f
9 changed files with 193 additions and 42 deletions

32
src/utils/input.py Normal file
View File

@@ -0,0 +1,32 @@
"""
Utility to show a seletion menu
"""
import time
class Option(object):
def __init__(self, text: str, callback: callable) -> None:
self.text = text
self.callback = callback
class Menu(object):
def __init__(self, title: str, options: list) -> None:
self.title = title
self.options = options
def show(self) -> int:
print(f"\n{self.title}")
for i, option in enumerate(self.options):
print(f"{i+1}. {option.text}")
time.sleep(0.25)
selected = int(input(f"Select an option [1-{len(self.options)}]: "))
if selected > len(self.options):
print("Invalid option.")
time.sleep(0.5)
self.show()
else:
print("") #Newline for better readability
if self.options[selected-1].callback is not None:
self.options[selected-1].callback()
return selected