def test_1_create_region(self): create_region(self.map_name, self.region_name) m = Bits().maps[self.map_name] regions = m.get_regions() self.assertIn(self.region_name, regions) region = regions[self.region_name] self.assertIsNotNone(region.get_data().id)
def rename_region(map_name, old_region_name, new_region_name): bits = Bits() assert map_name in bits.maps, map_name m = bits.maps[map_name] regions = m.get_regions() assert old_region_name in regions, old_region_name assert new_region_name not in regions, new_region_name region = regions[old_region_name] src_path = region.gas_dir.path dst_path = os.path.join(os.path.dirname(src_path), new_region_name) print('src: ' + src_path) print('dst: ' + dst_path) os.rename(src_path, dst_path) m.gas_dir.clear_cache() regions = m.get_regions() for region_name, r in regions.items(): stitch_helper_file = r.gas_dir.get_subdir('editor').get_gas_file( 'stitch_helper') stitch_helper_data = stitch_helper_file.get_gas().get_section( 'stitch_helper_data') if region_name == new_region_name: print(region_name + ' - the new region!') stitch_helper_data.set_attr_value('source_region_name', new_region_name) else: print(region_name) for section in stitch_helper_data.get_sections(): t, n = section.get_t_n_header() assert t == 'stitch_editor', t if n == old_region_name: section.set_t_n_header(t, new_region_name) section.set_attr_value('dest_region', new_region_name) stitch_helper_file.save()
def test_init_new(self): bits = Bits() map_dir_path = os.path.join(bits.gas_dir.path, 'world', 'maps', 'gaspy-unit-test-map') self.assertFalse(os.path.exists(map_dir_path)) m = Map(GasDir(map_dir_path), bits) self.assertIsInstance(m, Map)
def create_region(map_name, region_name, size='4x4', terrain_type='floor', plants=False): bits = Bits() m = bits.maps[map_name] region: Region = m.create_region(region_name, None) size_x, size_z = [int(s) for s in size.split('x')] if terrain_type == 'floor': flat_terrain_2d = MapgenTerrainFloor(size_x, size_z) elif terrain_type == 'dunes': flat_terrain_2d = MapgenTerrainDunes(size_x, size_z) else: assert False, 'unknown terrain type' terrain = flat_terrain_2d.make_terrain() region.terrain = terrain if plants: assert isinstance(plants, str) create_plants(flat_terrain_2d, plants) region.generated_objects_non_interactive = flat_terrain_2d.make_non_interactive_objects( ) region.lights = [] region.lights.append( # daylight from south DirectionalLight( color=Color(0xffffffcc), draw_shadow=True, intensity=1, occlude_geometry=True, on_timer=True, direction=DirectionalLight.direction_from_orbit_and_azimuth( 180, 45))) region.lights.append( # blue counter-light from north DirectionalLight( color=Color(0xffccccff), draw_shadow=False, intensity=0.7, occlude_geometry=False, on_timer=False, direction=DirectionalLight.direction_from_orbit_and_azimuth(0, 45))) region.save() # start positions group if len(m.get_regions()) == 1 and m.start_positions is None: # 1st region, let's add a start pos map_center_x = flat_terrain_2d.size_x / 2 map_center_z = flat_terrain_2d.size_z / 2 position = flat_terrain_2d.map_pos_to_node_pos(map_center_x, map_center_z) m.start_positions = StartPositions( { 'default': StartGroup( 'This is the default group.', False, 0, '', [StartPos(1, position, Camera(0.5, 20, 0, position))]) }, 'default') m.save()
def untranslate(lang_file_name): bits = Bits() lang_dir = bits.gas_dir.get_subdir('language') if lang_file_name: untranslate_file(lang_dir, lang_file_name) else: for lang_file_name in lang_dir.get_gas_files(): untranslate_file(lang_dir, lang_file_name) print('untranslated!')
def test_koe(self): bits = Bits() map_dir = bits.gas_dir.get_subdir('world').get_subdir( 'maps').get_subdir('map_world') m = Map(map_dir, bits) self.assertIsInstance(m, Map) self.assertEqual(map_dir, m.gas_dir) self.assertEqual('"Kingdom of Ehb"', m.get_data().screen_name) self.assertEqual(81, len(m.get_regions()))
def check_dupe_node_ids(map_name: str): bits = Bits() m = bits.maps[map_name] # check for dupes within map itself check_map(m) # check for dupes with other maps for m2 in bits.maps.values(): if m2 == m: continue check_map_vs_map(m, m2) print('All good.')
def test_save_and_delete(self): bits = Bits() map_dir_path = os.path.join(bits.gas_dir.path, 'world', 'maps', 'gaspy-unit-test-map') self.assertFalse(os.path.exists(map_dir_path)) m = Map( GasDir(map_dir_path), bits, Map.Data(name='gaspy-unit-test-map', screen_name='GasPy UnitTest Map!')) m.save() self.assertTrue(os.path.exists(map_dir_path)) self.assertTrue(os.path.exists(os.path.join(map_dir_path, 'main.gas'))) m.delete() self.assertFalse(os.path.exists(map_dir_path))
def create_map(name, screen_name): bits = Bits() assert name not in bits.maps m = bits.maps[name] = Map( GasDir(os.path.join(bits.gas_dir.path, 'world', 'maps', name)), bits) data = Map.Data(name, screen_name) data.dev_only = False data.timeofday = '0h0m' data.use_node_mesh_index = True data.use_player_journal = False data.camera.azimuth = 70.0 data.camera.distance = 13.0 data.camera.position = '0,0,0,0x0' m.data = data m.save()
def main(argv): args = parse_args(argv) GasParser.get_instance().print_warnings = False bits = Bits(args.bits) which = args.which if which == 'level-enemies': write_level_enemies_csv(bits) elif which == 'enemy-occurrence': print_enemy_occurrence(bits) elif which == 'map-levels': map_name = args.map_name assert map_name assert map_name in bits.maps write_map_levels_csv(bits.maps[map_name]) return 0
def plant_gen(map_name: str, region_name: str, plants_profile_name: str, nodes: list[str], exclude_nodes: list[str], override: bool): bits = Bits() _map = bits.maps[map_name] region = _map.get_region(region_name) region.print(info=None) region.load_data() region.load_terrain() region.terrain.print() nodes = [NodeMask.parse(nm_def) for nm_def in nodes] exclude_nodes = [NodeMask.parse(nm_def) for nm_def in exclude_nodes] plants_profile = load_plantgen_profile(plants_profile_name) plants = generate_plants(region.terrain, plants_profile, nodes, exclude_nodes) print(f'{len(plants)} plants generated') region.terrain = None # don't try to re-save the loaded terrain if override: region.load_objects() num_objs_before = len(region.objects_non_interactive) region.objects_non_interactive = [ go for go in region.objects_non_interactive if go.get_own_value( 'common', 'dev_instance_text') != '"gaspy plant_gen"' ] print( f'override: removing {num_objs_before - len(region.objects_non_interactive)} of {num_objs_before} plants/nios, {len(region.objects_non_interactive)} remaining' ) region.save() region.objects_non_interactive = None region.objects_loaded = False region.generated_objects_non_interactive = [ GameObjectData(plant.template_name, placement=Placement(position=plant.position, orientation=Quaternion.rad_to_quat( plant.orientation)), aspect=Aspect(scale_multiplier=plant.size), common=Common(dev_instance_text='"gaspy plant_gen"')) for plant in plants ] region.save() print('Done!') print('Open in SE and snap to ground.')
def convert_to_node_mesh_index(map_name, region_name): bits = Bits() m = bits.maps[map_name] nmg = NodeMeshGuids(bits) if region_name is not None: print(region_name) region = m.get_region(region_name) convert_region(region, nmg) else: print(map_name) convert_map(m) for r_name, region in m.get_regions().items(): print(r_name) convert_region(region, nmg) print('Done.') print( 'You have to open the converted region(s) in Siege Editor to complete the process.' )
def create_region(map_name, region_name, node='t_xxx_flr_04x04-v0'): bits = Bits() m = bits.maps[map_name] region: Region = m.create_region(region_name, None) region.terrain = Terrain(TerrainNode(None, node)) region.save() # start positions group if len(m.get_regions()) == 1 and m.start_positions is None: # 1st region, let's add a start pos position = Position(0, 0, 0, region.terrain.target_node.guid) m.start_positions = StartPositions( { 'default': StartGroup( 'This is the default group.', False, 0, '', [StartPos(1, position, Camera(0.5, 20, 0, position))]) }, 'default') m.save()
def mapgen(map_name, region_name, size_x, size_z, args: Args, rt_base: RegionTilingArg, print_world=False): print( f'mapgen heightmap {map_name}.{region_name} {size_x}x{size_z} ({args})' ) # check inputs assert size_x % 4 == 0 assert size_z % 4 == 0 if size_x * size_z > 256 * 256: # above a certain number of nodes, making terrain takes quite long # and actually loading it in SE takes forever (initial region recalc), maybe combinatorial issue in lighting calculation? print( f'warning: that\'s {int((size_x/4) * (size_z/4))} tiles in a region, I hope you are culling' ) if args.seed is None: args.seed = random.randint(1, 10**5) print(f'perlin seed: {args.seed}') if print_world: print_world_plots(size_x, size_z, args, rt_base) # check map exists bits = Bits() assert map_name in bits.maps, f'Map {map_name} does not exist' _map = bits.maps[map_name] start_pos_arg = args.start_pos for rtx in range(rt_base.gen_x_from, rt_base.gen_x_to): for rtz in range(rt_base.gen_z_from, rt_base.gen_z_to): args.start_pos = None if rtx == int(rt_base.num_x / 2) and rtz == int(rt_base.num_z / 2): args.start_pos = start_pos_arg # put start-pos in middle region rt = RegionTiling(rt_base.num_x, rt_base.num_z, rtx, rtz, region_name) generate_region(_map, rt.cur_region_name(), size_x, size_z, args, rt)
def edit_region_ids(map_name, region_name, mesh_range=None, scid_range=None, guid=None): bits = Bits() assert map_name in bits.maps, map_name _map = bits.maps[map_name] regions = _map.get_regions() assert region_name in regions, region_name region = regions[region_name] if mesh_range is not None: edit_region_mesh_range(region, Hex.parse(mesh_range)) region.gas_dir.clear_cache() region.load_data() if scid_range is not None: edit_region_scid_range(region, Hex.parse(scid_range)) region.gas_dir.clear_cache() region.load_data() if guid is not None: edit_region_guid(region, Hex.parse(guid))
def add_world_levels(map_name, bits_dir=None): bits = Bits(bits_dir) _map = bits.maps[map_name] add_map_world_levels(_map)
def edit_lights(map_name, region_name): bits = Bits() m = bits.maps[map_name] region = m.get_region(region_name) edit_region_lights(region)
def delete_region(map_name, region_name): bits = Bits() m: Map = bits.maps[map_name] m.delete_region(region_name)
def delete_map(name): bits = Bits() m = bits.maps[name] m.delete()
def main(argv): bits_arg = argv[0] if len(argv) > 0 else None bits = Bits(bits_arg) print_enemies(bits)
def test_4_delete_map(self): m: Map = Bits().maps[self.map_name] map_dir_path = m.gas_dir.path delete_map(self.map_name) self.assertFalse(os.path.exists(map_dir_path))
def test_3_delete_region(self): region: Region = Bits().maps[self.map_name].get_region(self.region_name) region_dir_path = region.gas_dir.path delete_region(self.map_name, self.region_name) self.assertFalse(os.path.exists(region_dir_path))
def test_1_create_map(self): create_map(self.map_name, 'GasPy UnitTest Map!') m = Bits().maps[self.map_name] self.assertTrue(os.path.exists(m.gas_dir.path)) self.assertTrue(os.path.exists(os.path.join(m.gas_dir.path, 'main.gas')))
def main(argv): args = parse_args(argv) bits = Bits(args.bits) import_region(bits, args.region, args.from_map, args.to_map) return 0