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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# FortuneEngine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FortuneEngine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the FortuneEngine. If not, see <http://www.gnu.org/licenses/>.
#
# Author: Justin Lewis <jlew.blackout@gmail.com>
from pyconsole.pyconsole import Console
class GameEngineConsole(Console):
"""
GameEngineConsole is a class that extends the pyconsole adding
in game engine specific functions.
"""
def __init__(self, gei, pos):
"""
Init function of the GameEngineConsole
@param gei: Passing in the Game Engine Instance.
@param pos: The position tuple to place the pyconsole
(startx, starty, width, height)
"""
# functions exposed to the console
function_list = {
"quit": gei.stop_event_loop,
"list_objects": gei.list_objects,
"list_drawcb": gei.list_draw_callbacks,
"list_eventcb": gei.list_event_callbacks,
"list_timers": gei.list_event_timers,
"inspect": gei._inspector.inspect_object,
"profile_draw":gei.list_draw_time,
"profile_event":gei.list_event_time,
"profile_timer":gei.list_timer_time,
"set_str": gei._inspector.set_str,
"set_int": gei._inspector.set_int,
"set_eval": gei._inspector.set_eval,
"fps": gei.toggle_fps,
}
# Ctrl + key mappings
key_calls = {
"d": gei.stop_event_loop,
"m": self.console_mode,
}
# Call parent class's init function passing in the
# function and key mapping dictionaries
Console.__init__(self, gei.screen, pos,
functions=function_list, key_calls=key_calls,
vars={}, syntax={})
def console_mode(self):
"""
Switches console between console and python interpreter
"""
# Deactivate Console if showing
if self.active:
self.set_active()
self.setvar("python_mode",
not self.getvar("python_mode"))
self.set_interpreter()
self.set_active()
|