def select_frame(self): selected_item = self.frame_list_view.currentItem() if selected_item: selected_component = selected_item.component graphic = self.selected_animation.component.graphic.component file_name = graphic.file_name self.show_graphic(file_name) # set field values crop = selected_component.component.crop self.frame_x_field.setText(str(crop.x)) self.frame_y_field.setText(str(crop.y)) self.frame_width_field.setText(str(crop.w)) self.frame_height_field.setText(str(crop.h)) self.frame_repeat_field.setText(str(selected_component.component.repeat)) # update any drawn frame boxes self.graphic_viewer.set_rect(crop) # fire event for selecting a frame new_event = Event('selected_frame', frame_component=selected_component, entity=selected_component.component.entity_id, graphic_file_name=file_name) EVENT_MANAGER.fire_event(new_event)
def add_animation(self): animation_name = str(self.animation_name_field.text()) entity = self.context['selected_entity'] animation_component = AnimationComponent(entity_id=entity, graphic=self.selected_graphic) animation_component_wrapper = Component(animation_component, animation_name) widget_component = WidgetItemComponent(animation_name, animation_component_wrapper) self.animation_list_view.addItem(widget_component) # add new component to the application context context_animations = self.context['entities'][entity]['components']['animation'] context_animations.append(animation_component_wrapper) # fire event for adding an animation new_event = Event('added_animation', animation_component=animation_component_wrapper, entity=animation_component_wrapper.component.entity_id) EVENT_MANAGER.fire_event(new_event) new_event = Event('added_component', entity=entity, component_type='animation', component=animation_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_binding(self): entity = self.context['selected_entity'] binding_name = str(self.binding_name_field.text()) # begin by building the bindings dictionary bindings = dict() mirrors = dict() for i in range(self.selected_inp_list_view.count()): input_comp = self.selected_inp_list_view.item(i).component key = input_comp.component.name.text bindings[key] = input_comp mirrors[key] = input_comp.component.mirror binding_comp = InputComponent(entity_id=entity, bindings=bindings, mirror_bindings=mirrors) binding_comp_wrapper = Component(binding_comp, binding_name) widget_component = WidgetItemComponent(binding_name, binding_comp_wrapper) self.binding_list_view.addItem(widget_component) # add the component to the application context self.context['entities'][entity]['components']['binding'].append( binding_comp_wrapper) # fire event for adding new binding new_event = Event('added_binding', binding_component=binding_comp_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event('added_component', entity=entity, component_type='binding', component=binding_comp_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_animation(self): animation_name = str(self.animation_name_field.text()) entity = self.context['selected_entity'] animation_component = AnimationComponent(entity_id=entity, graphic=self.selected_graphic) animation_component_wrapper = Component(animation_component, animation_name) widget_component = WidgetItemComponent(animation_name, animation_component_wrapper) self.animation_list_view.addItem(widget_component) # add new component to the application context context_animations = self.context['entities'][entity]['components'][ 'animation'] context_animations.append(animation_component_wrapper) # fire event for adding an animation new_event = Event( 'added_animation', animation_component=animation_component_wrapper, entity=animation_component_wrapper.component.entity_id) EVENT_MANAGER.fire_event(new_event) new_event = Event('added_component', entity=entity, component_type='animation', component=animation_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_movement(self): entity = self.context['selected_entity'] name = str(self.move_name_field.text()) standard = self.velocity_standard_type.isChecked() pulse = self.velocity_pulse_type.isChecked() parent = self.parent_list_view.currentItem() body = self.body_tree_view.currentItem().component velocity_wrapper = self.velocity_list_view.currentItem().component if parent != None: parent = parent.component # create movement component object movement_component = MovementComponent(entity_id=entity, body=body, parent=parent, velocity=velocity_wrapper) movement_component_wrapper = Component(movement_component, name) widget_component = WidgetItemComponent(name, movement_component_wrapper) self.movement_list_view.addItem(widget_component) self.context['entities'][entity]['components']['movement'].append(movement_component_wrapper) # fire event new_event = Event('added_component', entity=entity, component_type='movement', component=movement_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_box(self): box_name = str(self.box_name_field.text()) entity = self.context['selected_entity'] frame = self.selected_frame.component rect = Rect(int(self.box_x_field.text()), int(self.box_y_field.text()), int(self.box_width_field.text()), int(self.box_height_field.text())) hitactive = self.check_context['hitactive'] > 0 hurtactive = self.check_context['hurtactive'] > 0 blockactive = self.check_context['blockactive'] > 0 solid = self.check_context['solid'] > 0 box_component = BoxComponent(entity_id=entity, rect=rect, anchor=self.anchor, hitactive=hitactive, hurtactive=hurtactive, blockactive=blockactive, solid=solid) box_component_wrapper = Component(box_component, box_name) widget_component = WidgetItemComponent(box_name, box_component_wrapper) self.box_list_view.addItem(widget_component) # add box to the selected frame's box list frame.hitboxes.append(box_component_wrapper) # add the box component to the application context self.context['entities'][entity]['components']['hitbox'].append( box_component_wrapper) # fire event new_event = Event('added_component', entity=entity, component_type='hitbox', component=box_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_state(self): entity = self.context['selected_entity'] state_name = str(self.state_name_field.text()) # get activation event act_event_name = str(self.activation_list_view.currentItem().text()) # get deactivation event deact_event_name = str(self.deactivation_list_view.currentItem().text()) # get activation component act_component = self.activation_component_tree_view.currentItem().component # build list of rules added to this state rules = list() rule_values = dict() for i in range(self.selected_rule_list_view.count()): item = self.selected_rule_list_view.item(i) rule_component = item.component rules.append(rule_component.rule) rule_values[str(rule_component.rule.text)] = rule_component.rule_value # create state component state_component = StateComponent(entity_id=entity, rules=rules, activation_event_type=act_event_name, deactivation_event_type=deact_event_name, activation_component=act_component, rule_values=rule_values) state_component_wrapper = Component(state_component, state_name) widget_component = WidgetItemComponent(state_name, state_component_wrapper) self.state_list_view.addItem(widget_component) # add state component to application context self.context['entities'][entity]['components']['state'].append(state_component_wrapper) # fire event for adding component new_event = Event('added_component', entity=entity, component_type='state', component=state_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_graphic(self): # add the new graphic to the UI selected_asset = self.asset_list_view.currentItem() selected_component = selected_asset.component file_name = selected_component.component.file_name graphic_name = str(self.graphic_name_field.text()) selected_anchor = self.anchor_list_view.currentItem().component graphic_component = GraphicsComponent(entity_id=self.context.get('selected_entity'), surface=selected_component.component.surface, file_name=file_name, dest=selected_anchor) graphic_component_wrapper = Component(graphic_component, graphic_name) widget_component = WidgetItemComponent(graphic_name, graphic_component_wrapper) self.graphic_list_view.addItem(widget_component) # render it to the label image holder self.show_graphic(file_name) # then add it to the application context entity_name = self.context.get('selected_entity') if entity_name: self.context['entities'][entity_name]['components']['graphic'].append(graphic_component_wrapper) # fire off an event new_event = Event('graphic_added', graphic_component=graphic_component_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event('added_component', entity=entity_name, component_type='graphic', component=graphic_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def select_box(self): selected_item = self.box_list_view.currentItem() if selected_item: selected_component = selected_item.component box = selected_component.component # set field values hurtactive = 2 if box.hurtactive else 0 hitactive = 2 if box.hitactive else 0 blockactive = 2 if box.blockactive else 0 solid = 2 if box.solid else 0 self.box_x_field.setText(str(box.rect.x)) self.box_y_field.setText(str(box.rect.y)) self.box_width_field.setText(str(box.rect.w)) self.box_height_field.setText(str(box.rect.h)) self.box_hurtactive_check.setCheckState(hurtactive) self.box_hitactive_check.setCheckState(hitactive) self.box_blockactive_check.setCheckState(blockactive) self.box_solid_check.setCheckState(solid) # update drawn box in graphic viewer self.graphic_viewer.set_box(x=box.rect.x, y=box.rect.y, w=box.rect.w, h=box.rect.h) # fire event for selecting a box new_event = Event('selected_box', box_component=selected_component, entity=selected_component.component.entity_id) EVENT_MANAGER.fire_event(new_event)
def add_frame(self): frame_name = str(self.frame_name_field.text()) entity = self.context['selected_entity'] ani = self.selected_animation crop = Rect(int(self.frame_x_field.text()), int(self.frame_y_field.text()), int(self.frame_width_field.text()), int(self.frame_height_field.text())) repeat = int(self.frame_repeat_field.text()) frame_component = FrameComponent(entity_id=entity, crop=crop, repeat=repeat) frame_component_wrapper = Component(frame_component, frame_name) widget_component = WidgetItemComponent(frame_name, frame_component_wrapper) self.frame_list_view.addItem(widget_component) # add new frame component to the selected animation's frame list ani.component.frames.append(frame_component_wrapper) # fire event new_event = Event('added_component', entity=entity, component_type='frame', component=frame_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_binding(self): entity = self.context['selected_entity'] binding_name = str(self.binding_name_field.text()) # begin by building the bindings dictionary bindings = dict() mirrors = dict() for i in range(self.selected_inp_list_view.count()): input_comp = self.selected_inp_list_view.item(i).component key = input_comp.component.name.text bindings[key] = input_comp mirrors[key] = input_comp.component.mirror binding_comp = InputComponent(entity_id=entity, bindings=bindings, mirror_bindings=mirrors) binding_comp_wrapper = Component(binding_comp, binding_name) widget_component = WidgetItemComponent(binding_name, binding_comp_wrapper) self.binding_list_view.addItem(widget_component) # add the component to the application context self.context['entities'][entity]['components']['binding'].append(binding_comp_wrapper) # fire event for adding new binding new_event = Event('added_binding', binding_component=binding_comp_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event('added_component', entity=entity, component_type='binding', component=binding_comp_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_exec(self): entity = self.context['selected_entity'] exec_name = str(self.exec_name_field.text()) binding = self.binding_list_view.currentItem().component # build list of selected moves moves = list() for i in range(self.selected_move_list_view.count()): item = self.selected_move_list_view.item(i) move = item.component moves.append(move) exec_component = ExecutionComponent(entity_id=entity, executables=moves, inputs=binding) exec_component_wrapper = Component(exec_component, exec_name) widget_component = WidgetItemComponent(exec_name, exec_component_wrapper) self.exec_list_view.addItem(widget_component) # add execution component to the application context self.context['entities'][entity]['components']['execution'].append( exec_component_wrapper) # fire event for adding new execution new_event = Event('added_execution', execution_component=exec_component_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event('added_component', entity=entity, component_type='execution', component=exec_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def select_graphic(self): selected_item = self.graphic_list_view.currentItem() if not selected_item: return selected_component = selected_item.component name = selected_component.text anchor = selected_component.component.dest # set the name field self.graphic_name_field.setText(name) # this function gets called when a graphic is removed, # so we need to make sure there is actually a selected item if selected_item: file_name = selected_component.component.file_name self.show_graphic(file_name) # fire event for selecting a graphic new_event = Event('selected_graphic', graphic_component=selected_component, entity=selected_component.component.entity_id) EVENT_MANAGER.fire_event(new_event) anchor = selected_component.component.dest # select the proper anchor for i in xrange(self.anchor_list_view.count()): item = self.anchor_list_view.item(i) component = item.component if component == anchor: self.anchor_list_view.setCurrentRow(i) break
def select_frame(self): selected_item = self.frame_list_view.currentItem() if selected_item: selected_component = selected_item.component graphic = self.selected_animation.component.graphic.component file_name = graphic.file_name self.show_graphic(file_name) # set field values crop = selected_component.component.crop self.frame_x_field.setText(str(crop.x)) self.frame_y_field.setText(str(crop.y)) self.frame_width_field.setText(str(crop.w)) self.frame_height_field.setText(str(crop.h)) self.frame_repeat_field.setText( str(selected_component.component.repeat)) # update any drawn frame boxes self.graphic_viewer.set_rect(crop) # fire event for selecting a frame new_event = Event('selected_frame', frame_component=selected_component, entity=selected_component.component.entity_id, graphic_file_name=file_name) EVENT_MANAGER.fire_event(new_event)
def add_move(self): move_name = str(self.move_name_field.text()) entity = self.context['selected_entity'] selected_animation = self.ani_list_view.currentItem().component # build a list of the chosen inputs inputs = list() for i in range(self.selected_inp_list_view.count()): item = self.selected_inp_list_view.item(i) inp_component = item.component inputs.append(inp_component) # construct the move component move = MoveComponent(entity_id=entity, name=move_name, animation=selected_animation, inputs=inputs) move_component_wrapper = Component(move, move_name) widget_component = WidgetItemComponent(move_name, move_component_wrapper) self.move_list_view.addItem(widget_component) # add the move component to the application context self.context['entities'][entity]['components']['move'].append(move_component_wrapper) # fire event for adding new move new_event = Event('added_move', move_component=move_component_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event('added_component', entity=entity, component_type='move', component=move_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_exec(self): entity = self.context["selected_entity"] exec_name = str(self.exec_name_field.text()) binding = self.binding_list_view.currentItem().component # build list of selected moves moves = list() for i in range(self.selected_move_list_view.count()): item = self.selected_move_list_view.item(i) move = item.component moves.append(move) exec_component = ExecutionComponent(entity_id=entity, executables=moves, inputs=binding) exec_component_wrapper = Component(exec_component, exec_name) widget_component = WidgetItemComponent(exec_name, exec_component_wrapper) self.exec_list_view.addItem(widget_component) # add execution component to the application context self.context["entities"][entity]["components"]["execution"].append(exec_component_wrapper) # fire event for adding new execution new_event = Event("added_execution", execution_component=exec_component_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event( "added_component", entity=entity, component_type="execution", component=exec_component_wrapper ) EVENT_MANAGER.fire_event(new_event)
def remove_input(self): selected_index = self.input_list_view.currentRow() selected_input = self.input_list_view.takeItem(selected_index) # remove the input from the application context self.context["inputs"].remove(selected_input.component) # fire event for removing aninput new_event = Event("removed_input", input_component=selected_input.component) EVENT_MANAGER.fire_event(new_event)
def remove_input(self): selected_index = self.input_list_view.currentRow() selected_input = self.input_list_view.takeItem(selected_index) # remove the input from the application context self.context['inputs'].remove(selected_input.component) # fire event for removing aninput new_event = Event('removed_input', input_component=selected_input.component) EVENT_MANAGER.fire_event(new_event)
def remove_state(self): entity = self.context['selected_entity'] selected_index = self.state_list_view.currentRow() selected_item = self.state_list_view.takeItem(selected_index) # remove state component from application context self.context['entities'][entity]['components']['state'].remove(selected_item.component) # fire event for removing component new_event = Event('removed_component', entity=entity, component_type='state', component=selected_item.component) EVENT_MANAGER.fire_event(new_event)
def add_debug(self): entity = self.context['selected_entity'] name = self.debug_name_field.text() component_item = self.component_tree_view.currentItem() lambda_component = component_item.component color = self.color_list_view.currentItem().component location_vec = self.vector_list_view.currentItem().component inner_component = lambda_component.component.component #component_type = component_wrapper.__class__.__name__ attr = getattr(inner_component, lambda_component.attr).component component_type = attr.__class__.__name__ # create the debug component # extract the real component from a LambdaDef if component_type == 'BoxComponent': rect = getattr(inner_component, lambda_component.attr) debug_component = DebugComponent(entity_id=entity, rect=rect, style={'color': color}) else: lambda_name = lambda_component.attr text_lambda = TextLambdaDef(lambda_component, lambda_name, '{a}') text = str(getattr(lambda_component.component.component, lambda_name).component) text_comp = TextComponent(entity_id=entity, text=text, loc=location_vec, style={'color':color}) text_wrapper = Component(text_comp, text) # add this text component to the context self.context['entities'][entity]['components']['text'].append(text_wrapper) new_event = Event('added_component', entity=entity, component_type='text', component=text_wrapper) EVENT_MANAGER.fire_event(new_event) # finally create debug component debug_component = DebugComponent(entity_id=entity, text=text_wrapper, get_value=text_lambda, style={'color': color}) debug_wrapper = Component(debug_component, name) widget_item = WidgetItemComponent(name, debug_wrapper) self.debug_list_view.addItem(widget_item) # add to context self.context['entities'][entity]['components']['debug'].append(debug_wrapper) # fire event new_event = Event('added_component', entity=entity, component_type='debug', component=debug_wrapper) EVENT_MANAGER.fire_event(new_event)
def remove_asset(self): # remove the selectd graphic item from the UI selected_index = self.asset_list_view.currentRow() selected_item = self.asset_list_view.currentItem() self.asset_list_view.takeItem(selected_index) # then remove it from the application context self.context['assets'].remove(selected_item.component) # fire off an event new_event = Event('asset_removed', asset_component=selected_item.component) EVENT_MANAGER.fire_event(new_event)
def add_input(self): inp_name = str(self.input_name_field.text()) inp = Input(name=inp_name) inp_wrapper = Component(inp, inp_name) widget_component = WidgetItemComponent(inp_name, inp_wrapper) self.input_list_view.addItem(widget_component) # add input to the application context self.context['inputs'].append(inp_wrapper) # fire event for adding new input new_event = Event('added_input', input_component=inp_wrapper) EVENT_MANAGER.fire_event(new_event)
def add_input(self): inp_name = str(self.input_name_field.text()) inp = Input(name=inp_name) inp_wrapper = Component(inp, inp_name) widget_component = WidgetItemComponent(inp_name, inp_wrapper) self.input_list_view.addItem(widget_component) # add input to the application context self.context["inputs"].append(inp_wrapper) # fire event for adding new input new_event = Event("added_input", input_component=inp_wrapper) EVENT_MANAGER.fire_event(new_event)
def remove_exec(self): entity = self.context["selected_entity"] selected_index = self.exec_list_view.currentRow() selected_item = self.exec_list_view.takeItem(selected_index) selected_component = selected_item.component # remove execution component from the application context self.context["entities"][entity]["components"]["execution"].remove(selected_component) # fire event for removing execution new_event = Event("removed_execution", execution_component=selected_component) EVENT_MANAGER.fire_event(new_event) new_event = Event("removed_component", entity=entity, component_type="execution", component=selected_component) EVENT_MANAGER.fire_event(new_event)
def select_animation(self): selected_item = self.animation_list_view.currentItem() # this function gets called when an animation is removed, # so we need to make sure there is actually a selected item if selected_item: selected_component = selected_item.component file_name = selected_component.component.graphic.component.file_name self.show_graphic(file_name) # fire event for selecting an animation new_event = Event('selected_animation', animation_component=selected_component, entity=selected_component.component.entity_id) EVENT_MANAGER.fire_event(new_event)
def mousePressEvent(self, event): click_pos = event.pos() # translate the click position into scene coordinates click_pos = self.mapToScene(click_pos) self.dragging = True self.box_rect.x = click_pos.x() self.box_rect.y = click_pos.y() self.box_rect.w = 0 self.box_rect.h = 0 self.awkward_update() # fire event for updating box new_event = Event('updated_box', box=self.box_rect) EVENT_MANAGER.fire_event(new_event)
def mouseReleaseEvent(self, event): release_pos = event.pos() # translate the release position into scene coordinates release_pos = self.mapToScene(release_pos) self.dragging = False self.box_rect.w = release_pos.x() - self.box_rect.x self.box_rect.h = release_pos.y() - self.box_rect.y #self.box_rect.setWidth(release_pos.x() - self.box_rect.x()) #self.box_rect.setHeight(release_pos.y() - self.box_rect.y()) self.awkward_update() # fire event for updating box new_event = Event('updated_box', box=self.box_rect) EVENT_MANAGER.fire_event(new_event)
def mouseMoveEvent(self, event): drag_pos = event.pos() if self.dragging: # traslate the drag position into scene coordinates drag_pos = self.mapToScene(drag_pos) self.box_rect.w = drag_pos.x() - self.box_rect.x self.box_rect.h = drag_pos.y() - self.box_rect.y #self.box_rect.setWidth(drag_pos.x() - self.box_rect.x()) #self.box_rect.setHeight(drag_pos.y() - self.box_rect.y()) self.awkward_update() # fire event for updating frame box new_event = Event('updated_box', box=self.box_rect) EVENT_MANAGER.fire_event(new_event)
def remove_vector(self): entity = self.context['selected_entity'] selected_index = self.vector_list_view.currentRow() selected_item = self.vector_list_view.takeItem(selected_index) selected_component = selected_item.component self.context['entities'][entity]['components']['vector'].remove(selected_component) new_event = Event('removed_component', entity=entity, component_type='vector', component=selected_component) EVENT_MANAGER.fire_event(new_event) new_event = Event('vector_removed', vector_component=selected_component) EVENT_MANAGER.fire_event(new_event)
def remove_frame(self): entity = self.context['selected_entity'] selected_index = self.frame_list_view.currentRow() selected_frame = self.frame_list_view.takeItem(selected_index) # remove the frame from its parent animation frame_component = selected_frame.component self.selected_animation.component.frames.remove(frame_component) # fire event new_event = Event('removed_component', entity=entity, component_type='frame', component=frame_component) EVENT_MANAGER.fire_event(new_event)
def remove_rule(self): selected_index = self.rule_list_view.currentRow() selected_item = self.rule_list_view.takeItem(selected_index) selected_component = selected_item.component # remove rule from application context for comp in self.context['rules']: if comp == selected_component: self.context['rules'].remove(comp) break # fire event for removing rule new_event = Event('removed_rule', rule_component=selected_component) EVENT_MANAGER.fire_event(new_event)
def mouseReleaseEvent(self, event): release_pos = event.pos() # translate the release position into scene coordinates release_pos = self.mapToScene(release_pos) self.dragging = False self.frame_rect.w = release_pos.x() - self.frame_rect.x self.frame_rect.h = release_pos.y() - self.frame_rect.y #self.frame_rect.setWidth(release_pos.x() - self.frame_rect.x()) #self.frame_rect.setHeight(release_pos.y() - self.frame_rect.y()) self.awkward_update() # fire event for updating frame crop new_event = Event('updated_frame_crop', crop=self.frame_rect) EVENT_MANAGER.fire_event(new_event)
def mouseMoveEvent(self, event): drag_pos = event.pos() if self.dragging: # traslate the drag position into scene coordinates drag_pos = self.mapToScene(drag_pos) self.frame_rect.w = drag_pos.x() - self.frame_rect.x self.frame_rect.h = drag_pos.y() - self.frame_rect.y #self.frame_rect.setWidth(drag_pos.x() - self.frame_rect.x()) #self.frame_rect.setHeight(drag_pos.y() - self.frame_rect.y()) self.awkward_update() # fire event for updating frame crop new_event = Event('updated_frame_crop', crop=self.frame_rect) EVENT_MANAGER.fire_event(new_event)
def remove_movement(self): entity = self.context['selected_entity'] selected_index = self.movement_list_view.currentRow() selected_item = self.movement_list_view.takeItem(selected_index) selected_component = selected_item.component # remove from context self.context['entities'][entity]['components']['movement'].remove(selected_component) # fire event new_event = Event('removed_component', entity=entity, component_type='movement', component=selected_component) EVENT_MANAGER.fire_event(new_event)
def remove_physics(self): selected_index = self.physics_list_view.currentRow() selected_item = self.physics_list_view.takeItem(selected_index) selected_component = selected_item.component self.context['entities'][self.entity]['components']['physics'].remove(selected_component) new_event = Event('removed_component', entity=self.entity, component_type='physics', component=selected_component) EVENT_MANAGER.fire_event(new_event) new_event = Event('physics_removed', physics_component=selected_component) EVENT_MANAGER.fire_event(new_event) # remove any hitboxes and concomitant components box = selected_component.component.body self.context['entities'][self.entity]['components']['hitbox'].remove(box)
def remove_box(self): entity = self.context['selected_entity'] selected_index = self.box_list_view.currentRow() selected_box = self.box_list_view.takeItem(selected_index) # remove the box from its parent frame self.selected_frame.component.hitboxes.remove(selected_box.component) # remove box from context self.context['entities'][entity]['components']['hitbox'].remove(selected_box.component) # fire event new_event = Event('removed_component', entity=entity, component_type='hitbox', component=selected_box.component) EVENT_MANAGER.fire_event(new_event)
def remove_binding(self): entity = self.context['selected_entity'] selected_index = self.binding_list_view.currentRow() selected_item = self.binding_list_view.takeItem(selected_index) selected_component = selected_item.component # remove the component from the application context self.context['entities'][entity]['components']['binding'].remove(selected_component) # fire event for removing binding new_event = Event('removed_binding', binding_component=selected_component) EVENT_MANAGER.fire_event(new_event) new_event = Event('removed_component', entity=entity, component_type='binding', component=selected_component) EVENT_MANAGER.fire_event(new_event)
def remove_physics(self): selected_index = self.physics_list_view.currentRow() selected_item = self.physics_list_view.takeItem(selected_index) selected_component = selected_item.component self.context['entities'][self.entity]['components']['physics'].remove( selected_component) new_event = Event('removed_component', entity=self.entity, component_type='physics', component=selected_component) EVENT_MANAGER.fire_event(new_event) new_event = Event('physics_removed', physics_component=selected_component) EVENT_MANAGER.fire_event(new_event) # remove any hitboxes and concomitant components box = selected_component.component.body self.context['entities'][self.entity]['components']['hitbox'].remove( box)
def remove_box(self): entity = self.context['selected_entity'] selected_index = self.box_list_view.currentRow() selected_box = self.box_list_view.takeItem(selected_index) # remove the box from its parent frame self.selected_frame.component.hitboxes.remove(selected_box.component) # remove box from context self.context['entities'][entity]['components']['hitbox'].remove( selected_box.component) # fire event new_event = Event('removed_component', entity=entity, component_type='hitbox', component=selected_box.component) EVENT_MANAGER.fire_event(new_event)
def add_vector(self): entity = self.context['selected_entity'] x = float(self.x_field.text()) y = float(self.y_field.text()) name = str(self.vector_name_field.text()) vector = Vector2(entity, [x, y]) vector_wrapper = Component(vector, name) widget_component = WidgetItemComponent(vector_wrapper.text, vector_wrapper) self.vector_list_view.addItem(widget_component) self.context['entities'][entity]['components']['vector'].append(vector_wrapper) new_event = Event('added_component', entity=entity, component_type='vector', component=vector_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event('vector_added', vector_component=vector_wrapper) EVENT_MANAGER.fire_event(new_event)
def remove_exec(self): entity = self.context['selected_entity'] selected_index = self.exec_list_view.currentRow() selected_item = self.exec_list_view.takeItem(selected_index) selected_component = selected_item.component # remove execution component from the application context self.context['entities'][entity]['components']['execution'].remove( selected_component) # fire event for removing execution new_event = Event('removed_execution', execution_component=selected_component) EVENT_MANAGER.fire_event(new_event) new_event = Event('removed_component', entity=entity, component_type='execution', component=selected_component) EVENT_MANAGER.fire_event(new_event)
def remove_binding(self): entity = self.context['selected_entity'] selected_index = self.binding_list_view.currentRow() selected_item = self.binding_list_view.takeItem(selected_index) selected_component = selected_item.component # remove the component from the application context self.context['entities'][entity]['components']['binding'].remove( selected_component) # fire event for removing binding new_event = Event('removed_binding', binding_component=selected_component) EVENT_MANAGER.fire_event(new_event) new_event = Event('removed_component', entity=entity, component_type='binding', component=selected_component) EVENT_MANAGER.fire_event(new_event)
def mousePressEvent(self, event): click_pos = event.pos() # translate the click position into scene coordinates click_pos = self.mapToScene(click_pos) self.dragging = True self.frame_rect.x = click_pos.x() self.frame_rect.y = click_pos.y() self.frame_rect.w = 0 self.frame_rect.h = 0 #self.frame_rect.setX(click_pos.x()) #self.frame_rect.setY(click_pos.y()) #self.frame_rect.setWidth(0) #self.frame_rect.setHeight(0) self.update() self.repaint() # fire event for updating frame crop new_event = Event('updated_frame_crop', crop=self.frame_rect) EVENT_MANAGER.fire_event(new_event)
def remove_graphic(self): # remove the selectd graphic item from the UI selected_index = self.graphic_list_view.currentRow() selected_item = self.graphic_list_view.currentItem() self.graphic_list_view.takeItem(selected_index) # then remove it from the application context entity = self.context.get('selected_entity') if entity: self.context['entities'][entity]['components']['graphic'].remove(selected_item.component) # fire off an event new_event = Event('graphic_removed', graphic_component=graphic_component_wrapper) EVENT_MANAGER.fire_event(new_event) new_event = Event('removed_component', entity=entity, component_type='graphic', component=graphic_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def remove_animation(self): entity = self.context['selected_entity'] selected_index = self.animation_list_view.currentRow() selected_animation = self.animation_list_view.takeItem(selected_index) self.animation_list_view.takeItem(selected_index) # remove the animation from the application context inner_ani_component = selected_animation.component self.context['entities'][entity]['components']['animation'].remove( inner_ani_component) # fire event for removing an animation new_event = Event('removed_animation', animation_component=inner_ani_component, entity=inner_ani_component.component.entity_id) EVENT_MANAGER.fire_event(new_event) new_event = Event('removed_component', entity=entity, component_type='animation', component=animation_component_wrapper) EVENT_MANAGER.fire_event(new_event)
def remove_debug(self): entity = self.context['selected_entity'] selected_row = self.debug_list_view.currentRow() selected_item = self.debug_list_view.currentItem() selected_component = selected_item.component # first remove from debug list self.debug_list_view.takeItem(selected_row) # then remove from context debug_comps = self.context['entities'][entity]['components']['debug'] for debug_comp in debug_comps: if debug_comp == selected_component: debug_comps.remove(debug_comp) # fire event new_event = Event('removed_component', entity=entity, component_type='debug', component=selected_component) EVENT_MANAGER.fire_event(new_event)