def on_save_button(self, evt): # Send a enter key event to property for update values event = wx.KeyEvent(wx.wxEVT_CHAR) event.m_keyCode = wx.WXK_RETURN self.cmds_pg.GetEventHandler().ProcessEvent(event) # make this object the current nebulagui.nebula_object = self.object # Get redo command self.redo = self.__get_redo_command() # Get undo command self.undo = self.__get_undo_command() # new command servers.get_command_server().newcommand(str(self.redo), str(self.undo)) self.draw_state_commands(self.object) if self.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( self.object, True) elif self.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( self.object, True) if self.object.isa("nscenenode"): self.object.loadresources() self.object.setobjectdirty(True)
def on_change_input(self, event): if not self.getting_values: for i in range(self.checklist_input.GetCount()): self.entity.seteventflag(self.event_ids[i], self.checklist_input.IsChecked(i)) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def on_ok_button_clicked(self, event): result_list = self.get_selected_entities() if result_list: if self.has_valid_path_name(): #we need to save the entity id counter to avoid conflicts servers.get_entity_object_server().saveconfig() object_instancer = pynebula.new('nobjectinstancer') object_instancer.init( len(result_list), len(result_list) ) object_instancer.setentityobjecttype( CJR_NORMAL_ENTITY_TYPE ) for each_entity in result_list: entity_id_as_string = str( each_entity.getid() ) object_instancer.appendwithname( each_entity, entity_id_as_string ) object_instancer.saveas( self.get_path_name() ) pynebula.delete(object_instancer) self.Close() else: cjr.show_error_message( "Please enter a valid path name" ) else: cjr.show_error_message( "Please select at least one entity to export" )
def on_change_rectangle(self, event): if not self.getting_values: hx = self.float_width.get_value() / 2 hz = self.float_length.get_value() / 2 self.entity.setpolygon(-hx, 0, -hz, hx, 0, -hz, hx, 0, hz) self.entity.addvertextopolygon(-hx, 0, hz) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def on_select_script(self, event): if not self.getting_values: # Get the selected trigger script name = self.choice_script.GetStringSelection() if name == "<none>": # Unset trigger script self.entity.settriggerscript( None ) else: # Set the trigger script self.entity.settriggerscriptbyname( str(name) ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
def on_select_script(self, event): if not self.getting_values: # Get the selected trigger script name = self.choice_script.GetStringSelection() if name == "<none>": # Unset trigger script self.entity.settriggerscript(None) else: # Set the trigger script self.entity.settriggerscriptbyname(str(name)) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def set_event_flag(self, index, enabled): if self.entity.isa('nentityclass'): if self.events_set == InEvents: self.entity.setperceivableevent(index, enabled) else: self.entity.setemittedevent(index, enabled) servers.get_entity_class_server().setentityclassdirty( self.entity, True) else: self.entity.seteventflag(index, enabled) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def on_change_shape(self, event): if not self.getting_values: radius = 5.0 if self.choicebook_shape.GetSelection() == self.ID_Circle: self.float_radius.set_value( radius ) self.on_change_circle( None ) self.float_circle_height.set_value( self.entity.getheight() ) else: self.float_length.set_value( radius ) self.float_width.set_value( radius ) self.on_change_rectangle( None ) self.float_polygon_height.set_value( self.entity.getheight() ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
def on_change_rectangle(self, event): if not self.getting_values: hx = self.float_width.get_value() / 2 hz = self.float_length.get_value() / 2 self.entity.setpolygon( -hx, 0, -hz, hx, 0, -hz, hx, 0, hz ) self.entity.addvertextopolygon( -hx, 0, hz ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
def on_change_shape(self, event): if not self.getting_values: radius = 5.0 if self.choicebook_shape.GetSelection() == self.ID_Circle: self.float_radius.set_value(radius) self.on_change_circle(None) self.float_circle_height.set_value(self.entity.getheight()) else: self.float_length.set_value(radius) self.float_width.set_value(radius) self.on_change_rectangle(None) self.float_polygon_height.set_value(self.entity.getheight()) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def rename_entity ( self ): """ Renames the name of an entity """ rows = self.grid.GetSelectedRows() entity_server = servers.get_entity_object_server() for idx in rows: row = self.grid.data[idx] entity_id = row[0] entity = entity_server.getentityobject(entity_id) if not entity.hascomponent("ncGameplay"): cjr.show_information_message( "Only gameplay entities may have a name" ) else: dlg = wx.TextEntryDialog( None, "Enter entity name:", "Rename entity", entity.getname() ) if dlg.ShowModal() == wx.ID_OK: name = dlg.GetValue() entity.setname( str(name) ) entity_server.setentityobjectdirty(entity, True) self.refresh() dlg.Destroy()
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 layer_can_be_deleted(layer): """ Check that the layer can be deleted. Warn the user if it isn't and return false. Otherwise just return true. """ # check the layer has not been locked layer_name = layer.getlayername() if layer.islocked(): cjr.show_error_message( "You cannot delete the '%s' layer.\n\n" \ "It is not possible to delete a locked layer." % layer_name ) return False # check that there're at least two layers manager = servers.get_layer_manager() if manager.getnumlayers() <= 1: msg = "You cannot delete the '%s' layer.\n\n" \ "A level must always have at least one layer." % layer_name cjr.show_error_message(msg) return False # check if there's some entity not marked as deleted within the layer try: try: wx.BeginBusyCursor() e_server = servers.get_entity_object_server() entity = e_server.getfirstentityobject() report = [] while entity is not None: if entity.hascomponent('ncEditor'): if not entity.isdeleted(): entity_layer_id = entity.getlayerid() if entity_layer_id >= 0: entity_layer = manager.searchlayerbyid( entity_layer_id) if entity_layer.getlayername() == layer_name: entity_class = entity.getentityclass().getname( ) entity_name = "" if entity.hascomponent('ncGameplay'): entity_name = entity.getname() report.append((entity.getid(), entity_class, entity_name)) entity = e_server.getnextentityobject() finally: wx.EndBusyCursor() except: # make sure any errors are not hidden raise # show a report about all the entities found in the layer, if any if len(report) > 0: caption = "Error deleting the '%s' layer" % layer_name msg = "Unable to delete the '%s' layer because it " \ "still contains the following entities" % layer_name log = (['Id', 'Class', 'Name'], report) usagelog.UsageLogDialog(app.get_top_window(), caption, msg, log) return False return True
def set_event_flag(self, index, enabled): if self.entity.isa('nentityclass'): if self.events_set == InEvents: self.entity.setperceivableevent( index, enabled ) else: self.entity.setemittedevent( index, enabled ) servers.get_entity_class_server().setentityclassdirty( self.entity, True ) else: self.entity.seteventflag( index, enabled ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
def get_selected_entities(self): """"Return a list of all entities currently selected in the list, regardless of whether they are selected in Summoner""" entity_server = servers.get_entity_object_server() entity_list = [] for each_id in self.__get_ids_of_selected_entities(): entity_list.append( entity_server.getentityobject(each_id) ) return entity_list
def get_all_entities_for_selected_layer(self): """Return a list of entities""" layer_id = self.get_id_for_selected_layer() entity_list = [] entity_server = servers.get_entity_object_server() entity = entity_server.getfirstentityobject() while entity is not None: if entity.hascomponent('ncEditor') \ and entity.getlayerid() == layer_id: entity_list.append(entity) entity = entity_server.getnextentityobject() return entity_list
def on_ok_button_clicked(self, event): result_list = self.get_selected_entities() if result_list: if self.has_valid_path_name(): #we need to save the entity id counter to avoid conflicts servers.get_entity_object_server().saveconfig() object_instancer = pynebula.new('nobjectinstancer') object_instancer.init(len(result_list), len(result_list)) object_instancer.setentityobjecttype(CJR_NORMAL_ENTITY_TYPE) for each_entity in result_list: entity_id_as_string = str(each_entity.getid()) object_instancer.appendwithname(each_entity, entity_id_as_string) object_instancer.saveas(self.get_path_name()) pynebula.delete(object_instancer) self.Close() else: cjr.show_error_message("Please enter a valid path name") else: cjr.show_error_message( "Please select at least one entity to export")
def prelevel_process(is_new_level): # Forbid any level operation while in game mode if app.is_in_gameplay_mode(): cjr.show_error_message( "Operation not allowed while in game mode" ) return False # Exit from any test mode app.get_ai_tester().disablegameplayupdating() app.get_ai_tester().disablesoundsources() # Clear undo buffer servers.get_command_server().clean() if not is_new_level: return True # Discard deleted entities servers.get_entity_object_server().discarddeletedobjects() servers.get_entity_class_server().discarddeletedclasses() # What follows should be done only for new and open level commands # Clear selection app.get_object_state().resetselection() # Make terrain state release some buffers if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor(None) # Begin a persist-restore process to close those invalid windows for # the new level and refresh the valid ones (continue in postlevel_process) # Persist guiDialog windows frame = app.get_top_window() prelevel_process.child_data = [] for child in frame.get_child_dialogs(): data = persist_window(child) if data is not None: prelevel_process.child_data.insert(0, data) return True
def set_layer_visibility(self, active): layer_id = self.get_layer_id() e_server = servers.get_entity_object_server() entity = e_server.getfirstentityobject() while entity is not None: if entity.hascomponent("ncSpatial") \ and entity.hascomponent("ncEditor"): if entity.getlayerid() == layer_id and not entity.isdeleted(): if active: entity.restorefromtemparray() else: entity.removetemporary() entity = e_server.getnextentityobject()
def prelevel_process(is_new_level): # Forbid any level operation while in game mode if app.is_in_gameplay_mode(): cjr.show_error_message("Operation not allowed while in game mode") return False # Exit from any test mode app.get_ai_tester().disablegameplayupdating() app.get_ai_tester().disablesoundsources() # Clear undo buffer servers.get_command_server().clean() if not is_new_level: return True # Discard deleted entities servers.get_entity_object_server().discarddeletedobjects() servers.get_entity_class_server().discarddeletedclasses() # What follows should be done only for new and open level commands # Clear selection app.get_object_state().resetselection() # Make terrain state release some buffers if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor(None) # Begin a persist-restore process to close those invalid windows for # the new level and refresh the valid ones (continue in postlevel_process) # Persist guiDialog windows frame = app.get_top_window() prelevel_process.child_data = [] for child in frame.get_child_dialogs(): data = persist_window(child) if data is not None: prelevel_process.child_data.insert(0, data) return True
def get_entityobject_desc(entity_id): name = '' object = servers.get_entity_object_server().getentityobject(entity_id) if object.hascommand("getname"): gameplay_name = object.getname() if gameplay_name != '': name = "%s - " % object.getname() name += str(hex(object.getid())) + " - " + object.getclass() entity_class = object.getentityclass() class_path_cleared = entity_class.getfullname().replace( '/sys/nobject/nentityobject/', '') name += " ( %s )" % os.path.dirname(class_path_cleared) return name
def __get_prop_values(self): source_id = self.props_event.get_property_value(self.pids['source']) if source_id == 0: source_id = self.entity.getid() source = servers.get_entity_object_server().getentityobject(source_id) if source is None: cjr.show_warning_message( "There's no valid source entity for the specified entity id") source = self.entity self.props_event.set_property_value(self.pids['source'], 0) self.props_event.Refresh() duration = self.props_event.get_property_value(self.pids['duration']) priority = self.props_event.get_property_value(self.pids['priority']) return {'source': source, 'duration': duration, 'priority': priority}
def on_save_button (self, evt): # Send a enter key event to property for update values event = wx.KeyEvent(wx.wxEVT_CHAR) event.m_keyCode = wx.WXK_RETURN self.cmds_pg.GetEventHandler().ProcessEvent(event) # make this object the current nebulagui.nebula_object = self.object # Get redo command self.redo = self.__get_redo_command() # Get undo command self.undo = self.__get_undo_command() # new command servers.get_command_server().newcommand(str(self.redo), str(self.undo)) self.draw_state_commands(self.object) if self.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( self.object, True ) elif self.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( self.object, True ) if self.object.isa("nscenenode"): self.object.loadresources() self.object.setobjectdirty(True)
def __get_prop_values(self): source_id = self.props_event.get_property_value( self.pids['source'] ) if source_id == 0: source_id = self.entity.getid() source = servers.get_entity_object_server().getentityobject( source_id ) if source is None: cjr.show_warning_message( "There's no valid source entity for the specified entity id" ) source = self.entity self.props_event.set_property_value( self.pids['source'], 0 ) self.props_event.Refresh() duration = self.props_event.get_property_value( self.pids['duration'] ) priority = self.props_event.get_property_value( self.pids['priority'] ) return {'source': source, 'duration': duration, 'priority': priority}
def get_entityobject_desc ( entity_id ): name = '' object = servers.get_entity_object_server().getentityobject(entity_id) if object.hascommand("getname"): gameplay_name = object.getname() if gameplay_name != '': name = "%s - " % object.getname() name += str(hex(object.getid())) + " - " + object.getclass() entity_class = object.getentityclass() class_path_cleared = entity_class.getfullname().replace( '/sys/nobject/nentityobject/', '' ) name += " ( %s )" % os.path.dirname(class_path_cleared) return name
def on_toggle_sound(self, event): enable = event.Checked() self.Check(ID_ToggleSound, enable) self.get_frame().get_toolbar().ToggleTool(ID_ToggleSound, enable) if enable: app.get_ai_tester().enablesoundsources() else: app.get_ai_tester().disablesoundsources() e_server = servers.get_entity_object_server() entity = e_server.getfirstentityobject() while entity is not None: if entity.hascomponent('ncAreaTrigger'): entity.resets() if entity.hascomponent('ncSound'): entity.disablesoundtrigger() entity = e_server.getnextentityobject()
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_move_entities(self, event): if self.layer_selected is None: cjr.show_error_message("Please select a layer") else: layer_id = self.get_id_for_selected_layer() obj_state = app.get_object_state() items_were_moved = False for i in range( obj_state.getselectioncount() ): entity = obj_state.getselectedentity(i) if entity.hascomponent('ncEditor'): entity.setlayerid(layer_id) e_server = servers.get_entity_object_server() e_server.setentityobjectdirty(entity, True) items_were_moved = True if not items_were_moved: cjr.show_error_message( "There are no entities currently selected "\ "that can be moved to this layer" )
def on_move_entities(self, event): if self.layer_selected is None: cjr.show_error_message("Please select a layer") else: layer_id = self.get_id_for_selected_layer() obj_state = app.get_object_state() items_were_moved = False for i in range(obj_state.getselectioncount()): entity = obj_state.getselectedentity(i) if entity.hascomponent('ncEditor'): entity.setlayerid(layer_id) e_server = servers.get_entity_object_server() e_server.setentityobjectdirty(entity, True) items_were_moved = True if not items_were_moved: cjr.show_error_message( "There are no entities currently selected "\ "that can be moved to this layer" )
def unpackEntitiesAndAddToWorld(self): entity_server = servers.get_entity_object_server() world_server = servers.get_world_interface() number_of_elements = self.containerObject.size() for index in range(number_of_elements): entity = self.containerObject.at(index) original_id = self.containerObject.getobjectnameatindex(index) #check if the entity already exists match = entity_server.getentityobject( int(original_id) ) if not match == None: result = cjr.confirm_yes_no( self.parentView, "This entity already exists. "\ "Do you want to overwrite it?" ) wantsToOverwrite = (result == wx.ID_YES) if wantsToOverwrite: entity_server.swapentityobjectids(match, entity) entity_server.removeentityobject(match) entity.setlayerid(self.targetLayerId) world_server.addtoworld(entity)
def __get_object_value(self, pid): """Return the object of an object property""" p = self.properties[str(pid)] value = p.property.GetValueAsString(0) if value == "None": return None # Regular expresion for match the object type ENTITY_OBJECT = re.compile(r'\w[\w\d]*\(id=(.*)\)') NROOT = re.compile(r'(/.*)') NOBJECT = re.compile(r'nObject\((.*)\)') # Get the real object g = ENTITY_OBJECT.search(value) if (g): return servers.get_entity_object_server().getentityobject( int(g.group(1)) ) else: g = NROOT.search(value) if (g): return pynebula.lookup(value) else: g = NOBJECT.search(value) if (g): return None else: return None
def on_change_circle(self, event): if not self.getting_values: r = self.float_radius.get_value() self.entity.setcircle(r) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def __get_entity_object_with_id(self, object_id): object_server = servers.get_entity_object_server() return object_server.getentityobject(object_id)
def __mark_entity_as_dirty(self): servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def create_data (self, class_type_list, pattern=""): data = [] # prevent bad expression error if "*" == pattern: pattern = "." #set up a temporary dictionary to make lookup quicker if class_type_list is not None: class_type_dict = {} for each in class_type_list: class_type_dict[each] = True entity_server = servers.get_entity_object_server() layer_name_gopher = FastLayerNameGopher() entity = entity_server.getfirstentityobject() while entity is not None: if not entity.isinlimbo() and not entity.ishideineditor(): if class_type_list is None: include_class = True else: native_class = entity.getclasses()[-3] include_class = class_type_dict.has_key( native_class ) if include_class: class_name = entity.getclass() if pattern == "": # don't do the search unless really necessary match = True else: match = re.compile( pattern, re.IGNORECASE ).search(class_name) if match: row = [] # get entity id and cool name, if defined entity_id = entity.getid() if entity.hascommand("getname"): entity_cool_name = entity.getname() else: entity_cool_name = '-' # get layername if entity.hascommand("geteditorkeyint"): layer_id = entity.geteditorkeyint("layerId") else: layer_id = -1 layer_name = layer_name_gopher.\ get_name_for_layer_with_id( layer_id ) # get dirty state dirty = entity_server.getentityobjectdirty( entity_id ) # fill row row.append(entity_id) row.append( hex(entity_id) ) row.append(class_name) row.append(entity_cool_name) row.append(layer_name) if dirty: row.append("Yes") else: row.append("No") data.append(row) entity = entity_server.getnextentityobject() return data
def __get_entity_with_id(self, entity_id): entity_object_server = servers.get_entity_object_server() return entity_object_server.getentityobject(entity_id)
def get_entity_type_for_entity(self, entity): entity_server = servers.get_entity_object_server() return entity_server.getentityobjecttype( entity.getid() )
def __update_sound_triggers(self): es = servers.get_entity_object_server()
def on_change_input(self, event): if not self.getting_values: for i in range( self.checklist_input.GetCount() ): self.entity.seteventflag( self.event_ids[i], self.checklist_input.IsChecked(i) ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
def layer_can_be_deleted(layer): """ Check that the layer can be deleted. Warn the user if it isn't and return false. Otherwise just return true. """ # check the layer has not been locked layer_name = layer.getlayername() if layer.islocked(): cjr.show_error_message( "You cannot delete the '%s' layer.\n\n" \ "It is not possible to delete a locked layer." % layer_name ) return False # check that there're at least two layers manager = servers.get_layer_manager() if manager.getnumlayers() <= 1: msg = "You cannot delete the '%s' layer.\n\n" \ "A level must always have at least one layer." % layer_name cjr.show_error_message(msg) return False # check if there's some entity not marked as deleted within the layer try: try: wx.BeginBusyCursor() e_server = servers.get_entity_object_server() entity = e_server.getfirstentityobject() report = [] while entity is not None: if entity.hascomponent('ncEditor'): if not entity.isdeleted(): entity_layer_id = entity.getlayerid() if entity_layer_id >= 0: entity_layer = manager.searchlayerbyid( entity_layer_id ) if entity_layer.getlayername() == layer_name: entity_class = entity.getentityclass().getname() entity_name = "" if entity.hascomponent('ncGameplay'): entity_name = entity.getname() report.append( (entity.getid(), entity_class, entity_name) ) entity = e_server.getnextentityobject() finally: wx.EndBusyCursor() except: # make sure any errors are not hidden raise # show a report about all the entities found in the layer, if any if len( report ) > 0: caption = "Error deleting the '%s' layer" % layer_name msg = "Unable to delete the '%s' layer because it " \ "still contains the following entities" % layer_name log = ( ['Id', 'Class', 'Name'], report ) usagelog.UsageLogDialog( app.get_top_window(), caption, msg, log ) return False return True
def get_entity_type_for_entity(self, entity): entity_server = servers.get_entity_object_server() return entity_server.getentityobjecttype(entity.getid())
import servers es = servers.get_entity_object_server() entity = es.getfirstentityobject() while (entity != None): if entity.hascomponent("ncTransform") and not entity.hascomponent("ncPhyTerrainCell"): x,y,z = entity.getposition() entity.setposition(x, y, z) entity = es.getnextentityobject()
def on_change_polygon_height(self, event): if not self.getting_values: self.entity.setheight(self.float_polygon_height.get_value()) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def get_outdoor_obj(): id = get_level().findentity('outdoor') if id == 0: return None else: return servers.get_entity_object_server().getentityobject(id)
def on_change_circle(self, event): if not self.getting_values: r = self.float_radius.get_value() self.entity.setcircle( r ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
import servers es = servers.get_entity_object_server() entity = es.getfirstentityobject() while (entity != None): if entity.hascomponent( "ncTransform") and not entity.hascomponent("ncPhyTerrainCell"): x, y, z = entity.getposition() entity.setposition(x, y, z) entity = es.getnextentityobject()
def on_change_polygon_height(self, event): if not self.getting_values: self.entity.setheight( self.float_polygon_height.get_value() ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
def execute (inspector): # make this object the current nebulagui.nebula_object = inspector.object # Construct the command string to be called. # A variable will be use for storage the return value/s command = "import nebulagui;" command = command + "result = nebulagui.nebula_object.%s" % inspector.cmds.GetValue()+ "(" i = 0 for param in inspector.in_params: field = inspector.in_elements[i] param_type = inspector.xml.get_param_type(param) if param_type == 's': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "'%s'," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass name and use it as parameter object_id = re.compile("(\w*)\(").search(string) getentity_string = str( object_id.group(1) ) command = command + getentity_string + "," else: command = command + "'%s'," % field.GetValueAsString(0) elif param_type == 'o': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "lookup('%s')," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass id for get the entity object and use it as parameter object_id = re.compile("id=(\d*)").search(string) getentity_string = "servers.get_entity_object_server().getentityobject("+ str(object_id.group(1)) + ")" command = command + getentity_string + "," else: command = command + "lookup('%s')," % field.GetValueAsString(0) else: command = command + "%s," % field.GetValueAsString(0) i = i + 1 if i > 0: command = command[:-1] command = command + ")" # Run the command servers.get_python_server().run(str(command)) # Look for return values. If it have, extract it from the result # and fill the propertygrid fields. if len(inspector.out_params) > 0: if len(inspector.out_params) > 1: for i in xrange(len(inspector.out_params)): servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result[" + str(i) +"]") __draw_return_values( inspector, ret, inspector.out_params[i], inspector.out_elements[i] ) else: servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result") __draw_return_values( inspector, ret, inspector.out_params[0], inspector.out_elements[0] ) # delete temp variable servers.get_python_server().run( str("del result") ) # if is a entity dirt the object. # TODO: Ugly hack! Find a better way to do this if inspector.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( inspector.object, True ) elif inspector.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( inspector.object, True ) # Refresh control inspector.cmds_pg.CollapseAll() inspector.cmds_pg.ExpandAll() inspector.executed = True
def execute(inspector): # make this object the current nebulagui.nebula_object = inspector.object # Construct the command string to be called. # A variable will be use for storage the return value/s command = "import nebulagui;" command = command + "result = nebulagui.nebula_object.%s" % inspector.cmds.GetValue( ) + "(" i = 0 for param in inspector.in_params: field = inspector.in_elements[i] param_type = inspector.xml.get_param_type(param) if param_type == 's': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "'%s'," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass name and use it as parameter object_id = re.compile("(\w*)\(").search(string) getentity_string = str(object_id.group(1)) command = command + getentity_string + "," else: command = command + "'%s'," % field.GetValueAsString(0) elif param_type == 'o': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "lookup('%s')," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass id for get the entity object and use it as parameter object_id = re.compile("id=(\d*)").search(string) getentity_string = "servers.get_entity_object_server().getentityobject(" + str( object_id.group(1)) + ")" command = command + getentity_string + "," else: command = command + "lookup('%s')," % field.GetValueAsString(0) else: command = command + "%s," % field.GetValueAsString(0) i = i + 1 if i > 0: command = command[:-1] command = command + ")" # Run the command servers.get_python_server().run(str(command)) # Look for return values. If it have, extract it from the result # and fill the propertygrid fields. if len(inspector.out_params) > 0: if len(inspector.out_params) > 1: for i in xrange(len(inspector.out_params)): servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result[" + str(i) +"]") __draw_return_values(inspector, ret, inspector.out_params[i], inspector.out_elements[i]) else: servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result") __draw_return_values(inspector, ret, inspector.out_params[0], inspector.out_elements[0]) # delete temp variable servers.get_python_server().run(str("del result")) # if is a entity dirt the object. # TODO: Ugly hack! Find a better way to do this if inspector.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( inspector.object, True) elif inspector.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( inspector.object, True) # Refresh control inspector.cmds_pg.CollapseAll() inspector.cmds_pg.ExpandAll() inspector.executed = True
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) )
def __mark_entity_as_dirty(self): servers.get_entity_object_server().setentityobjectdirty( self.entity, True )