Exemple #1
0
    def on_select_lightmap_light(self, event):
        # get light        
        num_entities = app.get_object_state().getselectioncount()
        lightid = -1
        for i in xrange(num_entities):
            entity = app.get_object_state().getselectedentity(i)
            if entity.isa("nelight") :
                lightid = entity.getid()
                break

        # if light not found
        if lightid == -1 :
            cjr.show_error_message(
                "No nelight instance found as lightmap light source"
                )
            return

        # if found create in the level
        app.get_level().setentityname(
            lightid,
            "terrain_lightmap_light"
            )
        cjr.show_information_message(
            "Terrain lightmap light selected"
            )
Exemple #2
0
 def get_object_name(self):
     object_id = self.object.getid()
     object_name = app.get_level().getentityname(object_id)
     if object_name == ":null:":
         return str(object_id)
     else:
         return object_name
 def get_object_name (self):
     object_id = self.object.getid()
     object_name = app.get_level().getentityname( object_id )
     if object_name == ":null:":
         return str(object_id)
     else:
         return object_name
Exemple #4
0
def save_preset(preset_path):
    # Create preset path if it doesn't exist
    if not os.path.exists(preset_path):
        os.makedirs(preset_path)
    # Save stdlight
    entity_id = app.get_level().findentity('stdlight')
    if entity_id == 0:
        cjr.show_error_message("'stdlight' not found")
    else:
        entity = servers.get_entity_object_server().getentityobject(entity_id)
        entity.savestateas(
            str(format.append_to_path(preset_path, "stdlight.n2")))
    # Save viewport ui
    viewport_ui = app.get_viewports_dir()
    viewport_ui.savestateas(
        str(format.append_to_path(preset_path, "viewportui.n2")))
    # Save viewports
    for index in range(4):
        viewport_name = "viewport%s.n2" % index
        viewport_path = format.append_to_path(preset_path, viewport_name)
        viewport = pynebula.lookup(
            format.append_to_path(app.get_viewports_dir().getfullname(),
                                  viewport_name[:-3]))
        viewport.savestateas(str(viewport_path))
    # Save special viewport rnsview
    viewport_path = format.append_to_path(preset_path, "rnsview.n2")
    viewport = pynebula.lookup('/usr/rnsview')
    viewport.savestateas(str(viewport_path))
    # Save camera bookmarks
    bookmark_path = format.append_to_path(preset_path, "bookmarks.n2")
    servers.get_conjurer().savebookmarks(bookmark_path)
    # Save mouse settings (sensitivity, invert y-axis, etc)
    mouse_setting_path = format.append_to_path(preset_path, "mousesettings.n2")
    game_state = app.get_state("game")
    game_state.savemousesettings(str(mouse_setting_path))
Exemple #5
0
def get_detailed_object_description(object, object_id):
    """ Get a detailed descrition of an object, used for get
        the title of an editable object, for example.
    """
    name = ''
    if isinstance(object_id, int):
        # entity object format: [gameplay_name - ] hex_id object_class ( entityclass_path )
        name = get_entityobject_desc(object_id)
    elif object_id.startswith('/'):
        # entity class format: CLASS class_name ( entityclass_path )
        if object.isa("nentityclass"):
            name = "CLASS %s" % object.getname()
            class_path_cleared = os.path.dirname(object.getfullname().replace(
                '/sys/nobject/nentityobject/', ''))
            if class_path_cleared == '':
                class_path_cleared = 'native'
            name += " ( %s )" % class_path_cleared
        else:
            name = "%s ( %s )" % (object.getfullname(), object.getclass())
    else:
        entity_id = app.get_level().findentity(object_id)
        if entity_id == 0:
            name = "%s ( %s )" % (str(object_id), object.getclass())
        else:
            name = get_entityobject_desc(entity_id)

    return name
Exemple #6
0
def get_detailed_object_description ( object, object_id ):
    """ Get a detailed descrition of an object, used for get
        the title of an editable object, for example.
    """ 
    name = ''
    if isinstance(object_id, int):
        # entity object format: [gameplay_name - ] hex_id object_class ( entityclass_path )
        name = get_entityobject_desc( object_id )
    elif object_id.startswith('/'):
        # entity class format: CLASS class_name ( entityclass_path )
        if object.isa("nentityclass"):
            name = "CLASS %s" % object.getname()
            class_path_cleared = os.path.dirname(
                                            object.getfullname().replace(
                                                '/sys/nobject/nentityobject/'
                                                ,'')
                                            )
            if class_path_cleared == '':
                class_path_cleared = 'native'
            name += " ( %s )" % class_path_cleared
        else:
            name = "%s ( %s )" % ( object.getfullname(), object.getclass() )
    else:
        entity_id = app.get_level().findentity( object_id )
        if entity_id == 0:
            name =  "%s ( %s )" % ( str(object_id), object.getclass() )
        else:
            name = get_entityobject_desc( entity_id )
        
    return name
Exemple #7
0
    def __get_object(self):
        """
        Return a reference to the object for my object id.

        If no object is found None will be returned.
        For objects in NOH use absolute paths as their object id, 
        for entities use the id given by the entity server.
        """
        if self.object_id is None:
            return None
        if isinstance(self.object_id, int):
            # integer -> nEntity -> Get object from entity server
            return self.__get_entity_object_with_id(
                self.object_id 
                )
        elif self.object_id.startswith('/'):
            # NOH path -> nRoot -> Get object from NOH
            try:
                return pynebula.lookup( self.object_id )
            except:
                return None
        else:
            # name -> nEntity -> Get object from entity server
            entity_id = app.get_level().findentity( self.object_id )
            if entity_id == 0:
                return None
            else:
                return self.__get_entity_object_with_id(
                    entity_id
                    )
Exemple #8
0
 def __assign_preset(self, preset_name):
     # Build level configuration file path
     level_path = format.append_to_path(
         get_presets_path(), "levels/%s.txt" % app.get_level().getname())
     # Write the preset name to the level configuration file
     level_file = open(level_path, 'w')
     level_file.write(preset_name)
     level_file.close()
Exemple #9
0
    def on_select_lightmap_light(self, event):
        # get light
        num_entities = app.get_object_state().getselectioncount()
        lightid = -1
        for i in xrange(num_entities):
            entity = app.get_object_state().getselectedentity(i)
            if entity.isa("nelight"):
                lightid = entity.getid()
                break

        # if light not found
        if lightid == -1:
            cjr.show_error_message(
                "No nelight instance found as lightmap light source")
            return

        # if found create in the level
        app.get_level().setentityname(lightid, "terrain_lightmap_light")
        cjr.show_information_message("Terrain lightmap light selected")
Exemple #10
0
 def __assign_preset(self, preset_name):
     # Build level configuration file path
     level_path = format.append_to_path(
                         get_presets_path(), 
                         "levels/%s.txt" % app.get_level().getname()
                         )
     # Write the preset name to the level configuration file
     level_file = open( level_path, 'w' )
     level_file.write( preset_name )
     level_file.close()
Exemple #11
0
 def on_selected_objects(self, event):
     """ Open an object inspector for each one 
         of the current selected entities. """
     for each_entity in self.get_selected_entities():
         entity_id = each_entity.getid()
         name = app.get_level().getentityname(entity_id)
         if name == ':null:':
             win = objdlg.create_window(self.get_frame(), entity_id)
             win.display()
         else:
             win = objdlg.create_window(self.get_frame(), name)
             win.display()
    def on_ok(self, event):
        # Verify that has been given a valid class name
        name = str(self.text_classname.GetValue().capitalize())
        if not servers.get_entity_class_server().checkclassname(name):
            cjr.show_error_message("Invalid class name.")
            return

        # get lightmap size
        lightmap_size = self.get_lightmap_resolution()

        # get lightmap size
        shadowmap_size = self.get_shadowmap_resolution()

        # get the global lightmap size
        global_lightmap_size = self.get_global_lightmap_resolution()

        # get light id
        lightid = app.get_level().findentity("terrain_lightmap_light")

        distance = self.text_ctrl_distance.get_value()
        offset_u = self.text_ctrl_offset_u.get_value()
        offset_v = self.text_ctrl_offset_v.get_value()
        aaliasing = self.text_ctrl_aaliasing.get_value()

        overwrite = self.checkbox_overwrite.IsChecked()

        # if light not found
        if lightid == 0:
            cjr.show_information_message("Please use the 'Select lightmap light' " "option to select the light")
            return

        # Create the terrain class
        dlg = waitdlg.WaitDialog(self.GetParent(), "Creating terrain lightmap...")
        terrain = trn.get_terrain_module()
        terrain.createterrainlightmaps(
            name,
            lightmap_size,
            shadowmap_size,
            global_lightmap_size,
            lightid,
            overwrite,
            distance,
            offset_u,
            offset_v,
            aaliasing,
        )

        # Closes dialog reporting OK
        dlg.Destroy()
        self.EndModal(wx.ID_OK)
Exemple #13
0
def get_level_preset_name():
    # Get the preset name from the current level's configuration file
    level_name = app.get_level().getname()
    level_path = format.append_to_path(get_presets_path(),
                                       "levels/%s.txt" % level_name)
    if os.path.exists(level_path):
        # The level has a configuration file: get the preset name from it
        level_file = open(level_path, 'r')
        preset_name = level_file.read()
        level_file.close()
    else:
        # The level doesn't have a configuration file: use the default preset
        preset_name = "default"
    return preset_name
Exemple #14
0
def get_level_preset_name():
    # Get the preset name from the current level's configuration file
    level_name = app.get_level().getname()
    level_path = format.append_to_path(
                        get_presets_path(), 
                        "levels/%s.txt" % level_name
                        )
    if os.path.exists(level_path):
        # The level has a configuration file: get the preset name from it
        level_file = open(level_path, 'r')
        preset_name = level_file.read()
        level_file.close()
    else:
        # The level doesn't have a configuration file: use the default preset
        preset_name = "default"
    return preset_name
Exemple #15
0
def save_preset(preset_path):
    # Create preset path if it doesn't exist
    if not os.path.exists( preset_path ):
        os.makedirs( preset_path )
    # Save stdlight
    entity_id = app.get_level().findentity('stdlight')
    if entity_id == 0:
        cjr.show_error_message("'stdlight' not found")
    else:
        entity = servers.get_entity_object_server().getentityobject( entity_id )
        entity.savestateas(
            str( format.append_to_path(preset_path, "stdlight.n2") ) 
            )
    # Save viewport ui
    viewport_ui = app.get_viewports_dir()
    viewport_ui.savestateas(
        str( format.append_to_path(preset_path, "viewportui.n2") ) 
        )
    # Save viewports
    for index in range(4):
        viewport_name = "viewport%s.n2" % index
        viewport_path = format.append_to_path( preset_path, viewport_name )
        viewport = pynebula.lookup(
                            format.append_to_path(
                                app.get_viewports_dir().getfullname(), 
                                viewport_name[:-3]
                                )
                            )
        viewport.savestateas( str(viewport_path) )
    # Save special viewport rnsview
    viewport_path = format.append_to_path( preset_path, "rnsview.n2" )
    viewport = pynebula.lookup( '/usr/rnsview' )
    viewport.savestateas( str(viewport_path) )
    # Save camera bookmarks
    bookmark_path = format.append_to_path(
                                preset_path, 
                                "bookmarks.n2" 
                                )
    servers.get_conjurer().savebookmarks( bookmark_path )
    # Save mouse settings (sensitivity, invert y-axis, etc)
    mouse_setting_path = format.append_to_path(
                                    preset_path, 
                                    "mousesettings.n2" 
                                    )
    game_state = app.get_state( "game" )
    game_state.savemousesettings( str(mouse_setting_path) )
    def on_ok(self, event):
        # Verify that has been given a valid class name
        name = str(self.text_classname.GetValue().capitalize())
        if not servers.get_entity_class_server().checkclassname(name):
            cjr.show_error_message("Invalid class name.")
            return

        # get lightmap size
        lightmap_size = self.get_lightmap_resolution()

        # get lightmap size
        shadowmap_size = self.get_shadowmap_resolution()

        # get the global lightmap size
        global_lightmap_size = self.get_global_lightmap_resolution()

        # get light id
        lightid = app.get_level().findentity("terrain_lightmap_light")

        distance = self.text_ctrl_distance.get_value()
        offset_u = self.text_ctrl_offset_u.get_value()
        offset_v = self.text_ctrl_offset_v.get_value()
        aaliasing = self.text_ctrl_aaliasing.get_value()

        overwrite = self.checkbox_overwrite.IsChecked()

        # if light not found
        if lightid == 0:
            cjr.show_information_message(
                "Please use the 'Select lightmap light' " \
                "option to select the light"
                )
            return

        # Create the terrain class
        dlg = waitdlg.WaitDialog(self.GetParent(),
                                 "Creating terrain lightmap...")
        terrain = trn.get_terrain_module()
        terrain.createterrainlightmaps(name, lightmap_size, shadowmap_size,
                                       global_lightmap_size, lightid,
                                       overwrite, distance, offset_u, offset_v,
                                       aaliasing)

        # Closes dialog reporting OK
        dlg.Destroy()
        self.EndModal(wx.ID_OK)
Exemple #17
0
 def on_selected_objects (self, event):
     """ Open an object inspector for each one 
         of the current selected entities. """
     for each_entity in self.get_selected_entities():
         entity_id = each_entity.getid()
         name = app.get_level().getentityname( entity_id )
         if name == ':null:':
             win = objdlg.create_window(
                         self.get_frame(), 
                         entity_id 
                         )
             win.display()
         else:
             win = objdlg.create_window(
                         self.get_frame(), 
                         name 
                         )
             win.display()
Exemple #18
0
def apply_preset(preset_name, preset_path):
    """Load and apply the specified preset"""
    # Validate preset path
    if not os.path.exists(preset_path):
        if preset_name != "default":
            level_name = get_name_of_current_level()
            msg = "Unable to find the '%s' preset attached to " \
                        "the '%s' level" % (preset_name, level_name) 
            cjr.show_error_message(msg)
        return

    # Load stdlight
    stdlight_path = format.append_to_path(preset_path, "stdlight.n2") 
    if not os.path.exists(stdlight_path):
        cjr.show_error_message(
            "Unable to find the Stdlight state for the '%s' preset"\
            % preset_name
            )
    else:
        entity_id = app.get_level().findentity('stdlight')
        if entity_id == 0:
            cjr.show_error_message("'stdlight' not found")
        else:
            entity = servers.get_entity_object_server().getentityobject(
                            entity_id 
                            )
            entity.loadstate( str(stdlight_path) )

    # Viewport UI
    viewport_ui_path = format.append_to_path( preset_path, "viewportui.n2" )
    if not os.path.exists( viewport_ui_path ):
        cjr.show_error_message(
            "Unable to find the Viewport UI state for the '%s' preset"\
            % preset_name
            )
    else:
        viewport_ui = app.get_viewports_dir()
        viewport_ui.loadstate( str(viewport_ui_path) )

    # Viewports
    for index in range(4):
        viewport_name = "viewport%s.n2" % index
        viewport_path = format.append_to_path( preset_path, viewport_name )
        if not os.path.exists( viewport_path ):
            cjr.show_error_message(
                "Unable to find the Viewport %s state for the '%s' preset" \
                % ( index, preset_name )
                )
        else:
            viewport = pynebula.lookup(
                                format.append_to_path(
                                    app.get_viewports_dir().getfullname(), 
                                    viewport_name[:-3]
                                    )
                                )
            viewport.loadstate( str(viewport_path) )
    # Special viewport rnsview
    viewport_path = format.append_to_path(preset_path, "rnsview.n2")
    if os.path.exists( viewport_path ):
        viewport = pynebula.lookup( '/usr/rnsview' )
        viewport.loadstate( str(viewport_path) )

    # Camera bookmarks
    bookmark_path = format.append_to_path(preset_path, "bookmarks.n2")
    if os.path.exists( bookmark_path ):
        servers.get_conjurer().loadbookmarks(bookmark_path)

    # Mouse settings (sensitivity, invert y-axis, etc)
    mouse_setting_path = format.append_to_path(preset_path, "mousesettings.n2")
    if os.path.exists( mouse_setting_path ):
        game_state = app.get_state("game")
        game_state.loadmousesettings( str(mouse_setting_path) )
Exemple #19
0
def apply_preset(preset_name, preset_path):
    """Load and apply the specified preset"""
    # Validate preset path
    if not os.path.exists(preset_path):
        if preset_name != "default":
            level_name = get_name_of_current_level()
            msg = "Unable to find the '%s' preset attached to " \
                        "the '%s' level" % (preset_name, level_name)
            cjr.show_error_message(msg)
        return

    # Load stdlight
    stdlight_path = format.append_to_path(preset_path, "stdlight.n2")
    if not os.path.exists(stdlight_path):
        cjr.show_error_message(
            "Unable to find the Stdlight state for the '%s' preset"\
            % preset_name
            )
    else:
        entity_id = app.get_level().findentity('stdlight')
        if entity_id == 0:
            cjr.show_error_message("'stdlight' not found")
        else:
            entity = servers.get_entity_object_server().getentityobject(
                entity_id)
            entity.loadstate(str(stdlight_path))

    # Viewport UI
    viewport_ui_path = format.append_to_path(preset_path, "viewportui.n2")
    if not os.path.exists(viewport_ui_path):
        cjr.show_error_message(
            "Unable to find the Viewport UI state for the '%s' preset"\
            % preset_name
            )
    else:
        viewport_ui = app.get_viewports_dir()
        viewport_ui.loadstate(str(viewport_ui_path))

    # Viewports
    for index in range(4):
        viewport_name = "viewport%s.n2" % index
        viewport_path = format.append_to_path(preset_path, viewport_name)
        if not os.path.exists(viewport_path):
            cjr.show_error_message(
                "Unable to find the Viewport %s state for the '%s' preset" \
                % ( index, preset_name )
                )
        else:
            viewport = pynebula.lookup(
                format.append_to_path(app.get_viewports_dir().getfullname(),
                                      viewport_name[:-3]))
            viewport.loadstate(str(viewport_path))
    # Special viewport rnsview
    viewport_path = format.append_to_path(preset_path, "rnsview.n2")
    if os.path.exists(viewport_path):
        viewport = pynebula.lookup('/usr/rnsview')
        viewport.loadstate(str(viewport_path))

    # Camera bookmarks
    bookmark_path = format.append_to_path(preset_path, "bookmarks.n2")
    if os.path.exists(bookmark_path):
        servers.get_conjurer().loadbookmarks(bookmark_path)

    # Mouse settings (sensitivity, invert y-axis, etc)
    mouse_setting_path = format.append_to_path(preset_path, "mousesettings.n2")
    if os.path.exists(mouse_setting_path):
        game_state = app.get_state("game")
        game_state.loadmousesettings(str(mouse_setting_path))