Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROGRESS: main.py splitting #27

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
pip install -r requirements.txt
pip install PyInstaller

python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py source/enemy_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec
python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.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 --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec
mv dist/Bane-Of-Wargs Bane-Of-Wargs-Linux
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
pip install -r requirements.txt
pip install PyInstaller

python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py source/enemy_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs
python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.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 --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs
mv dist/Bane-Of-Wargs Bane-Of-Wargs-Mac
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
pip install -r requirements.txt
pip install windows-curses PyInstaller

python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py source/enemy_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec
python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.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 --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec
mv dist/Bane-Of-Wargs.exe Bane-Of-Wargs.exe
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down
6 changes: 6 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ 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 \
--add-data yamale/VERSION:yamale \
--collect-submodules fsspec \
--collect-submodules appdirs \
Expand Down
1 change: 1 addition & 0 deletions data/mission.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ First Mission:
description: "Go to $destination"
source: 0
destination: 5
invisible: true
on offer:
dialog: "first mission"
on complete:
Expand Down
6 changes: 6 additions & 0 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ 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 \
--add-data yamale/VERSION:yamale \
--collect-submodules fsspec \
--collect-submodules appdirs \
Expand Down
37 changes: 9 additions & 28 deletions source/battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import time
import term_menu
import text_handling
from colors import *
from colorama import Fore, Back, Style, init, deinit

Expand All @@ -15,26 +16,6 @@
turn = True
fighting = True

def print_long_string(text):
new_input = ""
for i, letter in enumerate(text):
if i % 54 == 0:
new_input += '\n'
new_input += letter

# this is just because at the beginning too a `\n` character gets added
new_input = new_input[1:]
print(str(new_input))

def print_separator(character):
count = 0

while count < 55:
sys.stdout.write(COLOR_STYLE_BRIGHT + character + COLOR_RESET_ALL)
sys.stdout.flush()
count += 1
sys.stdout.write('\n')

def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):
# get all stats
player_hp = player["health"]
Expand Down Expand Up @@ -226,7 +207,7 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin
enemies_number = enemies_remaining

text = '='
print_separator(text)
text_handling.print_separator(text)

if enemies_number > 1:
print("You encounter a group of " + str(enemy_plural) + " that won't let you pass.")
Expand Down Expand Up @@ -264,14 +245,14 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin
print("[R]un Away, [F]ight, [U]se Item? ")

text = '='
print_separator(text)
text_handling.print_separator(text)

print(" ")
startup_action = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL)
print("")

text = '='
print_separator(text)
text_handling.print_separator(text)

if startup_action.lower().startswith('r'):
# run away chance
Expand All @@ -280,9 +261,9 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin
fighting = False
else:
text = "You failed in running away from your enemy! You now have to fight him/them!"
print_long_string(text)
text_handling.print_long_string(text)
text = '='
print_separator(text)
text_handling.print_separator(text)
fighting = True
elif startup_action.lower().startswith('f'):
fighting = True
Expand Down Expand Up @@ -321,7 +302,7 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin
player["held shield"] = item_input
print("You are now holding a/an ", player["held shield"])
text = '='
print_separator(text)
text_handling.print_separator(text)
else:
print("'" + startup_action + "' is not a valid option")
fighting = True
Expand Down Expand Up @@ -454,7 +435,7 @@ def fight(player, item, enemy, map, map_location, enemies_remaining, lists):
player_inventory = player_inventory.replace(", ", '\n -')
print(" ")
text = '='
print_separator(text)
text_handling.print_separator(text)
print("INVENTORY:")
print(player_inventory)
item_input = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL)
Expand Down Expand Up @@ -484,7 +465,7 @@ def fight(player, item, enemy, map, map_location, enemies_remaining, lists):
player["held shield"] = item_input
print("You are now holding a/an ", player["held shield"])
text = '='
print_separator(text)
text_handling.print_separator(text)
print(" ")
else:
print("'" + action + "' is not a valid option")
Expand Down
3 changes: 2 additions & 1 deletion source/check_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import yaml
import appdirs
import logger_sys
import text_handling
from colors import *
from colorama import Fore, Back, Style, init, deinit

Expand Down Expand Up @@ -97,4 +98,4 @@ def examine(file_path):
except Exception as error:
print(COLOR_RED + "ERROR: " + COLOR_RESET_ALL + COLOR_RED + COLOR_STYLE_BRIGHT + "A parsing error in a yaml file has been detected:\n" + COLOR_RESET_ALL + str(error))
logger_sys.log_message(f"ERROR: A parsing error in a yaml file has been detected:\n{error}")
exit(1)
text_handling.exit_game()
136 changes: 136 additions & 0 deletions source/data_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import appdirs
import logger_sys
import check_yaml
import colors
import os
import yaml
import time
import text_handling
from colorama import Fore, Back, Style, init, deinit
from colors import *

# initialize colorama
init()

# Get program add directory
program_dir = str(appdirs.user_config_dir(appname='Bane-Of-Wargs'))

# Handling functions

def load_game_data(which_type, what_plugin=None):

# Check if the which_type variable is valid,
# so if it is not either 'vanilla' or
# 'plugin' which is inputted, send error
# and stop the program immediately
if which_type != 'vanilla' and which_type != 'plugin':
logger_sys.log_message(f"ERROR: Yaml data loading inputted key '{which_type}' is not valid --> crashing program")
print(f"{COLOR_RED}ERROR: {COLOR_STYLE_BRIGHT}Yaml data loading inputted key '{which_type}' is not valid --> crashing program{COLOR_RESET_ALL}")
time.sleep(5)
text_handling.exit_game()

# If the inputted which_type is vanilla, then just
# load the vanilla game data

if which_type == 'vanilla':
logger_sys.log_message("INFO: Loading vanilla game data")
with open(program_dir + "/game/data/map.yaml") as f:
map = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/map.yaml')

with open(program_dir + "/game/data/items.yaml") as f:
item = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/items.yaml')

with open(program_dir + "/game/data/drinks.yaml") as f:
drinks = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/drinks.yaml')

with open(program_dir + "/game/data/enemies.yaml") as f:
enemy = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/enemies.yaml')

with open(program_dir + "/game/data/npcs.yaml") as f:
npcs = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/npcs.yaml')

with open(program_dir + "/game/data/start.yaml") as f:
start_player = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/start.yaml')

with open(program_dir + "/game/data/lists.yaml") as f:
lists = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/lists.yaml')

with open(program_dir + "/game/data/zone.yaml") as f:
zone = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/zone.yaml')

with open(program_dir + "/game/data/dialog.yaml") as f:
dialog = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/dialog.yaml')

with open(program_dir + "/game/data/mission.yaml") as f:
mission = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/mission.yaml')

with open(program_dir + "/game/data/mounts.yaml") as f:
mounts = yaml.safe_load(f)
check_yaml.examine(program_dir + '/game/data/mounts.yaml')

else:
logger_sys.log_message(f"INFO: Loading plugin '{what_plugin}' data")
check_file = os.path.exists(program_dir + "/plugins/" + what_plugin)
if check_file == False:
print(COLOR_RED + COLOR_STYLE_BRIGHT + "ERROR: Couldn't find plugin '" + what_plugin + "'" + COLOR_RESET_ALL)
logger_sys.log_message(f"ERROR: Couldn't find plugin '{what_plugin}'")
play = 0
text_handling.exit_game()
with open(program_dir + "/plugins/" + what_plugin + "/map.yaml") as f:
map = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/map.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/items.yaml") as f:
item = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/items.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/drinks.yaml") as f:
drinks = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/drinks.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/enemies.yaml") as f:
enemy = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/enemies.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/npcs.yaml") as f:
npcs = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/npcs.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/start.yaml") as f:
start_player = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/start.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/lists.yaml") as f:
lists = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/lists.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/zone.yaml") as f:
zone = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/zone.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/dialog.yaml") as f:
dialog = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/dialog.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/mission.yaml") as f:
mission = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/mission.yaml")

with open(program_dir + "/plugins/" + what_plugin + "/mounts.yaml") as f:
mounts = yaml.safe_load(f)
check_yaml.examine(program_dir + "/plugins/" + what_plugin + "/mounts.yaml")

return map, item, drinks, enemy, npcs, start_player, lists, zone, dialog, mission, mounts

# deinitialize colorama
deinit()
20 changes: 2 additions & 18 deletions source/dialog_handling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logger_sys
import text_handling
import appdirs
import sys
import time
Expand All @@ -13,23 +14,6 @@
program_dir = str(appdirs.user_config_dir(appname='Bane-Of-Wargs'))

# Functions to handle dialogs
def print_speech_text_effect(text, preferences):
text = str(text) + "\n"
new_input = ""
for i, letter in enumerate(text):
if i % 54 == 0:
new_input += '\n'
new_input += letter
if preferences["speed up"] == False:
for character in new_input:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(round(random.uniform(.05, .1), 2))
else:
for character in new_input:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(.02)

def print_dialog(current_dialog, dialog, preferences, text_replacements_generic, player, drinks):
current_dialog_name = current_dialog
Expand Down Expand Up @@ -78,7 +62,7 @@ def print_dialog(current_dialog, dialog, preferences, text_replacements_generic,
current_text_replacement = str(list(text_replacements_generic)[count])
text = text.replace(current_text_replacement, str(text_replacements_generic[current_text_replacement]))
count += 1
print_speech_text_effect(text, preferences)
text_handling.print_speech_text_effect(text, preferences)
count += 1
if current_dialog["use actions"] == True:
logger_sys.log_message(f"INFO: Executing dialog '{current_dialog_name}' actions on the player")
Expand Down
Loading
Loading