Esempio n. 1
0
 def write_gas(self) -> Gas:
     node_sections = [Section('t:snode,n:' + snode.guid.to_str_lower(), [
         Attribute('bounds_camera', snode.bounds_camera),
         Attribute('camera_fade', snode.camera_fade),
         Attribute('guid', snode.guid),
         Attribute('mesh_guid', Hex(snode.mesh_guid)),
         Attribute('nodelevel', snode.nodelevel),
         Attribute('nodeobject', snode.nodeobject),
         Attribute('nodesection', snode.nodesection),
         Attribute('occludes_camera', snode.occludes_camera),
         Attribute('occludes_light', snode.occludes_light),
         Attribute('texsetabbr', snode.texsetabbr),
     ] + [Section('door*', [
         Attribute('fardoor', door.fardoor),
         Attribute('farguid', door.farguid),
         Attribute('id', door.id),
     ]) for door in snode.doors]) for snode in self.nodes]
     return Gas([
         Section('t:terrain_nodes,n:siege_node_list', [
             Attribute('ambient_color', Hex(self.ambient_color)),
             Attribute('ambient_intensity', float(self.ambient_intensity)),
             Attribute('object_ambient_color', Hex(self.object_ambient_color)),
             Attribute('object_ambient_intensity', float(self.object_ambient_intensity)),
             Attribute('actor_ambient_color', Hex(self.actor_ambient_color)),
             Attribute('actor_ambient_intensity', float(self.actor_ambient_intensity)),
             Attribute('targetnode', self.targetnode)
         ] + node_sections)
     ])
Esempio n. 2
0
 def store_start_positions(self):
     assert self.start_positions is not None
     info_dir = self.gas_dir.get_or_create_subdir('info')
     start_group_sections = []
     gas_file = info_dir.get_or_create_gas_file('start_positions')
     gas_file.gas = Gas([
         Section('start_positions', start_group_sections)
     ])
     for sg_name, sg in self.start_positions.start_groups.items():
         sp_sections: list = [
             Section('start_position', [
                 Attribute('id', sp.id),
                 Attribute('position', str(sp.position)),
                 Section('camera', [
                     Attribute('azimuth', float(sp.camera.azimuth)),
                     Attribute('distance', float(sp.camera.distance)),
                     Attribute('orbit', float(sp.camera.orbit)),
                     Attribute('position', str(sp.camera.position))
                 ])
             ]) for sp in sg.start_positions
         ]
         start_group_sections.append(Section('t:start_group,n:' + sg_name, [
             Attribute('default', self.start_positions.default == sg_name),
             Attribute('description', sg.description),
             Attribute('dev_only', sg.dev_only),
             Attribute('id', sg.id),
             Attribute('screen_name', sg.screen_name)
         ] + sp_sections))
Esempio n. 3
0
 def to_gas(self) -> Gas:
     map_section = Section('t:map,n:map', [
         Attribute('name', self.name),
         Attribute('screen_name', self.screen_name),
         Attribute('description', self.description),
         Attribute('dev_only', self.dev_only),
         Attribute('timeofday', self.timeofday),
         Attribute('use_node_mesh_index', self.use_node_mesh_index),
         Attribute('use_player_journal', self.use_player_journal),
         Section('camera', [
             Attribute('azimuth', self.camera.azimuth),
             Attribute('distance', self.camera.distance),
             Attribute('position', self.camera.position)
         ])
     ])
     if self.worlds is not None:
         world_sections: list[Section] = []
         for name, world in self.worlds.items():
             world_sections.append(Section(name, [
                 Attribute('screen_name', world.screen_name),
                 Attribute('description', world.description),
                 Attribute('required_level', str(world.required_level))
             ]))
         map_section.items.append(Section('worlds', world_sections))
     map_main_gas = Gas([map_section])
     return map_main_gas
Esempio n. 4
0
    def store_terrain(self):
        # index
        mesh_index = self.terrain.get_mesh_index()
        mesh_index = {
            Hex.parse('0x{:03X}{:05X}'.format(self.data.mesh_range,
                                              mesh_guid)): mesh_name
            for mesh_guid, mesh_name in mesh_index.items()
        }
        self.gas_dir.create_subdir(
            'index', {
                'node_mesh_index':
                Gas([
                    Section('node_mesh_index', [
                        Attribute(str(mesh_guid), mesh_name)
                        for mesh_guid, mesh_name in mesh_index.items()
                    ])
                ]),
                'streamer_node_index':
                Gas([
                    Section('streamer_node_index', [
                        Attribute('*', node.guid)
                        for node in self.terrain.nodes
                    ])
                ])
            })

        # terrain_nodes
        nodes_gas = NodesGas()
        nodes_gas.ambient_color = self.terrain.ambient_light.terrain_color
        nodes_gas.ambient_intensity = self.terrain.ambient_light.terrain_intensity
        nodes_gas.object_ambient_color = self.terrain.ambient_light.object_color
        nodes_gas.object_ambient_intensity = self.terrain.ambient_light.object_intensity
        nodes_gas.actor_ambient_color = self.terrain.ambient_light.actor_color
        nodes_gas.actor_ambient_intensity = self.terrain.ambient_light.actor_intensity
        nodes_gas.targetnode = self.terrain.target_node.guid
        snodes = list()
        for node in self.terrain.nodes:
            mesh_guid = Terrain.mesh_index_lookup[node.mesh_name]
            mesh_guid = Hex.parse('0x{:03X}{:05X}'.format(
                self.data.mesh_range, mesh_guid))
            doors = [
                Door(door_id, far_node.guid, far_door)
                for door_id, (far_node, far_door) in node.doors.items()
            ]
            nodesection = Hex(
                node.section if node.section != -1 else 0xffffffff)
            nodelevel = Hex(node.section if node.section != -1 else 0xffffffff)
            nodeobject = Hex(
                node.section if node.section != -1 else 0xffffffff)
            snode = SNode(node.guid, mesh_guid, node.texture_set, True, False,
                          False, True, nodesection, nodelevel, nodeobject,
                          doors)
            snodes.append(snode)
        nodes_gas.nodes = snodes
        self.gas_dir.create_subdir('terrain_nodes',
                                   {'nodes': nodes_gas.write_gas()})
Esempio n. 5
0
 def make_gas(self) -> Section:
     items = []
     if self.dev_instance_text is not None:
         items.append(Attribute('dev_instance_text',
                                self.dev_instance_text))
     if self.instance_triggers is not None:
         items.append(
             Section('instance_triggers',
                     [ti.make_gas() for ti in self.instance_triggers]))
     return Section('common', items)
Esempio n. 6
0
 def ensure_north_vector(self):
     editor_subdir = self.gas_dir.get_or_create_subdir('editor')
     if not editor_subdir.has_gas_file('hotpoints'):
         hotpoints_gas = Gas([
             Section('hotpoints', [
                 Section('t:hotpoint_directional,n:' + str(Hex(1)), [
                     Attribute('direction', '0,0,-1'),
                     Attribute('id', Hex(1))
                 ])
             ])
         ])
         editor_subdir.create_gas_file('hotpoints', hotpoints_gas)
Esempio n. 7
0
 def to_gas_section(self, is_pos):
     return Section('position' if is_pos else 'direction', [
         Attribute('node', self.node_guid),
         Attribute('x', self.x),
         Attribute('y', self.y),
         Attribute('z', self.z),
     ])
Esempio n. 8
0
 def make_gas(self) -> Section:
     attrs = []
     if self.orientation is not None:
         attrs.append(Attribute('orientation', self.orientation))
     if self.position is not None:
         attrs.append(Attribute('position', self.position))
     return Section('placement', attrs)
Esempio n. 9
0
 def write_gas(self) -> Gas:
     se_sections = [
         Section(f't:stitch_editor,n:{se.dest_region}', [
             Attribute('dest_region', se.dest_region),
             Section('node_ids', [
                 Attribute(
                     Hex(stitch_id).to_str_lower(), f'{node_guid},{door}')
                 for stitch_id, (node_guid, door) in se.node_ids.items()
             ])
         ]) for se in self.stitch_editors
     ]
     return Gas([
         Section('stitch_helper_data', [
             Attribute('source_region_guid', Hex(self.source_region_guid)),
             Attribute('source_region_name', self.source_region_name),
         ] + se_sections)
     ])
Esempio n. 10
0
 def make_gas(self) -> Section:
     sections = []
     if self.aspect is not None:
         sections.append(self.aspect.make_gas())
     if self.common is not None:
         sections.append(self.common.make_gas())
     if self.placement is not None:
         sections.append(self.placement.make_gas())
     return Section(f't:{self.template_name},n:{self.scid}', sections)
Esempio n. 11
0
 def to_gas(self) -> Section:
     return Section('t:decal,n:*', [
         Attribute('decal_orientation', ','.join(
             [str(x) for x in self.decal_orientation])),
         Attribute('decal_origin', str(self.decal_origin)),
         Attribute('far_plane', self.far_plane),
         Attribute('guid', self.guid),
         Attribute('horizontal_meters', self.horizontal_meters),
         Attribute('lod', self.lod),
         Attribute('near_plane', self.near_plane),
         Attribute('texture', self.texture),
         Attribute('vertical_meters', self.vertical_meters)
     ])
Esempio n. 12
0
    def store_lights(self):
        # Note: storing directional / point / spot lights; ambient light is part of terrain.

        # prepare
        if self.terrain is not None:
            target_node = self.terrain.target_node
            for light in self.lights:
                if isinstance(light, DirectionalLight):
                    if light.direction.node_guid is None:
                        light.direction.node_guid = target_node.guid

        # store
        lights_dir = self.gas_dir.get_or_create_subdir('lights', False)
        lights_dir.get_or_create_gas_file('lights').gas = Gas([
            Section('lights',
                    [light.to_gas_section() for light in self.lights])
        ])
Esempio n. 13
0
 def _to_gas_section(self,
                     type_name,
                     direction: PosDir = None,
                     position: PosDir = None) -> Section:
     section = Section(f't:{type_name},n:light_{self.id.to_str_lower()}', [
         Attribute('active', self.active),
         Attribute('affects_actors', self.affects_actors),
         Attribute('affects_items', self.affects_items),
         Attribute('affects_terrain', self.affects_terrain),
         Attribute('color', self.color),
         Attribute('draw_shadow', self.draw_shadow),
         Attribute('inner_radius', float(self.inner_radius)),
         Attribute('intensity', float(self.intensity)),
         Attribute('occlude_geometry', self.occlude_geometry),
         Attribute('on_timer', self.on_timer),
         Attribute('outer_radius', float(self.outer_radius))
     ])
     if direction is not None:
         section.items.append(direction.to_gas_section(False))
     if position is not None:
         section.items.append(position.to_gas_section(True))
     return section
Esempio n. 14
0
def convert_region(region: Region, nmg: NodeMeshGuids):
    index_dir = region.gas_dir.get_subdir('index')
    if index_dir.has_gas_file('node_mesh_index'):
        return
    nodes_file = region.gas_dir.get_subdir('terrain_nodes').get_gas_file(
        'nodes')
    node_gas = nodes_file.get_gas()
    nodes_section: Section = node_gas.items[0]
    node_sections = nodes_section.get_sections()
    mesh_guid_attrs = [ns.get_attr('mesh_guid') for ns in node_sections]
    node_mesh_index = {}
    node_mesh_guids = nmg.get_node_mesh_guids()
    for mesh_guid_attr in mesh_guid_attrs:
        mesh_guid = mesh_guid_attr.value.to_str_lower()
        assert mesh_guid in node_mesh_guids, str(
            mesh_guid) + ' is not in ' + str(node_mesh_guids)
        if mesh_guid not in node_mesh_index:
            node_mesh_index[mesh_guid] = Hex(len(node_mesh_index) + 1)
        mesh_id = node_mesh_index[mesh_guid]
        mesh_guid_attr.value = mesh_id
    nodes_file.save()
    node_mesh_index_attrs = [
        Attribute(mesh_id, node_mesh_guids[mesh_guid])
        for mesh_guid, mesh_id in node_mesh_index.items()
    ]
    index_dir.create_gas_file(
        'node_mesh_index',
        Gas([Section('node_mesh_index', node_mesh_index_attrs)])).save()
    region_data = region.get_data()
    if region_data.mesh_range == 0:
        if 0 < region_data.scid_range < Hex.parse('0x00001000'):
            region_data.mesh_range = region_data.scid_range
        elif 0 < region_data.id < Hex.parse('0x00001000'):
            region_data.mesh_range = region_data.id
        if region_data.mesh_range != 0:
            region.save()
    print(f'Converted region {region.get_name()} to NMI')
Esempio n. 15
0
 def make_gas(self) -> Section:
     attrs = []
     if self.scale_multiplier is not None:
         attrs.append(Attribute('scale_multiplier', self.scale_multiplier))
     return Section('aspect', attrs)
Esempio n. 16
0
 def make_gas(self) -> Section:
     return Section('*', [
         Attribute('condition*', self.condition),
         Attribute('action*', self.action)
     ])
Esempio n. 17
0
 def write_gas(self) -> Gas:
     return Gas(
         [Section('decals', [decal.to_gas() for decal in self.decals])])