Skip to content

Commit

Permalink
Merge pull request #217 from pygamelib/1.4.x
Browse files Browse the repository at this point in the history
1.4.x
  • Loading branch information
arnauddupuis committed Oct 26, 2022
2 parents 59f7d08 + 9080e7a commit b12ce0d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 207 deletions.
5 changes: 0 additions & 5 deletions docs/source/pygamelib.engine.Game.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Game
~Game.actuate_npcs
~Game.actuate_projectiles
~Game.add_board
~Game.add_menu_entry
~Game.add_npc
~Game.add_projectile
~Game.animate_items
Expand All @@ -34,14 +33,11 @@ Game
~Game.current_board
~Game.delete_all_levels
~Game.delete_level
~Game.delete_menu_category
~Game.detach
~Game.display_board
~Game.display_menu
~Game.display_player_stats
~Game.get_board
~Game.get_key
~Game.get_menu_entry
~Game.handle_notification
~Game.insert_board
~Game.instance
Expand All @@ -60,7 +56,6 @@ Game
~Game.start
~Game.stop
~Game.store_screen_position
~Game.update_menu_entry



Expand Down
178 changes: 0 additions & 178 deletions pygamelib/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,6 @@ def __init__(
name="Game",
player=None,
boards={},
menu={},
current_level=None,
enable_partial_display=False,
partial_display_viewport=None,
Expand Down Expand Up @@ -1830,7 +1829,6 @@ def __init__(
super().__init__()
self.name = name
self._boards = boards
self._menu = menu
self.current_level = current_level
self.player = player
self.__state = constants.RUNNING
Expand Down Expand Up @@ -2090,182 +2088,6 @@ def clear_session_logs(self) -> None:
"""
self._logs = list()

def add_menu_entry(self, category, shortcut, message, data=None):
"""Add a new entry to the menu.
.. deprecated:: 1.3.0
This function will be removed in version 1.4.0
Add another shortcut and message to the specified category.
Categories help organize the different sections of a menu or dialogues.
:param category: The category to which the entry should be added.
:type category: str
:param shortcut: A shortcut (usually one key) to display.
:type shortcut: str
:param message: a message that explains what the shortcut does.
:type message: str
:param data: a data that you can get from the menu object.
:type message: various
The shortcut and data is optional.
Example::
game.add_menu_entry('main_menu','d','Go right',constants.RIGHT)
game.add_menu_entry('main_menu',None,'-----------------')
game.add_menu_entry('main_menu','v','Change game speed')
"""
if category in self._menu.keys():
self._menu[category].append(
{"shortcut": shortcut, "message": message, "data": data}
)
else:
self._menu[category] = [
{"shortcut": shortcut, "message": message, "data": data}
]

def delete_menu_category(self, category=None):
"""Delete an entire category from the menu.
.. deprecated:: 1.3.0
This function will be removed in version 1.4.0
That function removes the entire list of messages that are attached to the
category.
:param category: The category to delete.
:type category: str
:raise PglInvalidTypeException: If the category is not a string
.. important:: If the entry have no shortcut it's advised not to try to update
unless you have only one NoneType as a shortcut.
Example::
game.add_menu_entry('main_menu','d','Go right')
game.update_menu_entry('main_menu','d','Go LEFT',constants.LEFT)
"""
if type(category) is str and category in self._menu:
del self._menu[category]
else:
raise base.PglInvalidTypeException(
"in Game.delete_menu_entry(): category cannot be anything else but a"
"string."
)

def update_menu_entry(self, category, shortcut, message, data=None):
"""Update an entry of the menu.
.. deprecated:: 1.3.0
This function will be removed in version 1.4.0
Update the message associated to a category and a shortcut.
:param category: The category in which the entry is located.
:type category: str
:param shortcut: The shortcut of the entry you want to update.
:type shortcut: str
:param message: a message that explains what the shortcut does.
:type message: str
:param data: a data that you can get from the menu object.
:type message: various
.. important:: If the entry have no shortcut it's advised not to try to update
unless you have only one NoneType as a shortcut.
Example::
game.add_menu_entry('main_menu','d','Go right')
game.update_menu_entry('main_menu','d','Go LEFT',constants.LEFT)
"""
for e in self._menu[category]:
if e["shortcut"] == shortcut:
e["message"] = message
if data is not None:
e["data"] = data

def get_menu_entry(self, category, shortcut):
"""Get an entry of the menu.
.. deprecated:: 1.3.0
This function will be removed in version 1.4.0
This method return a dictionnary with 3 entries :
* shortcut
* message
* data
:param category: The category in which the entry is located.
:type category: str
:param shortcut: The shortcut of the entry you want to get.
:type shortcut: str
:return: The menu entry or None if none was found
:rtype: dict
Example::
ent = game.get_menu_entry('main_menu','d')
game.move_player(int(ent['data']),1)
"""
if category in self._menu:
for e in self._menu[category]:
if e["shortcut"] == shortcut:
return e
return None

def display_menu(
self, category, orientation=constants.ORIENTATION_VERTICAL, paginate=10
):
"""Display the menu.
.. deprecated:: 1.3.0
This function will be removed in version 1.4.0
This method display the whole menu for a given category.
:param category: The category to display. **Mandatory** parameter.
:type category: str
:param orientation: The shortcut of the entry you want to get.
:type orientation: :class:`pygamelib.constants`
:param paginate: pagination parameter (how many items to display before
changing line or page).
:type paginate: int
Example::
game.display_menu('main_menu')
game.display_menu('main_menu', constants.ORIENTATION_HORIZONTAL, 5)
"""
line_end = "\n"
if orientation == constants.ORIENTATION_HORIZONTAL:
line_end = " | "
if category not in self._menu:
raise base.PglException(
"invalid_menu_category",
f"The '{category}' category is not registered in the menu. Did you add"
f"a menu entry in that category with Game.add_menu_entry('{category}',"
f"'some shortcut','some message') ? If yes, then you should check "
f"for typos.",
)
pagination_counter = 1
for k in self._menu[category]:
if k["shortcut"] is None:
print(k["message"], end=line_end)
else:
print(f"{k['shortcut']} - {k['message']}", end=line_end)
pagination_counter += 1
if pagination_counter > paginate:
print("")
pagination_counter = 1

def clear_screen(self):
"""
Clear the whole screen (i.e: remove everything written in terminal)
Expand Down
24 changes: 0 additions & 24 deletions tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,6 @@ def user_update_paused_placeholder(g, i, dt):
g.run()
self.assertEqual(g.state, constants.STOPPED)

def test_menu(self):
game = engine.Game()
self.assertIsNone(
game.add_menu_entry("main_menu", "d", "Go right", constants.RIGHT)
)
self.assertIsNone(game.add_menu_entry("main_menu", None, "-----------------"))
self.assertIsNone(game.add_menu_entry("main_menu", "v", "Change game speed"))
self.assertIsNone(game.add_menu_entry("destroy", None, "-----------------"))
self.assertIsNone(game.delete_menu_category("destroy"))
with self.assertRaises(base.PglInvalidTypeException):
game.delete_menu_category(12)
self.assertIsNone(
game.update_menu_entry("main_menu", "d", "Go LEFT", constants.LEFT)
)
self.assertIsNone(game.get_menu_entry("main_menu_bork", "d"))
self.assertEqual(game.get_menu_entry("main_menu", "d")["data"], constants.LEFT)
self.assertIsNone(
game.display_menu("main_menu", constants.ORIENTATION_HORIZONTAL, 1)
)
with self.assertRaises(base.PglException) as e:
game.display_menu("main_menu_bork")
self.assertEqual(e.exception.error, "invalid_menu_category")
self.assertIsNone(game.clear_screen())

def test_config(self):
g = engine.Game()
self.assertIsNone(g.create_config("high_scores"))
Expand Down

0 comments on commit b12ce0d

Please sign in to comment.