Example #1
0
 def load_templates(self, gas_dir: GasDir):
     if self.templates is None:
         self.templates = {}
     for gas_file in gas_dir.get_gas_files().values():
         sections = gas_file.get_gas().items
         for section in sections:
             self.load_templates_rec(section)  # recurse into sub-sections
     # recurse into subdirs
     for name, subdir in gas_dir.get_subdirs().items():
         self.load_templates(subdir)
Example #2
0
 def load_node_mesh_guids_recursive(cls, gas_dir: GasDir,
                                    node_mesh_guids: dict):
     for gas_file in gas_dir.get_gas_files().values():
         mesh_file_sections = gas_file.get_gas().find_sections_recursive(
             'mesh_file*')
         for mesh_file_section in mesh_file_sections:
             filename = mesh_file_section.get_attr_value('filename')
             guid = mesh_file_section.get_attr_value('guid')
             node_mesh_guids[guid] = filename
     for subdir in gas_dir.get_subdirs().values():
         cls.load_node_mesh_guids_recursive(subdir, node_mesh_guids)
Example #3
0
 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)
Example #4
0
    def create_region(self, name, region_id) -> Region:
        regions = self.get_regions()
        regions_data = [r.get_data() for r in regions.values()]
        region_ids = [rd.id for rd in regions_data]
        if region_id is not None:
            assert region_id not in region_ids
        else:
            max_region_id = max(region_ids) if region_ids else 0
            region_id = max_region_id + 1

        region_dirs = self.gas_dir.get_subdir('regions').get_subdirs()
        assert name not in region_dirs
        region_dir = GasDir(os.path.join(self.gas_dir.path, 'regions', name))
        region = Region(region_dir, self)
        region_dirs[name] = region_dir

        mesh_ranges = [rd.mesh_range for rd in regions_data]
        mesh_range = region_id if region_id not in mesh_ranges else (max(mesh_ranges + [0]) + 1)
        scid_ranges = [rd.scid_range for rd in regions_data]
        scid_range = region_id if region_id not in scid_ranges else (max(scid_ranges + [0]) + 1)

        region.data = Region.Data()
        region.data.id = region_id
        region.data.mesh_range = mesh_range
        region.data.scid_range = scid_range

        return region
Example #5
0
 def __init__(self, path: str = None):
     if path is None or path.upper() == 'DSLOA':
         path = Bits.DSLOA_PATH
     elif path.upper() == 'DS1':
         path = Bits.DS1_PATH
     elif path.upper() == 'DS2':
         path = Bits.DS2_PATH
     assert os.path.isdir(path), path
     super().__init__(GasDir(path))
     self.templates = self.init_templates()
     self.maps: dict[str, Map] = self.init_maps()
Example #6
0
def untranslate_file(lang_dir: GasDir, lang_file_name: str):
    print(lang_file_name)
    lang_file = lang_dir.get_gas_files().get(lang_file_name)
    lang_file_gas: Gas = lang_file.get_gas()
    text_section: Section = lang_file_gas.items[0]
    for translation_section in text_section.get_sections():
        if translation_section.get_attr(
                'from') and translation_section.get_attr('to'):
            translation_section.set_attr_value(
                'to', translation_section.get_attr_value('from'))
    lang_file.save()
Example #7
0
 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))
Example #8
0
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()