2020-11-27 15:33:17 +00:00
|
|
|
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-11-11 21:22:33 +00:00
|
|
|
from enum import Enum, auto
|
2020-11-11 21:51:02 +00:00
|
|
|
from typing import Optional
|
2020-11-11 21:22:33 +00:00
|
|
|
|
2020-11-19 01:18:08 +00:00
|
|
|
from squirrelbattle.settings import Settings
|
2020-11-11 21:22:33 +00:00
|
|
|
|
2020-11-18 13:56:59 +00:00
|
|
|
# This file contains a few useful enumeration classes used elsewhere in the code
|
2020-11-18 11:19:27 +00:00
|
|
|
|
2020-11-12 00:58:10 +00:00
|
|
|
|
2020-11-11 22:48:46 +00:00
|
|
|
class DisplayActions(Enum):
|
2020-11-18 11:19:27 +00:00
|
|
|
"""
|
|
|
|
Display actions options for the callable displayaction Game uses
|
2020-11-18 13:56:59 +00:00
|
|
|
It just calls the same action on the display object displayaction refers to.
|
2020-11-18 11:19:27 +00:00
|
|
|
"""
|
2020-11-11 22:48:46 +00:00
|
|
|
REFRESH = auto()
|
|
|
|
UPDATE = auto()
|
2020-11-11 21:22:33 +00:00
|
|
|
|
2020-11-12 00:58:10 +00:00
|
|
|
|
2020-11-11 21:22:33 +00:00
|
|
|
class GameMode(Enum):
|
2020-11-18 11:19:27 +00:00
|
|
|
"""
|
|
|
|
Game mode options
|
|
|
|
"""
|
2020-11-11 21:22:33 +00:00
|
|
|
MAINMENU = auto()
|
|
|
|
PLAY = auto()
|
|
|
|
SETTINGS = auto()
|
|
|
|
INVENTORY = auto()
|
2020-12-05 20:43:13 +00:00
|
|
|
STORE = auto()
|
2020-11-11 21:22:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KeyValues(Enum):
|
2020-11-18 11:19:27 +00:00
|
|
|
"""
|
|
|
|
Key values options used in the game
|
|
|
|
"""
|
2020-11-11 21:22:33 +00:00
|
|
|
UP = auto()
|
|
|
|
DOWN = auto()
|
|
|
|
LEFT = auto()
|
|
|
|
RIGHT = auto()
|
|
|
|
ENTER = auto()
|
|
|
|
SPACE = auto()
|
2020-12-03 23:27:25 +00:00
|
|
|
T = auto()
|
2020-11-11 21:22:33 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2020-11-11 21:47:51 +00:00
|
|
|
def translate_key(key: str, settings: Settings) -> Optional["KeyValues"]:
|
2020-11-11 21:22:33 +00:00
|
|
|
"""
|
|
|
|
Translate the raw string key into an enum value that we can use.
|
|
|
|
"""
|
|
|
|
if key in (settings.KEY_DOWN_SECONDARY,
|
|
|
|
settings.KEY_DOWN_PRIMARY):
|
2020-11-11 21:47:51 +00:00
|
|
|
return KeyValues.DOWN
|
2020-11-11 21:22:33 +00:00
|
|
|
elif key in (settings.KEY_LEFT_PRIMARY,
|
|
|
|
settings.KEY_LEFT_SECONDARY):
|
2020-11-11 21:47:51 +00:00
|
|
|
return KeyValues.LEFT
|
2020-11-11 21:22:33 +00:00
|
|
|
elif key in (settings.KEY_RIGHT_PRIMARY,
|
|
|
|
settings.KEY_RIGHT_SECONDARY):
|
2020-11-11 21:47:51 +00:00
|
|
|
return KeyValues.RIGHT
|
2020-11-11 21:22:33 +00:00
|
|
|
elif key in (settings.KEY_UP_PRIMARY,
|
|
|
|
settings.KEY_UP_SECONDARY):
|
2020-11-11 21:47:51 +00:00
|
|
|
return KeyValues.UP
|
2020-11-11 21:22:33 +00:00
|
|
|
elif key == settings.KEY_ENTER:
|
2020-11-11 21:47:51 +00:00
|
|
|
return KeyValues.ENTER
|
2020-11-11 21:22:33 +00:00
|
|
|
elif key == ' ':
|
2020-11-11 21:47:51 +00:00
|
|
|
return KeyValues.SPACE
|
2020-12-03 23:27:25 +00:00
|
|
|
elif key == 't':
|
|
|
|
return KeyValues.T
|
2020-11-11 21:47:51 +00:00
|
|
|
return None
|