Changeset 255:d4928d4a661a


Ignore:
Timestamp:
Sep 4, 2013, 10:05:03 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
rebase_source:
651740e465cf101420ba45555294a4010e5b2456
Message:

Object editing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/area_editor.py

    r251 r255  
    3333from nagslang.constants import SCREEN
    3434from nagslang.level import Level, POLY_COLORS, LINE_COLOR
     35from nagslang.yamlish import load_s
    3536import nagslang.enemies as ne
    3637import nagslang.game_object as ngo
     
    246247    def __init__(self, classname, cls, data):
    247248        super(EditClassDialog, self).__init__()
     249        self.classname = classname
    248250        self.rect = pygame.rect.Rect(0, 0, 800, 550)
    249251        title = Label("Editing %s" % classname)
     
    264266                if requirement in data:
    265267                    field.set_text('%s' % data[requirement])
    266                 elif 'args' in data:
     268                elif 'args' in data and requirement != 'name':
    267269                    # NB: The ordering assumptions in requires should make
    268270                    # this safe, but it's really, really, really fragile
    269                     field.set_text('%s' % data['args'][index])
    270                     index += 1
     271                    try:
     272                        field.set_text('%s' % data['args'][index])
     273                        index += 1
     274                    except IndexError:
     275                        # Assumed to be arguments with the default value
     276                        pass
    271277            self.fields[requirement] = field
    272278            hintlabel = Label(hint)
     
    283289
    284290    def get_data(self):
    285         return ''
     291        result = {}
     292        result['classname'] = self.classname
     293        args = []
     294        # We arrange to bounce this through yaml'ish to convert
     295        # stuff to the expected type
     296        for val in self.fields:
     297            text = self.fields[val].get_text()
     298            if not text:
     299                # skip empty fields
     300                continue
     301            if val == 'name':
     302                result['name'] = text
     303            else:
     304                args.append(' - ' + text)
     305        data = "args:\n" + '\n'.join(args)
     306        result['args'] = load_s(data)['args']
     307        return result
    286308
    287309
Note: See TracChangeset for help on using the changeset viewer.