From a497d08f316a5f2d80758fc0c017599eccc397ec Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 8 Jan 2021 15:48:12 +0100 Subject: [PATCH] Implement the monocle of truth, closes #62 --- squirrelbattle/display/statsdisplay.py | 42 +++++++++++++++---- squirrelbattle/display/texturepack.py | 2 + squirrelbattle/entities/items.py | 10 ++++- squirrelbattle/game.py | 2 +- squirrelbattle/interfaces.py | 16 +++---- .../locale/de/LC_MESSAGES/squirrelbattle.po | 24 ++++++----- .../locale/es/LC_MESSAGES/squirrelbattle.po | 24 ++++++----- .../locale/fr/LC_MESSAGES/squirrelbattle.po | 24 ++++++----- squirrelbattle/tests/game_test.py | 1 + squirrelbattle/tests/translations_test.py | 1 + 10 files changed, 97 insertions(+), 49 deletions(-) diff --git a/squirrelbattle/display/statsdisplay.py b/squirrelbattle/display/statsdisplay.py index 91b85b9..a60f6a2 100644 --- a/squirrelbattle/display/statsdisplay.py +++ b/squirrelbattle/display/statsdisplay.py @@ -3,10 +3,10 @@ import curses +from ..entities.items import Monocle from ..entities.player import Player from ..game import Game -from ..interfaces import FriendlyEntity -from ..settings import Settings +from ..interfaces import FightingEntity from ..translations import gettext as _ from .display import Display @@ -87,16 +87,40 @@ class StatsDisplay(Display): self.addstr(self.pad, self.height - 2, 0, msg, italic=True, reverse=True) + self.update_entities_stats() + + def update_entities_stats(self) -> None: + """ + Display information about a near entity if we have a monocle. + """ for dy, dx in [(-1, 0), (0, -1), (0, 1), (1, 0)]: - for entity in self.player.map.find_entities(FriendlyEntity): + for entity in self.player.map.find_entities(FightingEntity): + if entity == self.player: + continue + if entity.y == self.player.y + dy \ and entity.x == self.player.x + dx: - msg = _("Move to the friendly entity to talk to it") \ - if self.game.waiting_for_friendly_key else \ - _("Use {key} then move to talk to the entity") \ - .format(key=self.game.settings.KEY_CHAT.upper()) - self.addstr(self.pad, self.height - 1, 0, msg, - italic=True, reverse=True) + if entity.is_friendly(): + msg = _("Move to the friendly entity to talk to it") \ + if self.game.waiting_for_friendly_key else \ + _("Use {key} then move to talk to the entity") \ + .format(key=self.game.settings.KEY_CHAT.upper()) + self.addstr(self.pad, self.height - 1, 0, msg, + italic=True, reverse=True) + + if isinstance(self.player.equipped_secondary, Monocle): + # Truth monocle + message = f"{entity.translated_name.capitalize()} " \ + f"{self.pack[entity.name.upper()]}\n" \ + f"STR {entity.strength}\n" \ + f"INT {entity.intelligence}\n" \ + f"CHR {entity.charisma}\n" \ + f"DEX {entity.dexterity}\n" \ + f"CON {entity.constitution}\n" \ + f"CRI {entity.critical}%" + self.addstr(self.pad, 17, 0, message) + # Only display one entity + break def display(self) -> None: self.pad.erase() diff --git a/squirrelbattle/display/texturepack.py b/squirrelbattle/display/texturepack.py index 1fa0584..34c76ee 100644 --- a/squirrelbattle/display/texturepack.py +++ b/squirrelbattle/display/texturepack.py @@ -84,6 +84,7 @@ TexturePack.ASCII_PACK = TexturePack( HEDGEHOG='*', HELMET='0', MERCHANT='M', + MONOCLE='ô', PLAYER='@', RABBIT='Y', RING_OF_CRITICAL_DAMAGE='o', @@ -121,6 +122,7 @@ TexturePack.SQUIRREL_PACK = TexturePack( HELMET='⛑️ ', PLAYER='🐿️ ️', MERCHANT='🦜', + MONOCLE='🧐', RABBIT='🐇', RING_OF_CRITICAL_DAMAGE='💍', RING_OF_MORE_EXPERIENCE='💍', diff --git a/squirrelbattle/entities/items.py b/squirrelbattle/entities/items.py index dab346c..25244cd 100644 --- a/squirrelbattle/entities/items.py +++ b/squirrelbattle/entities/items.py @@ -86,8 +86,8 @@ class Item(Entity): """ Returns the list of all item classes. """ - return [BodySnatchPotion, Bomb, Heart, Shield, Sword, - Chestplate, Helmet, RingCritical, RingXP] + return [BodySnatchPotion, Chestplate, Bomb, Heart, Helmet, Monocle, + Shield, Sword, RingCritical, RingXP] def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool: """ @@ -453,3 +453,9 @@ class RingXP(Ring): experience: float = 2, *args, **kwargs): super().__init__(name=name, price=price, experience=experience, *args, **kwargs) + + +class Monocle(Item): + def __init__(self, name: str = "monocle", price: int = 10, + *args, **kwargs): + super().__init__(name=name, price=price, *args, **kwargs) diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 837e753..5cb3762 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -345,7 +345,7 @@ class Game: try: self.map_index = d["map_index"] self.maps = [Map().load_state(map_dict) for map_dict in d["maps"]] - except KeyError: + except KeyError as e: self.message = _("Some keys are missing in your save file.\n" "Your save seems to be corrupt. It got deleted.") os.unlink(ResourceManager.get_config_path("save.json")) diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 19ee25c..900067c 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -635,24 +635,26 @@ class Entity: from squirrelbattle.entities.friendly import Merchant, Sunflower, \ Trumpet from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \ - Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP + Heart, Monocle, Sword, Shield, Chestplate, Helmet, \ + RingCritical, RingXP return { - "Tiger": Tiger, "Bomb": Bomb, + "Chestplate": Chestplate, "Heart": Heart, "BodySnatchPotion": BodySnatchPotion, + "Eagle": GiantSeaEagle, "Hedgehog": Hedgehog, - "Rabbit": Rabbit, - "TeddyBear": TeddyBear, + "Helmet": Helmet, "Player": Player, "Merchant": Merchant, + "Monocle": Monocle, "Sunflower": Sunflower, "Sword": Sword, "Trumpet": Trumpet, - "Eagle": GiantSeaEagle, "Shield": Shield, - "Chestplate": Chestplate, - "Helmet": Helmet, + "TeddyBear": TeddyBear, + "Tiger": Tiger, + "Rabbit": Rabbit, "RingCritical": RingCritical, "RingXP": RingXP, } diff --git a/squirrelbattle/locale/de/LC_MESSAGES/squirrelbattle.po b/squirrelbattle/locale/de/LC_MESSAGES/squirrelbattle.po index e55e2a1..2cea0a3 100644 --- a/squirrelbattle/locale/de/LC_MESSAGES/squirrelbattle.po +++ b/squirrelbattle/locale/de/LC_MESSAGES/squirrelbattle.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: squirrelbattle 3.14.1\n" "Report-Msgid-Bugs-To: squirrel-battle@crans.org\n" -"POT-Creation-Date: 2021-01-08 15:04+0100\n" +"POT-Creation-Date: 2021-01-08 15:15+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -49,40 +49,40 @@ msgstr "BESTAND" msgid "STALL" msgstr "STAND" -#: squirrelbattle/display/statsdisplay.py:46 +#: squirrelbattle/display/statsdisplay.py:44 msgid "Inventory:" msgstr "Bestand:" -#: squirrelbattle/display/statsdisplay.py:63 +#: squirrelbattle/display/statsdisplay.py:61 msgid "Equipped main:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:67 +#: squirrelbattle/display/statsdisplay.py:65 msgid "Equipped secondary:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:72 +#: squirrelbattle/display/statsdisplay.py:70 msgid "Equipped chestplate:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:76 +#: squirrelbattle/display/statsdisplay.py:74 msgid "Equipped helmet:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:83 +#: squirrelbattle/display/statsdisplay.py:81 msgid "YOU ARE DEAD" msgstr "SIE WURDEN GESTORBEN" -#: squirrelbattle/display/statsdisplay.py:87 +#: squirrelbattle/display/statsdisplay.py:85 #, python-brace-format msgid "Use {key} to use the ladder" msgstr "" -#: squirrelbattle/display/statsdisplay.py:96 +#: squirrelbattle/display/statsdisplay.py:94 msgid "Move to the friendly entity to talk to it" msgstr "" -#: squirrelbattle/display/statsdisplay.py:98 +#: squirrelbattle/display/statsdisplay.py:96 #, python-brace-format msgid "Use {key} then move to talk to the entity" msgstr "" @@ -347,3 +347,7 @@ msgstr "" #: squirrelbattle/tests/translations_test.py:82 msgid "ring of more experience" msgstr "" + +#: squirrelbattle/tests/translations_test.py:84 +msgid "monocle" +msgstr "" diff --git a/squirrelbattle/locale/es/LC_MESSAGES/squirrelbattle.po b/squirrelbattle/locale/es/LC_MESSAGES/squirrelbattle.po index aaa59cc..18868c3 100644 --- a/squirrelbattle/locale/es/LC_MESSAGES/squirrelbattle.po +++ b/squirrelbattle/locale/es/LC_MESSAGES/squirrelbattle.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: squirrelbattle 3.14.1\n" "Report-Msgid-Bugs-To: squirrel-battle@crans.org\n" -"POT-Creation-Date: 2021-01-08 15:04+0100\n" +"POT-Creation-Date: 2021-01-08 15:15+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -49,40 +49,40 @@ msgstr "INVENTORIO" msgid "STALL" msgstr "PUESTO" -#: squirrelbattle/display/statsdisplay.py:46 +#: squirrelbattle/display/statsdisplay.py:44 msgid "Inventory:" msgstr "Inventorio :" -#: squirrelbattle/display/statsdisplay.py:63 +#: squirrelbattle/display/statsdisplay.py:61 msgid "Equipped main:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:67 +#: squirrelbattle/display/statsdisplay.py:65 msgid "Equipped secondary:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:72 +#: squirrelbattle/display/statsdisplay.py:70 msgid "Equipped chestplate:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:76 +#: squirrelbattle/display/statsdisplay.py:74 msgid "Equipped helmet:" msgstr "" -#: squirrelbattle/display/statsdisplay.py:83 +#: squirrelbattle/display/statsdisplay.py:81 msgid "YOU ARE DEAD" msgstr "ERES MUERTO" -#: squirrelbattle/display/statsdisplay.py:87 +#: squirrelbattle/display/statsdisplay.py:85 #, python-brace-format msgid "Use {key} to use the ladder" msgstr "" -#: squirrelbattle/display/statsdisplay.py:96 +#: squirrelbattle/display/statsdisplay.py:94 msgid "Move to the friendly entity to talk to it" msgstr "" -#: squirrelbattle/display/statsdisplay.py:98 +#: squirrelbattle/display/statsdisplay.py:96 #, python-brace-format msgid "Use {key} then move to talk to the entity" msgstr "" @@ -346,3 +346,7 @@ msgstr "" #: squirrelbattle/tests/translations_test.py:82 msgid "ring of more experience" msgstr "" + +#: squirrelbattle/tests/translations_test.py:84 +msgid "monocle" +msgstr "" diff --git a/squirrelbattle/locale/fr/LC_MESSAGES/squirrelbattle.po b/squirrelbattle/locale/fr/LC_MESSAGES/squirrelbattle.po index f55fa7e..4657fe8 100644 --- a/squirrelbattle/locale/fr/LC_MESSAGES/squirrelbattle.po +++ b/squirrelbattle/locale/fr/LC_MESSAGES/squirrelbattle.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: squirrelbattle 3.14.1\n" "Report-Msgid-Bugs-To: squirrel-battle@crans.org\n" -"POT-Creation-Date: 2021-01-08 15:04+0100\n" +"POT-Creation-Date: 2021-01-08 15:15+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -43,40 +43,40 @@ msgstr "INVENTAIRE" msgid "STALL" msgstr "STAND" -#: squirrelbattle/display/statsdisplay.py:46 +#: squirrelbattle/display/statsdisplay.py:44 msgid "Inventory:" msgstr "Inventaire :" -#: squirrelbattle/display/statsdisplay.py:63 +#: squirrelbattle/display/statsdisplay.py:61 msgid "Equipped main:" msgstr "Équipement principal :" -#: squirrelbattle/display/statsdisplay.py:67 +#: squirrelbattle/display/statsdisplay.py:65 msgid "Equipped secondary:" msgstr "Équipement secondaire :" -#: squirrelbattle/display/statsdisplay.py:72 +#: squirrelbattle/display/statsdisplay.py:70 msgid "Equipped chestplate:" msgstr "Plastron équipé :" -#: squirrelbattle/display/statsdisplay.py:76 +#: squirrelbattle/display/statsdisplay.py:74 msgid "Equipped helmet:" msgstr "Casque équipé :" -#: squirrelbattle/display/statsdisplay.py:83 +#: squirrelbattle/display/statsdisplay.py:81 msgid "YOU ARE DEAD" msgstr "VOUS ÊTES MORT" -#: squirrelbattle/display/statsdisplay.py:87 +#: squirrelbattle/display/statsdisplay.py:85 #, python-brace-format msgid "Use {key} to use the ladder" msgstr "Appuyez sur {key} pour utiliser l'échelle" -#: squirrelbattle/display/statsdisplay.py:96 +#: squirrelbattle/display/statsdisplay.py:94 msgid "Move to the friendly entity to talk to it" msgstr "Avancez vers l'entité pour lui parler" -#: squirrelbattle/display/statsdisplay.py:98 +#: squirrelbattle/display/statsdisplay.py:96 #, python-brace-format msgid "Use {key} then move to talk to the entity" msgstr "Appuyez sur {key} puis déplacez-vous pour parler" @@ -341,3 +341,7 @@ msgstr "anneau de coup critique" #: squirrelbattle/tests/translations_test.py:82 msgid "ring of more experience" msgstr "anneau de plus d'expérience" + +#: squirrelbattle/tests/translations_test.py:84 +msgid "monocle" +msgstr "monocle" diff --git a/squirrelbattle/tests/game_test.py b/squirrelbattle/tests/game_test.py index dab0e7e..785cd6a 100644 --- a/squirrelbattle/tests/game_test.py +++ b/squirrelbattle/tests/game_test.py @@ -66,6 +66,7 @@ class TestGame(unittest.TestCase): new_state = self.game.save_state() self.assertEqual(old_state, new_state) + self.assertIsNone(self.game.message) # Ensure that the bomb is loaded self.assertTrue(self.game.player.inventory) diff --git a/squirrelbattle/tests/translations_test.py b/squirrelbattle/tests/translations_test.py index 54581f3..bdf0238 100644 --- a/squirrelbattle/tests/translations_test.py +++ b/squirrelbattle/tests/translations_test.py @@ -81,3 +81,4 @@ class TestTranslations(unittest.TestCase): "anneau de coup critique") self.assertEqual(_("ring of more experience"), "anneau de plus d'expérience") + self.assertEqual(_("monocle"), "monocle")