Grimmys / rpg_tactical_fantasy_game

A tactical turn-based game project in pygame, open to support
GNU General Public License v3.0
392 stars 85 forks source link

Enhance #31 left click outside of a menu or Esc to leave it. #66

Closed JimZhouZZY closed 11 months ago

JimZhouZZY commented 11 months ago

Add feature:

  1. Left clicking outside a menu to leave a menu.
  2. Press Escape key to leave a menu.

Add interface for key operation. Now we can add key binding in "level_scene.py" like this:

...
 def key_down(self, keyname):
        ...
        if keyname == pygame.K_ESCAPE:
            self.leave_menu()
...
Grimmys commented 11 months ago

Feature is working well, good job!

Just waiting for the small refactor to be done.

JimZhouZZY commented 11 months ago

I'm so sorry I made this ill-advised edit. I realised how stupid is was. And I modified the code seriously.

Here are the modified functions on clicks/keys. Please let me know if any funtion need to be changed.

And Replying to:

My suggestion: call this method inside of right click instead of having the same piece of code twice.

I deleted the method leave_menu, because it doesn't have a good practicality.

Grimmys commented 11 months ago

I'm so sorry I made this ill-advised edit. I realised how stupid is was. And I modified the code seriously.

No no no and definitely no, you don't have to be sorry for the work you are producing. In development, everyone makes "mistakes" all the time, even seniors. And what may be considered an error by someone might not be for someone else. Everything is about point of view! Solutions should be debated, and we need to think about whether or not what we did make sense, but not blame ourselves and feel bad about it.

JimZhouZZY commented 11 months ago

I'm so sorry I made this ill-advised edit. I realised how stupid is was. And I modified the code seriously.

No no no and definitely no, you don't have to be sorry for the work you are producing. In development, everyone makes "mistakes" all the time, even seniors. And what may be considered an error by someone might not be for someone else. Everything is about point of view! Solutions should be debated, and we need to think about whether or not what we did make sense, but not blame ourselves and feel bad about it.

Thank you for your kind words. I appreciate your encouragement and support. I’m still learning and trying to improve my skills, so it’s good to know that the community is so accommodating and easy-going. I’ll keep your advice in mind and try to do better next time. Thanks again!

JimZhouZZY commented 11 months ago

I'm confused with the Unit tests. Sometimes it passes, but sometimes fails. Always on the line self.assertIsInstance(self.start_screen.level, self.level_class).

======================================================================
FAIL: test_load_existent_save (tests.test_start_screen.TestStartScreen)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/rpg_tactical_fantasy_game/rpg_tactical_fantasy_game/tests/test_start_screen.py", line 147, in test_load_existent_save
    self.assertIsInstance(self.start_screen.level, self.level_class)
AssertionError: None is not an instance of <class 'src.scenes.level_scene.LevelScene'>

----------------------------------------------------------------------
Ran 110 tests in 27.345s
Grimmys commented 11 months ago

Yes I noticed it, but it's passing most of the time, and the test doesn't look related to the changes you did.

I'm assuming it's just a flakky test (i.e., test wrongly failling sometimes) because the position is randomly generated. Will investigate it later.