Skip to content

Commit

Permalink
fix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrose committed Dec 2, 2022
1 parent 033ef6d commit 895a9f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
48 changes: 22 additions & 26 deletions fileio/settingIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
from assets import values

global Player_Name, Master_Volume, Music_Volume
global SFX_Volume, Difficulty
global SFX_Volume, DifficultyLevel
global Keymap_Left, Keymap_Right, Keymap_Up
global Keymap_Down, Keymap_Primary_Fire
global Keymap_Secondary_Fire, Keymap_Dash, Keymap_Pause


class difficulty(Enum):
Easy = 1
Medium = 2
Hard = 3
EASY = 1
MEDIUM = 2
HARD = 3


def load_settings(path):
Expand All @@ -37,7 +37,7 @@ def load_settings(path):
IOError: if the file does not exist, will load default settings
"""
global Player_Name, Master_Volume, Music_Volume
global SFX_Volume, Difficulty
global SFX_Volume, DifficultyLevel
global Keymap_Left, Keymap_Right, Keymap_Up
global Keymap_Down, Keymap_Primary_Fire
global Keymap_Secondary_Fire, Keymap_Dash, Keymap_Pause
Expand All @@ -49,7 +49,7 @@ def load_settings(path):
Music_Volume = data["Music_Volume"]
SFX_Volume = data["SFX_Volume"]
Difficulty_pre = data["Difficulty"]
Difficulty = convertDifficulty(Difficulty_pre)
DifficultyLevel = convertDifficulty(Difficulty_pre)
Keymap_Left = data["Keymap_Left"]
Keymap_Right = data["Keymap_Right"]
Keymap_Up = data["Keymap_Up"]
Expand All @@ -59,26 +59,27 @@ def load_settings(path):
Keymap_Dash = data["Keymap_Dash"]
Keymap_Pause = data["Keymap_Pause"]
except:
print("fialed")
load_default_settings()
pygame.display.set_caption(
"Setting File Not Found, Default Setting Loaded")


def convertDifficulty(difficulty):
if difficulty == "Easy":
return difficulty.Easy
elif difficulty == "Medium":
return difficulty.Medium
elif difficulty == "Hard":
return difficulty.Hard
def convertDifficulty(difficulty1):
if difficulty1 == "Easy":
return difficulty.EASY
elif difficulty1 == "Medium":
return difficulty.MEDIUM
elif difficulty1 == "Hard":
return difficulty.HARD


def convertDifficultyToText(difficulty):
if difficulty == difficulty.Easy:
def convertDifficultyToText(difficultyE):
if difficultyE == difficulty.EASY:
return "Easy"
elif difficulty == difficulty.Medium:
elif difficultyE == difficulty.MEDIUM:
return "Medium"
elif difficulty == difficulty.Hard:
elif difficultyE == difficulty.HARD:
return "Hard"


Expand All @@ -87,12 +88,12 @@ def save_settings():
"""

global Player_Name, Master_Volume, Music_Volume
global SFX_Volume, Difficulty
global SFX_Volume, DifficultyLevel
global Keymap_Left, Keymap_Right, Keymap_Up
global Keymap_Down, Keymap_Primary_Fire
global Keymap_Secondary_Fire, Keymap_Dash, Keymap_Pause

dif_text = convertDifficultyToText(Difficulty)
dif_text = convertDifficultyToText(DifficultyLevel)

#Cleans Name Value
Player_Name = Player_Name.replace("\u001b", "")
Expand Down Expand Up @@ -120,7 +121,7 @@ def save_settings():

def load_default_settings():
global Player_Name, Master_Volume, Music_Volume
global SFX_Volume, Difficulty
global SFX_Volume, DifficultyLevel
global Keymap_Left, Keymap_Right, Keymap_Up
global Keymap_Down, Keymap_Primary_Fire
global Keymap_Secondary_Fire, Keymap_Dash, Keymap_Pause
Expand All @@ -129,7 +130,7 @@ def load_default_settings():
Master_Volume = 100
Music_Volume = 100
SFX_Volume = 100
Difficulty = difficulty.Easy
Difficulty = difficulty.EASY
Keymap_Left = pygame.K_a
Keymap_Right = pygame.K_d
Keymap_Up = pygame.K_w
Expand Down Expand Up @@ -199,11 +200,6 @@ def check_valid_setting_file(path):
easygui.msgbox(
"Invalid File - Sound_Effect Invalid Value (TRUE or FALSE)",
"Error")
if (data["Difficulty"] != "Easy" and data["Difficulty"] != "Medium"
and data["Difficulty"] != "Hard"):
easygui.msgbox(
"Invalid File - Difficulty Invalid Value (Easy, Medium, Hard)",
"Error")
if (type(data["Keymap_Left"]) != int):
easygui.msgbox(
"Invalid File - Keymap_Left Invalid Value (Integer)", "Error")
Expand Down
12 changes: 6 additions & 6 deletions views/settingScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def settings_screen(noises):
easy_image = subtitleFont.render("Easy", True, values.COLOR_Red)
#find width of image
easy_image_width = easy_image.get_width()
if settingIO.Difficulty == settingIO.difficulty.Easy:
if settingIO.DifficultyLevel is settingIO.difficulty.EASY:
pass
elif checkDifCords(easydifficultySettingCords, easy_image):
easy_image = subtitleFont.render("Easy", True, values.COLOR_Yellow)
Expand All @@ -141,7 +141,7 @@ def settings_screen(noises):
screen.get_height() / 16 * 7)
medium_image = subtitleFont.render("Medium", True, values.COLOR_Red)
medium_image_width = medium_image.get_width()
if settingIO.Difficulty == settingIO.difficulty.Medium:
if settingIO.DifficultyLevel is settingIO.difficulty.MEDIUM:
pass
elif checkDifCords(mediumdifficultySettingCords, medium_image):
medium_image = subtitleFont.render("Medium", True, values.COLOR_Yellow)
Expand All @@ -158,7 +158,7 @@ def settings_screen(noises):
harddifficultySettingCords = (left + 30 + widthButton + easy_image_width + 10 + dash_width + 10 + medium_image_width + 10 + dash_width + 10,
screen.get_height() / 16 * 7)
hard_image = subtitleFont.render("Hard", True, values.COLOR_Red)
if settingIO.Difficulty == settingIO.difficulty.Hard:
if settingIO.DifficultyLevel is settingIO.difficulty.HARD:
pass
elif checkDifCords(harddifficultySettingCords, hard_image):
hard_image = subtitleFont.render("Hard", True, values.COLOR_Yellow)
Expand Down Expand Up @@ -244,13 +244,13 @@ def settings_screen(noises):
settingIO.export_settings()
elif checkDifCords(easydifficultySettingCords, easy_image):
noises.playSound("quack")
settingIO.Difficulty = settingIO.difficulty.Easy
settingIO.DifficultyLevel = settingIO.difficulty.EASY
elif checkDifCords(mediumdifficultySettingCords, medium_image):
noises.playSound("quack")
settingIO.Difficulty = settingIO.difficulty.Medium
settingIO.DifficultyLevel = settingIO.difficulty.MEDIUM
elif checkDifCords(harddifficultySettingCords, hard_image):
noises.playSound("quack")
settingIO.Difficulty = settingIO.difficulty.Hard
settingIO.DifficultyLevel = settingIO.difficulty.HARD
elif checkSliderCords(left, 30, master_volume_image, screen,
masterValRange, 3.95):
noises.playSound("quack")
Expand Down

0 comments on commit 895a9f6

Please sign in to comment.