예제 #1
0
def delete_particle(particle):

    if particle is None:
        return

    particle.mfd = True
    Logger.log_custom("control", "Deleting particle.")
예제 #2
0
def set_global_particle_velocity(sim, v):

    for e in sim.entities:
        try:
            e.velocity = [v, v]
        except AttributeError:
            Logger.log_warning("Can't set velocity of entity {}".format(e))
    Logger.log_custom("control",
                      "Set global particle velocity to {}.".format(v))
예제 #3
0
def set_global_particle_radius(sim, r):
    """ Sets all PrimordialParticle's radii. Note: This is rather costly """

    for e in sim.entities:
        try:
            e.radius = r
        except AttributeError:
            Logger.log_warning("Can't set radius of entity: {}".format(e))
    Logger.log_custom("control", "Set global particle radius to {}.".format(r))
예제 #4
0
def toggle_pause(target):

    target.paused = (not target.paused)

    log_msg = str(type(target))
    if target.paused:
        log_msg += " paused."
    else:
        log_msg += " unpaused."
    Logger.log_custom("control", log_msg)
예제 #5
0
    def on_key_press(self, symbol, modifiers):
        # Handle key press

        # Mode switch
        if symbol in [key.M]:
            self.mode = ModeEnum((self.mode.value + 1) % len(list(ModeEnum)))
            Logger.log_custom("control",
                              "Changed mode to {}.".format(self.mode))

        if self.mode == ModeEnum.SELECT:

            if symbol == key.P:
                if self._cur_selected is None:
                    controls.toggle_pause(self.sim)
                else:
                    controls.toggle_pause(self._cur_selected)

            if symbol in [key.UP, key.DOWN
                          ] and modifiers == 18:  # 16 (base) + 2 (ctrl)
                controls.set_tick_speed(self, symbol)

            if symbol == key.H:
                if self._cur_selected is None:
                    self._ui.visible = not self._ui.visible
                else:
                    controls.toggle_debug_view(self._cur_selected)

            if symbol == key.T:
                if self._cur_selected is not None:
                    controls.toggle_trail(self._cur_selected)

            if symbol == key.SPACE:
                if self._cur_selected is not None:
                    controls.toggle_particle_movable(self._cur_selected)

            if symbol == key.S and modifiers == 18:  # CRTL+S
                Logger.log_custom("control", "Saving current state...")
                persistence.save_to_json(self.sim)
                Logger.log_custom("control", "Finished saving.")

            if symbol == key.L and modifiers == 18:  # CRTL+L
                Logger.log_custom("control", "Loading state...")
                persistence.load_from_json(self.sim)
                Logger.log_custom("control", "Finished loading.")

        if self.mode == ModeEnum.DESTROY:

            if symbol == key.BACKSPACE:
                controls.delete_particle(self._cur_selected)
                self._cur_selected = None

        if self.mode == ModeEnum.CREATE:

            # Cycling creatable types
            if symbol == key.LEFT:
                self.cur_creation_index = (self.cur_creation_index + 1) % len(
                    self.creatable_types)
                Logger.log_custom(
                    "control", "Changed creation type to {}.".format(
                        self.creatable_types[self.cur_creation_index]))
            if symbol == key.RIGHT:
                self.cur_creation_index = ((self.cur_creation_index - 1) %
                                           len(self.creatable_types))
                Logger.log_custom(
                    "control", "Changed creation type to {}.".format(
                        self.creatable_types[self.cur_creation_index]))