Skip to content

Commit

Permalink
bugfix/progress - custom terminal menu (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
OcelotWalrus authored Jan 24, 2024
1 parent ae405b5 commit 3f596ed
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 24 deletions.
5 changes: 2 additions & 3 deletions Bane-Of-Wargs.spec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_submodules

hiddenimports = ['appdirs', 'fsspec', 'simple_term_menu']
hiddenimports = ['appdirs', 'fsspec']
hiddenimports += collect_submodules('fsspec')
hiddenimports += collect_submodules('appdirs')
hiddenimports += collect_submodules('simple_term_menu')


a = Analysis(
['source/main.py', 'source/battle.py', 'source/check_yaml.py', 'source/colors.py', 'source/train.py', 'source/logger_sys.py', 'source/term_menu.py', 'source/mission_handling.py', 'source/dialog_handling.py', 'source/enemy_handling.py', 'source/data_handling.py', 'source/npc_handling.py', 'source/text_handling.py', 'source/zone_handling.py', 'source/uuid_handling.py', 'source/weapon_upgrade_handling.py'],
Expand Down Expand Up @@ -40,7 +40,6 @@ exe = EXE(
codesign_identity=None,
entitlements_file=None,
)

coll = COLLECT(
exe,
a.binaries,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ You can also take the game to a next level by compiling it. Check the documentat

Bane Of Wargs is a minimal game but you will have to install/updated some python modules.
All required modules are in the `requirements.txt` file.
[simple-term-menu](https://pypi.org/project/simple-term-menu/), [fade](https://pypi.org/project/fade/), [GitPython](https://pypi.org/project/GitPython/), [colorama](https://pypi.org/project/colorama/), [PyYaml](https://pypi.org/project/PyYAML/), [Yamale](https://pypi.org/project/yamale/), [Fsspec](https://filesystem-spec.readthedocs.io/en/latest/index.html), [AppDirs](https://pypi.org/project/appdirs/), [Requests](https://pypi.org/project/requests/).
[fade](https://pypi.org/project/fade/), [GitPython](https://pypi.org/project/GitPython/), [colorama](https://pypi.org/project/colorama/), [PyYaml](https://pypi.org/project/PyYAML/), [Yamale](https://pypi.org/project/yamale/), [Fsspec](https://filesystem-spec.readthedocs.io/en/latest/index.html), [AppDirs](https://pypi.org/project/appdirs/), [Requests](https://pypi.org/project/requests/).

---

Expand Down
2 changes: 0 additions & 2 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,3 @@ source/weapon_upgrade_handling.py \
--hidden-import fsspec \
--exclude-module fcntl \
--log-level DEBUG

sudo mv dist/Bane-Of-Wargs /usr/bin/
1 change: 0 additions & 1 deletion docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Well of course first, you'll need to have the Python interpreter installed as we

Afterwards, you'll also need to get the python packages required for the game to run. Here are the PIP packages:
```
simple_term_menu
fade
GitPython
colorama
Expand Down
1 change: 0 additions & 1 deletion docs/PLAYING.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ The download should start quickly.
Like most python programs, it's very rare that it only requires the default packages coming with the Python environment. This program requires 6 python modules/libraries.
All of these modules/libraries are contained in the [requirements.txt](https://github.com/Dungeons-of-Kathallion/Bane-Of-Wargs/blob/master/requirements.txt) file.

* **[simple_term_menu](https://pypi.org/project/simple-term-menu/)** // the modules that makes the choice-menu things possible.
* **[fade](https://pypi.org/project/fade/)** // the modules that makes the game title fade possible.
* **[GitPython](https://pypi.org/project/GitPython/)** // the modules that makes updating the game from the github repository while being in-game possible.
* **[colorama](https://pypi.org/project/colorama/)** // the module that makes displaying colored text in terminal easier.
Expand Down
5 changes: 0 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
simple_term_menu
fade
GitPython
colorama
Expand All @@ -7,7 +6,3 @@ yamale
fsspec
appdirs
requests
cryptography
certifi
numpy
psutil
74 changes: 63 additions & 11 deletions source/term_menu.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
from simple_term_menu import TerminalMenu
import time
from colors import *
from colorama import Fore, Back, Style, init, deinit

# initialize colorama
init()

def show_menu(options):
# settings for the single-choice menu
terminal_menu = TerminalMenu(
options, menu_cursor_style=("fg_green", "bold"),
menu_highlight_style=("fg_green", "bold")
)

# show to menu and stores the user input to choice
menu_entry_index = terminal_menu.show()
choice = options[menu_entry_index]
def show_menu(options, length=54):
continue_action = True

return choice
# Get how many choices there are
choice_number = len(options)

# Print the box with the choices displayed
print("╭" + int(length) * '─' + '╮')

count = 0
while count < choice_number:
number_of_spaces_remaining = (length - 2) - (2 + len(list(str(options[count]))))
print(
"│ " + COLOR_GREEN + COLOR_STYLE_BRIGHT + str(count) +
'> ' + COLOR_RESET_ALL + str(options[count]) + int(number_of_spaces_remaining) * ' ' + '│'
)

count += 1

print("╰" + int(length) * '─' + '╯')

while continue_action:
error_happened = False
# Get user's input and return the value
# of the user's input. Also check if the
# input is valid, if not, return warning
get_input = input('$ ')
try:
input_type = str(type(int(get_input)))
except Exception as error:
input_type = '...'

# Check if the input is an integer
if input_type != "<class 'int'>":
print(COLOR_YELLOW + f"Options '{get_input}' is not valid!" + COLOR_RESET_ALL)
time.sleep(.5)
error_happened = True

# Check if the input is in the choices
if not error_happened:
if int(get_input) < 0 or int(get_input) > choice_number:
print(COLOR_YELLOW + f"Options '{get_input}' is not valid!" + COLOR_RESET_ALL)
time.sleep(.5)
error_happened = True

# Get the corresponding choice, depending
# on the input number

if not error_happened:
user_input = options[int(get_input)]
continue_action = False
else:
user_input = None

return user_input


# deinitialize colorama
deinit()

0 comments on commit 3f596ed

Please sign in to comment.