jo-ruether / led_table

LED table
5 stars 0 forks source link

Suggesting fundamental changes in our software architecture #22

Closed arjunsarin closed 4 years ago

arjunsarin commented 4 years ago

I feel that most of the existing issues cannot be resolved due to the limited capabilities of our architecture. Therefore, I want to suggest some changes to the logic of the program flow.

1) Remove postman The asynchronous communication isn't compatible with a dialog is it is needed for Spotify connect #21. 2) As support for USB controller will be introduced with #3 (maybe also #17) we will have to define a set of commands. Each of these commands can be mapped to a method which may be implemented by a Game. To ensure the mere existence of the methods we add command methods to class Game, e.g. cmd_left(..), cmd_right(..), cmd_action(..) and so on. Note: As command set I would like suggest the SNES controller layout . 3) Introduce class GameWrapper i) Keeps track of the running and all available games. ii) Acts as a broker between input class, e.g. TelegramBot and USB controller, and the games. iii) Can draw the current icon to the table. iv) Starts a new program. (?) v) Note: GameWrapper would take some function from Menu. However I think we need both of them for a clean layout although Menu then only is a placeholder. Or do I miss something?

Why all this? Well, TelegramBot will be past the GameWrapper class on creation. The most important part of GameWrapper is to provide a pointer to the current game instance. Hence, TelegramBot can directly call the game's command methods (see point 2) when receiving a command. Furthermore, the command methods are allowed to return values which trigger bot messages to the user. This addresses #14.

Ok, this out of the depth of my brain. What's your opinion @jo-ruether?

Useful python background knowledge: Pointers in Python: What's the point?

arjunsarin commented 4 years ago

New features we may want to create:

File created during discussion:

from table.games.Snake import Snake

class GameWrapper:
    games = [Tetris(), Snake]

    def __init__(self):

    @property
    def running_game(self):
        # Return running game
        # For access to TelgramBot and Input

        return games[running_game]

    def run(self):
        menu = Menu()

        while True:
            selected_game = menu.run(games)

            # Start selected game
            games[selected_game].run()

    # TelegramBot:
    GameWrapper.running_game.cmd_queue.put('left')
    GameWrapper.running_game.cmd_queue.put('exit')
    GameWrapper.running_game.get_telegram_layout()
    GameWrapper.running_game.get_cmd_list()

    # Game:
    reply_keyboard = [['play'], ['next', 'prev']]
    reply_markup = ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=False)