-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_menu_model.py
52 lines (38 loc) · 1.52 KB
/
main_menu_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from types import ModuleType
from typing import Set, Tuple
class Entry:
def __init__(self, text, on_select_func, on_hover_start_func, on_hover_end_func, does_close_menu):
self.text = text
self._on_select_func = on_select_func
self._on_hover_start_func = on_hover_start_func
self._on_hover_end_func = on_hover_end_func
self.does_close_menu = does_close_menu
def select(self):
if self._on_select_func:
self._on_select_func()
def start_hover(self):
if self._on_hover_start_func:
self._on_hover_start_func()
def end_hover(self):
if self._on_hover_end_func:
self._on_hover_end_func()
class MainMenuModel:
def __init__(self, entries, game_key_binding_manager):
self.entries = entries
self._game_key_binding_manager = game_key_binding_manager
self.current_index = 0
def change_current_index(self, delta_index):
self.current_index = (self.current_index + delta_index) % len(self.entries)
def get_current_entry(self):
return self.entries[self.current_index]
def get_control_lines(self):
return self._game_key_binding_manager.get_control_lines()
def run_tests(headless: bool) -> Tuple[Tuple[int, int], Set[ModuleType]]:
"""
@return ((failure_count, test_count), tested_modules)
"""
import sys
import test
return test.run_doctests(sys.modules[__name__], module_dependencies=[], headless=headless)
if __name__ == '__main__':
run_tests(headless=False)