Exemple #1
0
class MapParserTest(unittest.TestCase):
    def setUp(self):
        from byond.map import Map, Tile
        self.dmm = Map()
    
    def test_basic_SplitAtoms_operation(self):
        testStr = '/obj/effect/landmark{name = "carpspawn"},/obj/structure/lattice,/turf/space,/area'
        expectedOutput = ['/obj/effect/landmark{name = "carpspawn"}', '/obj/structure/lattice', '/turf/space', '/area']
        
        out = self.dmm.SplitAtoms(testStr)
        self.assertListEqual(out, expectedOutput)
    
    def test_basic_SplitProperties_operation(self):
        testStr = 'd1 = 1; d2 = 2; icon_state = "1-2"; tag = ""'
        expectedOutput = ['d1 = 1', ' d2 = 2', ' icon_state = "1-2"', ' tag = ""']
        
        out = self.dmm.SplitProperties(testStr)
        self.assertListEqual(out, expectedOutput)
    
    def test_basic_consumeTile_operation(self):
        from byond.map import Map, Tile
        '''
        "aaK" = (
            /obj/structure/cable{
                d1 = 1;
                d2 = 2; 
                icon_state = "1-2";
                tag = ""
            },
            /obj/machinery/atmospherics/pipe/simple/supply/hidden{
                dir = 4
            },
            /turf/simulated/floor{
                icon_state = "floorgrime"
            },
            /area/security/prison
        )
        '''
        testStr = '"aaK" = (/obj/structure/cable{d1 = 1; d2 = 2; icon_state = "1-2"; tag = ""},/obj/machinery/atmospherics/pipe/simple/supply/hidden{dir = 4},/turf/simulated/floor{icon_state = "floorgrime"},/area/security/prison)'
        out = self.dmm.consumeTile(testStr, 0)
        print('IIDs: {0}'.format(repr(out.instances)))

        self.assertEquals(out.origID, 'aaK', 'origID')
        self.assertEquals(len(out.instances), 4, 'instances size')
        self.assertEquals(len(out.GetAtom(0).properties), 4, 'instances[0] properties')
        self.assertIn('d1', out.GetAtom(0).properties, 'd1 not present in properties')
        self.assertListEqual(out.GetAtom(0).mapSpecified,['d1','d2','icon_state','tag'])
        
        self.assertEquals(len(out.GetAtom(2).properties), 1, 'Failure to parse /turf/simulated/floor{icon_state = "floorgrime"}')
        self.assertIn('icon_state', out.GetAtom(2).properties, 'Failure to parse /turf/simulated/floor{icon_state = "floorgrime"}')
        
        self.assertEqual(out.MapSerialize(Tile.FLAG_USE_OLD_ID), testStr)
        
    def test_consumeTile_landmark(self):
        from byond.map import Map, Tile
        testStr='"aah" = (/obj/effect/landmark{name = "carpspawn"},/obj/structure/lattice,/turf/space,/area)'
        out = self.dmm.consumeTile(testStr, 0)
        self.assertEqual(out.MapSerialize(Tile.FLAG_USE_OLD_ID), testStr)
Exemple #2
0
 def setUp(self):
     from byond.map import Map, Tile
     self.dmm = Map()
    # filemode='w'
    )
opt = argparse.ArgumentParser()
opt.add_argument('project', metavar="project.dme")
opt.add_argument('map', metavar="map.dmm")
opt.add_argument('--render-stars', dest='render_stars', default=False, action='store_true', help="Render space.  Normally off to prevent ballooning the image size.")
opt.add_argument('--render-areas', dest='render_areas', default=False, action='store_true', help="Render area overlays.")
opt.add_argument('--render-only', dest='render_types', action='append', help="Render ONLY these types.  Can be used multiple times to specify more types.")
opt.add_argument('--area', dest='area', type=list, nargs='*', default=None, help="Specify an area to restrict rendering to.")
opt.add_argument('-O', '--out', dest='outfile', type=str, default=None, help="What to name the file ({z} will be replaced with z-level)")
opt.add_argument('--area-list', dest='areas', type=str, default=None, help="A file with area_file.png = /area/path on each line")
args = opt.parse_args()
if os.path.isfile(args.project):
    tree = ObjectTree()
    tree.ProcessFilesFromDME(args.project)
    dmm = Map(tree)
    dmm.readMap(args.map)
    renderflags = 0
    if args.render_stars:
        renderflags |= MapRenderFlags.RENDER_STARS
    if args.render_areas:
        renderflags |= MapRenderFlags.RENDER_AREAS
    kwargs = {}
    if args.areas:
        with open(args.areas) as f:
            for line in f:
                if line.startswith("#"):
                    continue
                if '=' not in line:
                    continue
                outfile, area = line.split('=')
Exemple #4
0
            if subject == "type" or subject == "type!":
                force = subject == "type!"
                old, new = action.split(">")
                newtype = new.strip()
                if tree.GetAtom(newtype) is None:
                    print("{0}:{1}: {2}".format(sys.argv[2], ln, line.strip("\r\n")))
                    print('  ERROR: Unable to find replacement type "{0}".'.format(newtype))
                    errors += 1
                actions += [mapfixes.base.ChangeType(old.strip(), newtype, force)]
        if errors > 0:
            print("!!! {0} errors, please fix them.".format(errors))
            sys.exit(1)
print("Changes to make:")
for action in actions:
    print(" * " + str(action))
dmm = Map(tree, forgiving_atom_lookups=1)
dmm.readMap(args.map)
dmm.writeMap2(args.map.replace(".dmm", ".dmm2"))
for iid in xrange(len(dmm.instances)):
    atom = dmm.getInstance(iid)
    changes = []
    for action in actions:
        action.SetTree(tree)
        if action.Matches(atom):
            atom = action.Fix(atom)
            changes += [str(action)]
    atom.id = iid

    """
    compiled_atom = tree.GetAtom(atom.path)
    if compiled_atom is not None:
    '-O',
    '--out',
    dest='outfile',
    type=str,
    default=None,
    help="What to name the file ({z} will be replaced with z-level)")
opt.add_argument('--area-list',
                 dest='areas',
                 type=str,
                 default=None,
                 help="A file with area_file.png = /area/path on each line")
args = opt.parse_args()
if os.path.isfile(args.project):
    tree = ObjectTree()
    tree.ProcessFilesFromDME(args.project)
    dmm = Map(tree)
    dmm.Load(args.map)
    renderflags = 0
    if args.render_stars:
        renderflags |= MapRenderFlags.RENDER_STARS
    if args.render_areas:
        renderflags |= MapRenderFlags.RENDER_AREAS
    kwargs = {}
    if args.areas:
        with open(args.areas) as f:
            for line in f:
                if line.startswith("#"):
                    continue
                if '=' not in line:
                    continue
                outfile, area = line.split('=')
Exemple #6
0
                if tree.GetAtom(newtype) is None:
                    print('{0}:{1}: {2}'.format(sys.argv[2], ln,
                                                line.strip('\r\n')))
                    print('  ERROR: Unable to find replacement type "{0}".'.
                          format(newtype))
                    errors += 1
                actions += [
                    mapfixes.base.ChangeType(old.strip(), newtype, force)
                ]
        if errors > 0:
            print('!!! {0} errors, please fix them.'.format(errors))
            sys.exit(1)
print('Changes to make:')
for action in actions:
    print(' * ' + str(action))
dmm = Map(tree, forgiving_atom_lookups=1)
dmm.readMap(args.map)
dmm.writeMap2(args.map.replace('.dmm', '.dmm2'))
for iid in xrange(len(dmm.instances)):
    atom = dmm.getInstance(iid)
    changes = []
    for action in actions:
        action.SetTree(tree)
        if action.Matches(atom):
            atom = action.Fix(atom)
            changes += [str(action)]
    atom.id = iid
    '''
    compiled_atom = tree.GetAtom(atom.path)
    if compiled_atom is not None:
        for propname in list(atom.properties.keys()):
Exemple #7
0
    '-O',
    '--out',
    dest='outfile',
    type=str,
    default=None,
    help="What to name the file ({z} will be replaced with z-level)")
opt.add_argument('--area-list',
                 dest='areas',
                 type=str,
                 default=None,
                 help="A file with area_file.png = /area/path on each line")
args = opt.parse_args()
if os.path.isfile(args.project):
    tree = ObjectTree()
    tree.ProcessFilesFromDME(args.project)
    dmm = Map(tree)
    dmm.readMap(args.map)
    renderflags = 0
    if args.render_stars:
        renderflags |= MapRenderFlags.RENDER_STARS
    if args.render_areas:
        renderflags |= MapRenderFlags.RENDER_AREAS
    kwargs = {}
    if args.areas:
        with open(args.areas) as f:
            for line in f:
                if line.startswith("#"):
                    continue
                if '=' not in line:
                    continue
                outfile, area = line.split('=')
Exemple #8
0
                    errors += 1
                elif tree.GetAtom(newtype) is None:
                    logging.error(
                        '{0}:{1}: ERROR: Unable to find replacement type "{2}".'
                        .format(fixscript, ln, newtype))
                    errors += 1
                else:
                    actions += [
                        mapfixes.base.ChangeType(old.strip(), newtype, force)
                    ]
        if errors > 0:
            logging.critical(
                'Found {0} errors, please fix them.'.format(errors))
            sys.exit(1)

dmm = Map(tree, forgiving_atom_lookups=1)
dmm.Load(args.map)
#dmm.Load(args.map.replace('.dmm', '.dmm2'))
logging.info('Changes to make:')
for action in actions:
    logging.info(' * ' + str(action))
logging.info('Iterating tiles...')
hashMap = {
}  # hash => null to remove, hash => True to not remove, hash => Tile to replace with this.
it = dmm.Tiles()
thousandsActivity = 0
for tile in it:
    if tile is None: continue
    for atom in tile.GetAtoms():
        ': :type atom Atom:'
        changes = []
Exemple #9
0
 def setUp(self):
     from byond.map.format.dmm import DMMFormat
     from byond.map import Map
     self.map = Map()
     self.dmm = DMMFormat(self.map)