class MapParserTest(unittest.TestCase): def setUp(self): 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): """ "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): 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)
class MapRenderingTest(unittest.TestCase): def setUp(self): self.dmm = Map() def test_basic_bbox(self): correct_bbox=( 3584,4382, 3616,4414 ) # 1126, 440 # 1126, 470 #3584, 4288 tile_x,tile_y=(112,134) pixel_x=0 pixel_y=-30 icon_height=32 icon_width=32 bbox = self.dmm.tilePosToBBox(tile_x, tile_y, pixel_x,pixel_y, icon_height,icon_width) self.assertTupleEqual(correct_bbox, bbox)
subject, action = line.split(':') subject = type.lower() if subject == 'property': old, new = action.split('>') actions += [RenameProperty(old.strip(), new.strip())] if subject == 'type': old, new = action.split('>') actions += [ChangeType(old.strip(), new.strip())] print('Changes to make:') for action in actions: print(' * ' + str(action)) tree = ObjectTree() tree.ProcessFilesFromDME('baystation12.dme') dmm = Map(tree) dmm.readMap(sys.argv[1]) dmm.writeMap2(sys.argv[1].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 dmm.setInstance(iid,atom) if len(changes) > 0: print('{0} (#{1}):'.format(atom.path,atom.id)) for change in changes:
dmm.generateImage(outfile, os.path.dirname(args.project), renderflags, **kwargs) 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('--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('=')
] def MakePage(**kwargs): rewt = '.' depth = kwargs.get('depth', 0) if depth > 0: rewt = '/'.join(['..'] * depth) title = kwargs.get('title', 'LOL NO TITLE') body = kwargs.get('body', '') return (tmpl_head + body + tmpl_footer).replace('{TITLE}', title).replace('{ROOT}', rewt) if os.path.isfile(sys.argv[1]): selectedDMEs = [] tree = ObjectTree() tree.ProcessFilesFromDME(sys.argv[1]) dmm = Map(tree) dmm.readMap(sys.argv[2]) basedir = os.path.join(os.path.dirname(sys.argv[1]), 'analysis', os.path.basename(sys.argv[2])) if not os.path.isdir(basedir): os.makedirs(os.path.join(basedir,'instances')) os.makedirs(os.path.join(basedir,'tiles')) # Dump instances instance_info = {} for atom in dmm.instances: if atom.path not in instance_info: instance_info[atom.path] = [] instance_info[atom.path] += [atom.id]
def setUp(self): self.dmm = Map()