Mercurial > nagslang
diff tools/area_editor.py @ 255:d4928d4a661a
Object editing
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 05 Sep 2013 00:05:03 +0200 |
parents | 611370331bd1 |
children | 521f73061872 |
line wrap: on
line diff
--- a/tools/area_editor.py Thu Sep 05 00:04:25 2013 +0200 +++ b/tools/area_editor.py Thu Sep 05 00:05:03 2013 +0200 @@ -32,6 +32,7 @@ from nagslang.options import parse_args from nagslang.constants import SCREEN from nagslang.level import Level, POLY_COLORS, LINE_COLOR +from nagslang.yamlish import load_s import nagslang.enemies as ne import nagslang.game_object as ngo import nagslang.puzzle as np @@ -245,6 +246,7 @@ def __init__(self, classname, cls, data): super(EditClassDialog, self).__init__() + self.classname = classname self.rect = pygame.rect.Rect(0, 0, 800, 550) title = Label("Editing %s" % classname) title.rect = pygame.rect.Rect(100, 10, 600, 25) @@ -263,11 +265,15 @@ if data is not None: if requirement in data: field.set_text('%s' % data[requirement]) - elif 'args' in data: + elif 'args' in data and requirement != 'name': # NB: The ordering assumptions in requires should make # this safe, but it's really, really, really fragile - field.set_text('%s' % data['args'][index]) - index += 1 + try: + field.set_text('%s' % data['args'][index]) + index += 1 + except IndexError: + # Assumed to be arguments with the default value + pass self.fields[requirement] = field hintlabel = Label(hint) hintlabel.rect = pygame.rect.Rect(640, y, 100, 25) @@ -282,7 +288,23 @@ self.add(row) def get_data(self): - return '' + result = {} + result['classname'] = self.classname + args = [] + # We arrange to bounce this through yaml'ish to convert + # stuff to the expected type + for val in self.fields: + text = self.fields[val].get_text() + if not text: + # skip empty fields + continue + if val == 'name': + result['name'] = text + else: + args.append(' - ' + text) + data = "args:\n" + '\n'.join(args) + result['args'] = load_s(data)['args'] + return result class LevelWidget(Widget):