Skip to content
Merged

Work #26

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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "tetr_cli"
version = "0.8.0"
version = "1.0.0"
description = "Setup script for the tetr_cli package."
authors = [
{ name = "Airun_Iru", email = "hugo_s_tanaka@yahoo.com" }
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="tetr_cli",
version="0.8.0",
version="1.0.0",
packages=find_packages(),
entry_points={"console_scripts": ["tetr_cli = tetr_cli.starter:starter"]},
python_requires=">=3.7",
Expand Down
61 changes: 40 additions & 21 deletions tetr_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
window,
KEY_RESIZE,
)
from pygame import mixer

from pygame.mixer import Sound

from tetr_cli.tetr_modules.keyboard_handlers.curses_handler import curses_key_name
Expand All @@ -42,24 +42,42 @@
)
from tetr_cli.tetr_modules.modules.debug import DebugClass
from tetr_cli.tetr_modules.modules.database import get_setting
from tetr_cli.tetr_modules.modules.sound import load_sfx, play_sounds
from tetr_cli.tetr_modules.modules.sound import (
load_sfx,
play_sounds,
stop_all_sounds,
update_volume,
)

# O, I, T, L, J, S, Z


TRANSITION_LIST: Dict[str, str] = {
"Main_Menu": "main_menu",
"Solo_Menu": "solo.solo_menu",

# Option Modes
# Audio Options
"Option_Menu": "options.option",
"Audio_Options": "options.audio_options",
# "Gameplay_Options": "options.gameplay_options",

"Audio_Options": "options.audio_options.audio_options",
"BGM_Option": "options.audio_options.bgm_option",
"SFX_Option": "options.audio_options.sfx_option",
# Game Options
"Gameplay_Options": "options.gameplay_options.gameplay_options",
"DAS_Option": "options.gameplay_options.das_option",
"ARR_Option": "options.gameplay_options.arr_option",
"Ghost_Piece_Option": "options.gameplay_options.ghost_piece_option",
# Graphic Options
"Graphic_Options": "options.graphic_options.graphic_options",
"Color_Option": "options.graphic_options.color_option",
"Mino_Style_Option": "options.graphic_options.mino_design",
"FPS_Option": "options.graphic_options.fps_option",
# Control Options
"Control_Options": "options.control_options.control_options",
"Change_Keybind": "options.control_options.change_keybind",
"Score_Screen": "score_screen",

# Solo Modes
"Marathon": "solo.marathon",
"Sprint": "solo.sprint",
"Ultra": "solo.ultra",
}


Expand All @@ -82,8 +100,6 @@ async def main(

audio_check: bool = not no_music_mode
try:
mixer.init()
mixer.music.set_volume(0.25)
sound_effect_dict: Dict[str, Sound] = await load_sfx()
except Exception:
audio_check = False
Expand All @@ -104,13 +120,13 @@ async def main(
use_default_colors()

if curses.COLORS >= 256:
init_pair(1, COLOR_YELLOW, -1) # O
init_pair(2, COLOR_CYAN, -1) # I
init_pair(3, COLOR_MAGENTA, -1) # T
init_pair(1, 214, -1) # O
init_pair(2, 51, -1) # I
init_pair(3, 201, -1) # T
init_pair(4, 208, -1) # L
init_pair(5, COLOR_BLUE, -1) # J
init_pair(6, COLOR_GREEN, -1) # S
init_pair(7, COLOR_RED, -1) # Z
init_pair(5, 27, -1) # J
init_pair(6, 46, -1) # S
init_pair(7, 196, -1) # Z
init_pair(8, 244, -1) # Garbage
else:
init_pair(1, COLOR_YELLOW, -1) # O
Expand All @@ -125,7 +141,7 @@ async def main(
start_time: float = 0.0
elapsed_time: float = 0.0

frame_limit: int = int(get_setting("FPS_limit"))
frame_limit: int = int(get_setting("fps_limit", "30"))
frame_duration: float = 1 / frame_limit

try:
Expand Down Expand Up @@ -194,15 +210,18 @@ async def main(
stdscr.refresh()

if "update_fps" in actions:
frame_limit = int(get_setting("FPS_limit"))
frame_limit = int(get_setting("fps_limit", "30"))
frame_duration = 1 / frame_limit

if "update_volume" in actions and audio_check:
await update_volume(sound_effect_dict=sound_effect_dict)

elapsed_time = perf_counter() - start_time
except KeyboardInterrupt:
pass

if mixer and audio_check:
mixer.music.stop()
mixer.quit()
if audio_check:
await stop_all_sounds()
nocbreak()
noecho()
curs_set(True)
Expand Down
2 changes: 1 addition & 1 deletion tetr_cli/starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"--curses, --ncurses, --c": "Enable ncurses mode for terminal-based UI.",
"--no-music, --nm": "Disable music playback during the game.",
"--reset-db, --reset-database, --r": "Reset the game database to default settings.",
"--input-test, --it": "Run the input test mode to check key inputs.",
}


Expand Down Expand Up @@ -62,7 +63,6 @@ def starter() -> None:
no_music_mode: bool = parse_flag(["--no-music", "-nm"])
reset_database: bool = parse_flag(["--reset-db", "--reset-database", "-r"])
print_help_call: bool = parse_flag(["--help", "-h"])

input_test: bool = parse_flag(["--input-test", "-it"])

if print_help_call:
Expand Down
4 changes: 1 addition & 3 deletions tetr_cli/tetr_modules/menu_core/base_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class BaseModeClass:

def __init__(self) -> None:
"""Initialize the base mode class."""
self.__fps: int = int(get_setting("FPS_limit"))
if self.__fps == 0:
self.__fps = 30
self.__fps: int = int(get_setting("fps_limit", "30"))
self.__action: Dict[str, List[str]] = {}
self.__sound_action: Dict[str, List[str]] = {"BGM": ["stop"], "SFX": []}
self.__user_keybinds: Dict[str, Dict[str, Set[str]]] = load_keybinds()
Expand Down
131 changes: 76 additions & 55 deletions tetr_cli/tetr_modules/menu_core/menu_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
safe_addstr,
)

from tetr_cli.tetr_modules.modules.database import get_setting, set_setting


class VerticalMenuModeClass(BaseModeClass):
"""This class holds the basic features for the menu mode."""
Expand All @@ -25,6 +27,11 @@ def __init__(
self.__options: List[str] = option_list
self.__option_to_action: Dict[str, Dict[str, str]] = option_to_action

@property
def selected_option(self) -> int:
"""This will return the selected option."""
return self.__selected_option

def menu_control(self, pressed_keys: Set) -> None:
"""This will handle the menu controls."""
if self.__key_cooldown > 0:
Expand Down Expand Up @@ -72,84 +79,98 @@ def display_menu(self, stdscr, title: str) -> None:
)


class TwoDimmMenuModeClass(BaseModeClass):
"""This class holds the basic features for the 2D menu mode."""
class SideMenuToggleClass(BaseModeClass):
"""This class will handle option to increase/decrease values."""

def __init__(
self, option_list: List[List[str]], option_to_action: Dict[str, Dict[str, str]]
self,
toggle_name: str,
toggle_to_action: Dict[str, Dict[str, str]],
lower: int,
upper: int,
step: int = 1,
) -> None:
"""This will initialize this class."""
super().__init__()
self.__selected_option: List[int] = [0, 0]
self.__key_cooldown: int = 0
self.__options: List[List[str]] = option_list
self.__option_to_action: Dict[str, Dict[str, str]] = option_to_action
self.__toggle_name: str = toggle_name
self.__toggle_to_action: Dict[str, Dict[str, str]] = toggle_to_action
self.__lower: int = lower
self.__upper: int = upper
self.__step: int = step
self.__current_value: int = int(
get_setting(self.__toggle_name, default_value=str(lower))
)
self.__old_value: int = self.__current_value

@property
def current_value(self) -> int:
"""This will return the current value."""
return self.__current_value

@property
def old_value(self) -> int:
"""This will return the old value."""
return self.__old_value

def menu_control(self, pressed_keys: Set) -> None:
"""This will handle the menu controls."""
if self.__key_cooldown > 0:
self.__key_cooldown -= 1
elif self.get_user_keybind("menu_up", menu_mode=True) & pressed_keys:
self.__selected_option[1] = max(0, self.__selected_option[1] - 1)
self.__key_cooldown = 3
self.sound_action["SFX"].append("select_move")
elif self.get_user_keybind("menu_down", menu_mode=True) & pressed_keys:
self.__selected_option[1] = min(
len(self.__options[0]) - 1, self.__selected_option[1] + 1
)
self.__key_cooldown = 3
self.sound_action["SFX"].append("select_move")
elif self.get_user_keybind("menu_left", menu_mode=True) & pressed_keys:
self.__selected_option[0] = max(0, self.__selected_option[0] - 1)
self.__key_cooldown = 3
self.sound_action["SFX"].append("select_move")
elif self.get_user_keybind("menu_right", menu_mode=True) & pressed_keys:
self.__selected_option[0] = min(
len(self.__options) - 1, self.__selected_option[0] + 1
)
self.__current_value = max(self.__lower, self.__current_value - self.__step)
self.__key_cooldown = 3
elif self.get_user_keybind("menu_right", menu_mode=True) & pressed_keys:
self.sound_action["SFX"].append("select_move")
self.__current_value = min(self.__upper, self.__current_value + self.__step)
self.__key_cooldown = 3
elif self.get_user_keybind("menu_confirm", menu_mode=True) & pressed_keys:
transition_name: str = self.__options[
self.__selected_option[0]
][self.__selected_option[1]]
self.action["transition"] = [
self.__option_to_action[transition_name]["action"]
]
self.sound_action["SFX"].append(
self.__option_to_action[transition_name]["sound"]
)
self.sound_action["SFX"].append("select_confirm")
set_setting(self.__toggle_name, str(self.__current_value))
self.action["transition"] = [self.__toggle_to_action["Confirm"]["action"]]
self.sound_action["SFX"].append(self.__toggle_to_action["Confirm"]["sound"])
elif self.get_user_keybind("menu_back", menu_mode=True) & pressed_keys:
self.action["transition"] = [self.__option_to_action["Go_Back"]["action"]]
self.sound_action["SFX"].append(self.__option_to_action["Go_Back"]["sound"])
self.action["transition"] = [self.__toggle_to_action["Go_Back"]["action"]]
self.sound_action["SFX"].append(self.__toggle_to_action["Go_Back"]["sound"])

def display_menu(self, stdscr, title: str) -> None:
"""This will display the menu."""
def display_toggle(self, stdscr, title: str) -> None:
"""This will display the toggle."""
start_y, start_x, width = calculate_centered_menu(
stdscr, [item for sublist in self.__options for item in sublist]
stdscr, [""]
)

safe_addstr(stdscr, start_y - 2, (width - len(title)) // 2, title, A_BOLD)

for row_index, row in enumerate(self.__options):
for col_index, option in enumerate(row):
prefix: str = " "
attr: int = 0
if (
row_index == self.__selected_option[0]
and col_index == self.__selected_option[1]
):
prefix = "> "
attr = A_REVERSE
option_x = start_x + col_index * (len(option) + 4)
option_y = start_y + row_index
safe_addstr(
stdscr,
option_y,
option_x,
f"{prefix}{option}",
attr,
)
bar_width: int = 20
filled_length = int(
(self.__current_value - self.__lower)
/ (self.__upper - self.__lower)
* bar_width
)
bar: str = (
self.__toggle_name
+ "["
+ "#" * filled_length
+ "-" * (bar_width - filled_length)
+ "]"
)
safe_addstr(
stdscr,
start_y,
start_x - (len(bar) // 2),
bar,
A_REVERSE,
)

value_str = str(self.__current_value).rjust(3)
safe_addstr(
stdscr,
start_y + 1,
start_x - len(value_str) // 2,
value_str,
A_BOLD,
)


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions tetr_cli/tetr_modules/modes/options/audio_options/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""This is an init file for modes.audio_options."""

if __name__ == "__main__":
print("This is an init file for the modes.audio_options, please run starter.py.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""This will handle the audio options menu."""
# coding: utf-8

from typing import Dict, List, Set

from curses import window

from tetr_cli.tetr_modules.menu_core.menu_mode import VerticalMenuModeClass

AUDIO_OPTION_TO_ACTION: Dict[str, Dict[str, str]] = {
"BGM": {"action": "BGM_Option", "sound": "select_confirm"},
"SFX": {"action": "SFX_Option", "sound": "select_confirm"},
"Go_Back": {"action": "Main_Menu", "sound": "select_back"},
}

AUDIO_OPTION_LIST: List[str] = [
"BGM",
"SFX",
"Go_Back",
]


class ModeClass(VerticalMenuModeClass):
"""This will handle the option mode menu."""

def __init__(self) -> None:
"""This will initialize this class."""
super().__init__(AUDIO_OPTION_LIST, AUDIO_OPTION_TO_ACTION)

def increment_frame(self, stdscr: window, pressed_keys: Set[str]) -> None:
"""This will progress the menu based on the inputs."""
self.menu_control(pressed_keys)
self.display_menu(stdscr, "Audio Options")


if __name__ == "__main__":
print("This is a audio_options module, please run starter.py.")
Loading