def Fix(self, atom): print('MIN: {}'.format(PIPING_LAYER_MIN)) print('MAX: {}'.format(PIPING_LAYER_MAX)) self.layer = int(atom.getProperty('piping_layer')) print('LAYER: {}'.format(self.layer)) if self.layer < PIPING_LAYER_MIN: self.layer = PIPING_LAYER_MIN atom.setProperty('piping_layer', PIPING_LAYER_MIN, PropertyFlags.MAP_SPECIFIED) if self.layer > PIPING_LAYER_MAX: self.layer = PIPING_LAYER_MAX atom.setProperty('piping_layer', PIPING_LAYER_MAX, PropertyFlags.MAP_SPECIFIED) self.pixel_x = (self.layer - PIPING_LAYER_DEFAULT) * PIPING_LAYER_P_X self.pixel_y = (self.layer - PIPING_LAYER_DEFAULT) * PIPING_LAYER_P_Y atom.properties['pixel_x'] = BYONDValue(self.pixel_x) atom.setProperty('pixel_x', self.pixel_x, PropertyFlags.MAP_SPECIFIED) atom.properties['pixel_y'] = BYONDValue(self.pixel_y) atom.setProperty('pixel_y', self.pixel_y, PropertyFlags.MAP_SPECIFIED) return atom
def consumeDataValue(self, value, lineNumber): data = None if value[0] in ('"', "'"): quote = value[0] if quote == '"': data = BYONDString(value[1:-1], self.filename, lineNumber) elif quote == "'": data = BYONDFileRef(value[1:-1], self.filename, lineNumber) else: data = BYONDValue(value, self.filename, lineNumber) return data
def test_serialization(self): from byond.basetypes import Atom, BYONDString, BYONDValue atom = Atom('/datum/test', __file__, 0) # Assign properties. Order is important (orderedDict!) atom.properties['dir'] = BYONDValue(2) atom.properties['name'] = BYONDString('test datum') # What we expect after running str(). atom_serialized = '/datum/test{dir=2;name="test datum"}' # Check it self.assertEqual(str(atom), atom_serialized)
def test_copy_consistency(self): from byond.basetypes import Atom, BYONDString, BYONDValue atom = Atom('/datum/test',__file__,0) atom.properties={ 'dir': BYONDValue(2), 'name': BYONDString('test datum') } atom.mapSpecified=['dir','name'] atom2=atom.copy() atom_serialized=atom.MapSerialize() atom2_serialized=atom2.MapSerialize() self.assertEqual(atom_serialized, atom2_serialized)
def Fix(self, atom): self.changesMade = [] propChanges = self.ICON_STATE_CHANGES[self.stateKey] if 'tag' in atom.mapSpecified: atom.mapSpecified.remove('tag') for key, newval in propChanges.items(): if key not in atom.mapSpecified: atom.mapSpecified += [key] oldval = 'NONE' if key in atom.properties: oldval = str(atom.properties[key]) if isinstance(newval, str): atom.properties[key] = BYONDString(newval) elif isinstance(newval, int): atom.properties[key] = BYONDValue(newval) self.changesMade += ['{0}: {1} -> {2}'.format(key, oldval, atom.properties[key])] return atom
def Fix(self, atom): fix = atom.properties['network'].value atom.properties['network'] = BYONDValue('list("{0}")'.format(fix)) return atom
def makeNumber(self, s, l, toks, from_list=False): # print('makeNumber(%r)' % toks[0]) return [BYONDValue(float(toks[0]))]