2021-01-10 10:46:17 +01:00
|
|
|
# Copyright (C) 2020-2021 by ÿnérant, eichhornchen, nicomarg, charlse
|
2020-11-27 16:33:17 +01:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-01-10 11:25:53 +01:00
|
|
|
from enum import auto, Enum
|
2020-11-11 22:51:02 +01:00
|
|
|
from typing import Optional
|
2020-11-11 22:22:33 +01:00
|
|
|
|
2020-11-19 02:18:08 +01:00
|
|
|
from squirrelbattle.settings import Settings
|
2020-11-11 22:22:33 +01:00
|
|
|
|
2020-11-18 14:56:59 +01:00
|
|
|
# This file contains a few useful enumeration classes used elsewhere in the code
|
2020-11-18 12:19:27 +01:00
|
|
|
|
2020-11-12 01:58:10 +01:00
|
|
|
|
2020-11-11 23:48:46 +01:00
|
|
|
class DisplayActions(Enum):
|
2020-11-18 12:19:27 +01:00
|
|
|
"""
|
|
|
|
Display actions options for the callable displayaction Game uses
|
2020-11-18 14:56:59 +01:00
|
|
|
It just calls the same action on the display object displayaction refers to.
|
2020-11-18 12:19:27 +01:00
|
|
|
"""
|
2020-11-11 23:48:46 +01:00
|
|
|
REFRESH = auto()
|
|
|
|
UPDATE = auto()
|
2020-12-11 16:56:22 +01:00
|
|
|
MOUSE = auto()
|
2020-11-11 22:22:33 +01:00
|
|
|
|
2020-11-12 01:58:10 +01:00
|
|
|
|
2020-11-11 22:22:33 +01:00
|
|
|
class GameMode(Enum):
|
2020-11-18 12:19:27 +01:00
|
|
|
"""
|
2020-12-13 21:29:25 +01:00
|
|
|
Game mode options.
|
2020-11-18 12:19:27 +01:00
|
|
|
"""
|
2020-11-11 22:22:33 +01:00
|
|
|
MAINMENU = auto()
|
|
|
|
PLAY = auto()
|
|
|
|
SETTINGS = auto()
|
|
|
|
INVENTORY = auto()
|
2020-12-05 21:43:13 +01:00
|
|
|
STORE = auto()
|
2021-01-08 23:15:48 +01:00
|
|
|
CHEST = auto()
|
2020-12-18 22:24:41 +01:00
|
|
|
CREDITS = auto()
|
2020-11-11 22:22:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
class KeyValues(Enum):
|
2020-11-18 12:19:27 +01:00
|
|
|
"""
|
2020-12-13 21:29:25 +01:00
|
|
|
Key values options used in the game.
|
2020-11-18 12:19:27 +01:00
|
|
|
"""
|
2020-11-11 22:22:33 +01:00
|
|
|
UP = auto()
|
|
|
|
DOWN = auto()
|
|
|
|
LEFT = auto()
|
|
|
|
RIGHT = auto()
|
|
|
|
ENTER = auto()
|
2020-12-04 14:41:59 +01:00
|
|
|
INVENTORY = auto()
|
2020-12-04 16:53:27 +01:00
|
|
|
USE = auto()
|
|
|
|
EQUIP = auto()
|
|
|
|
DROP = auto()
|
2020-11-11 22:22:33 +01:00
|
|
|
SPACE = auto()
|
2020-12-09 15:32:37 +01:00
|
|
|
CHAT = auto()
|
2020-12-12 18:12:37 +01:00
|
|
|
WAIT = auto()
|
2021-01-06 14:55:16 +01:00
|
|
|
LADDER = auto()
|
2021-01-08 18:06:26 +01:00
|
|
|
LAUNCH = auto()
|
2021-01-10 17:10:00 +01:00
|
|
|
DANCE = auto()
|
2020-11-11 22:22:33 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2021-01-10 19:17:04 +01:00
|
|
|
def translate_key(key: str, settings: Settings) \
|
|
|
|
-> Optional["KeyValues"]: # noqa: C901
|
2020-11-11 22:22:33 +01:00
|
|
|
"""
|
2020-12-13 21:29:25 +01:00
|
|
|
Translates the raw string key into an enum value that we can use.
|
2020-11-11 22:22:33 +01:00
|
|
|
"""
|
2020-12-11 18:17:59 +01:00
|
|
|
if key in (settings.KEY_DOWN_SECONDARY,
|
|
|
|
settings.KEY_DOWN_PRIMARY):
|
2020-11-11 22:47:51 +01:00
|
|
|
return KeyValues.DOWN
|
2020-11-11 22:22:33 +01:00
|
|
|
elif key in (settings.KEY_LEFT_PRIMARY,
|
|
|
|
settings.KEY_LEFT_SECONDARY):
|
2020-11-11 22:47:51 +01:00
|
|
|
return KeyValues.LEFT
|
2020-11-11 22:22:33 +01:00
|
|
|
elif key in (settings.KEY_RIGHT_PRIMARY,
|
|
|
|
settings.KEY_RIGHT_SECONDARY):
|
2020-11-11 22:47:51 +01:00
|
|
|
return KeyValues.RIGHT
|
2020-11-11 22:22:33 +01:00
|
|
|
elif key in (settings.KEY_UP_PRIMARY,
|
|
|
|
settings.KEY_UP_SECONDARY):
|
2020-11-11 22:47:51 +01:00
|
|
|
return KeyValues.UP
|
2020-11-11 22:22:33 +01:00
|
|
|
elif key == settings.KEY_ENTER:
|
2020-11-11 22:47:51 +01:00
|
|
|
return KeyValues.ENTER
|
2020-12-04 14:41:59 +01:00
|
|
|
elif key == settings.KEY_INVENTORY:
|
|
|
|
return KeyValues.INVENTORY
|
2020-12-04 16:53:27 +01:00
|
|
|
elif key == settings.KEY_USE:
|
|
|
|
return KeyValues.USE
|
|
|
|
elif key == settings.KEY_EQUIP:
|
|
|
|
return KeyValues.EQUIP
|
|
|
|
elif key == settings.KEY_DROP:
|
|
|
|
return KeyValues.DROP
|
2020-11-11 22:22:33 +01:00
|
|
|
elif key == ' ':
|
2020-11-11 22:47:51 +01:00
|
|
|
return KeyValues.SPACE
|
2020-12-09 15:32:37 +01:00
|
|
|
elif key == settings.KEY_CHAT:
|
|
|
|
return KeyValues.CHAT
|
2020-12-12 18:12:37 +01:00
|
|
|
elif key == settings.KEY_WAIT:
|
|
|
|
return KeyValues.WAIT
|
2021-01-06 14:55:16 +01:00
|
|
|
elif key == settings.KEY_LADDER:
|
|
|
|
return KeyValues.LADDER
|
2021-01-08 18:06:26 +01:00
|
|
|
elif key == settings.KEY_LAUNCH:
|
|
|
|
return KeyValues.LAUNCH
|
2021-01-10 17:10:00 +01:00
|
|
|
elif key == settings.KEY_DANCE:
|
|
|
|
return KeyValues.DANCE
|