class TestBrick_SimpleDoor(unittest.TestCase): selector = selector_regular.SelectorRegular() def test_generate(self): """generate one simple door with no parameter""" stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) selector = selector_regular.SelectorRegular() custom_brick = brick.Brick(def_0, selector) custom_brick.structure_personalization() custom_brick.dressing_instantiation() custom_brick.dressing_personalization() concrete = concrete_room.ConcreteRoom() custom_brick.finalize(concrete) # check that it contains an object with expected parent objects = concrete.get_objects() self.assertEquals(len(objects), 1) object = objects[0] self.assertEquals(object.parent, None) # check there is a portal to an outer world (sounds nice, he ?) phys_faces = object.get_physical_faces() portal_faces = [ faces for faces in phys_faces if object.PHYS_TYPE_PORTAL == faces["physics"]["type"] ] self.assertEquals(len(portal_faces), 1) portal_face = portal_faces[0] self.assertEquals(portal_face["physics"], {'type': 'portal', 'connect': 'A', 'gate' : 'gate0'})
def test_get_list_bricks_regular(self): """ test retrieving list of bricks""" _s = selector_regular.SelectorRegular() print(room_register.brickTypes) self.assertIsNotNone(room_register.brickTypes) self.assertTrue("rectangular" in room_register.brickTypes)
def generate(self): selector = selector_regular.SelectorRegular() custom_brick = brick.Brick(def_0, selector) custom_brick.structure_personalization() custom_brick.dressing_instantiation() custom_brick.dressing_personalization() concrete = concrete_room.ConcreteRoom() custom_brick.finalize(concrete) return concrete
def test_get_list_room(self): """ test retrieving list of rooms""" _s = selector_regular.SelectorRegular() _r = room.Room("/tmp", "name", _s) #_s.get_from_name(name, _r) print(register.brickTypes) self.assertIsNotNone(register.brickTypes) self.assertTrue("rectangular" in register.brickTypes)
def check_level(directory, filename): """ Get level, check it loads and return it""" if directory == '': print("Error, expected directory. See --help for info.") sys.exit(1) if not filename in os.listdir(directory): print("Error, expected directory with ", filename, "file. See --help for info.") sys.exit(1) return level.Level(directory + "/" + filename, selector_regular.SelectorRegular())
def test_generate_0_pad(self): """generate one rectangular with no pad""" stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) selector = selector_regular.SelectorRegular() custom_brick = brick.Brick(brick_0_pad, selector) custom_brick.structure = sphere.BrickSphere().get_instance( custom_brick) custom_brick.dressing = basic.DressingBasic().get_instance( custom_brick) custom_brick.structure_personalization() custom_brick.dressing_instantiation() custom_brick.dressing_personalization() concrete = concrete_room.ConcreteRoom() custom_brick.finalize(concrete) self.assertEqual(len(concrete.objects), 1)
def test_generate_0_pad_values(self): """generate one rectangular with no pad""" stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) selector = selector_regular.SelectorRegular() custom_brick = brick.Brick(brick_1_pad_values, selector) custom_brick.structure = rectangular.BrickRectangular().get_instance(custom_brick) custom_brick.dressing = basic.DressingBasic().get_instance(custom_brick) custom_brick.structure_personalization() logger.info(custom_brick.values.parameters) self.assertEqual(custom_brick.values.parameters.structure_private , {'size': [1.0, 2.0, 3.0]}) custom_brick.dressing_instantiation() custom_brick.dressing_personalization() concrete = concrete_room.ConcreteRoom() custom_brick.finalize(concrete) self.assertEqual(len(concrete.objects) , 1)
def main(argv): preview = False force = False only_preview = False start_step = None end_step = None output_dir = None try: opts, args = getopt.getopt(argv, "ho:fs:e:r:pPv") except getopt.GetoptError: my_help() for opt, arg in opts: if opt == '-h': my_help() elif opt in ("-o"): output_dir = arg print("Option: Output set to: %s" % output_dir) elif opt in ("-r"): room = arg elif opt in ("-s"): start_step = arg elif opt in ("-e"): end_step = arg elif opt in ("-f"): force = True print("Option: Force generation.") elif opt in ("-p"): preview = True print("Option: Preview") elif opt in ("-P"): print("Option: Only preview") only_preview = True elif opt in ("-v"): logger.getLogger().setLevel(logging.DEBUG) logger.debug("Set verbose to debug") if len(args) != 1: print("Error, expected level directory. See --help for info.") sys.exit(1) directory = args[0] if output_dir is None: output_dir = directory selector = selector_regular.SelectorRegular() my_level = level.Level(selector) try: states = my_level.read_state_list(directory) except Exception as e: print("Invalid directory or unreadable level state. ERROR=%s" % str(e)) sys.exit(1) print("Level has states: %s" % states) if start_step is None: start_step = max(states.current) if end_step is None: end_step = state.LevelState.Finalize print("Need to open at step:%s and generate up to:%s" % (start_step, end_step)) try: my_level.load(directory, start_step) except Exception as e: print("Unable to load level at this step. ERROR=%s" % str(e)) sys.exit(1) for step in state.LevelState: if step > start_step and step <= end_step: print("Apply step: %s" % step.name) if states.has_state(step) and not force: print( "Step is already generated, and force is not set. Will exit." ) sys.exit(1) if not only_preview: my_level.run_step(step) my_level.save(output_dir) if step == state.LevelState.Finalize: my_level.finalize(output_dir, preview) if preview or only_preview: my_level.preview(output_dir)