-
Notifications
You must be signed in to change notification settings - Fork 5
/
commands.py
56 lines (52 loc) · 2.18 KB
/
commands.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
53
54
55
56
import logging
from functools import partial
from communication import send_command
from controllers import set_current_controller
def view_from(direction):
logging.debug('viewing from %s' % direction)
send_command('view_%s' % direction)
# mapping of mode to mode changing command (falsy: keep current)
_mode_mapping = {
'sculpt': 'sculpt',
'pottery': 'sculpt',
'paint': 'texture_paint',
'object': 'object',
}
def enter_mode(mode):
logging.debug('entering mode: %s' % mode)
if mode not in _mode_mapping:
logging.error('unrecognized mode %s' % mode)
mode_command = _mode_mapping[mode]
if mode_command:
send_command('mode_%s' % mode_command)
set_current_controller(mode)
# mapping of command word to callable
_cmd_mapping = {
'above': partial(view_from, 'top'),
'add': partial(send_command, 'sculpt_add'),
'back': partial(view_from, 'back'),
'below': partial(view_from, 'bottom'),
'camera': partial(view_from, 'camera'),
'center': partial(send_command, 'object_center'),
'front': partial(view_from, 'front'),
'left': partial(view_from, 'left'),
'noob': partial(send_command, 'toggle_noob'),
'object': partial(enter_mode, 'object'),
'over': partial(view_from, 'top'),
'paint': partial(enter_mode, 'paint'),
'pottery': partial(enter_mode, 'pottery'),
'render': partial(send_command, 'render'),
'reset': partial(send_command, 'object_reset_everything'),
'right': partial(view_from, 'right'),
'sculpt': partial(enter_mode, 'sculpt'),
'substract': partial(send_command, 'sculpt_subtract'),
'under': partial(view_from, 'bottom'),
}
def interpret_command(cmd):
if cmd not in _cmd_mapping:
logging.debug('unrecognized command %s' % cmd)
return False
retval = _cmd_mapping[cmd]()
if retval is not None:
return retval
return True