Search in sources :

Example 1 with InputVirtual

use of io.xol.chunkstories.input.InputVirtual in project chunkstories by Hugobros3.

the class PacketInput method process.

public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException {
    long code = in.readLong();
    boolean pressed = in.readBoolean();
    if (processor instanceof ServerPlayerPacketsProcessor) {
        ServerPlayerPacketsProcessor sppc = (ServerPlayerPacketsProcessor) processor;
        // Look for the controller handling this buisness
        EntityControllable entity = (EntityControllable) sppc.getPlayer().getControlledEntity();
        if (entity != null) {
            // Get input of the client
            input = sppc.getPlayer().getInputsManager().getInputFromHash(code);
            if (input == null)
                throw new NullPointerException("Unknown input hash : " + code);
            // System.out.println(processor.getServerClient().getProfile() +
            // " "+input + " "+pressed);
            // Update it's state
            ((InputVirtual) input).setPressed(pressed);
            // Fire appropriate event
            if (pressed) {
                PlayerInputPressedEvent event = new PlayerInputPressedEvent(sppc.getPlayer(), input);
                entity.getWorld().getGameLogic().getPluginsManager().fireEvent(event);
                if (!event.isCancelled())
                    entity.onControllerInput(input, entity.getControllerComponent().getController());
            } else {
                PlayerInputReleasedEvent event = new PlayerInputReleasedEvent(sppc.getPlayer(), input);
                entity.getWorld().getGameLogic().getPluginsManager().fireEvent(event);
            }
        // TODO why is this disabled and still there ?
        // If we pressed the input, apply game logic
        // if(pressed)
        // entity.handleInteraction(input,
        // entity.getControllerComponent().getController());
        }
    }
}
Also used : PlayerInputReleasedEvent(io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent) ServerPlayerPacketsProcessor(io.xol.chunkstories.api.server.ServerPacketsProcessor.ServerPlayerPacketsProcessor) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) PlayerInputPressedEvent(io.xol.chunkstories.api.events.player.PlayerInputPressedEvent) InputVirtual(io.xol.chunkstories.input.InputVirtual)

Example 2 with InputVirtual

use of io.xol.chunkstories.input.InputVirtual in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method insertInput.

public void insertInput(String type, String name, String value, Collection<String> arguments) {
    Input input;
    if (type.equals("keyBind")) {
        Lwjgl3KeyBind key = new Lwjgl3KeyBind(this, name, value);
        input = key;
        if (arguments.contains("hidden"))
            key.editable = false;
        if (arguments.contains("repeat"))
            key.repeat = true;
    // keyboardInputs.add(key);
    } else if (type.equals("virtual")) {
        input = new InputVirtual(name);
    } else if (type.equals("keyBindCompound")) {
        Lwjgl3KeyBindCompound keyCompound = new Lwjgl3KeyBindCompound(this, name, value);
        input = keyCompound;
    } else
        return;
    inputs.add(input);
    inputsMap.put(input.getHash(), input);
}
Also used : PacketInput(io.xol.chunkstories.net.packets.PacketInput) Input(io.xol.chunkstories.api.input.Input) InputVirtual(io.xol.chunkstories.input.InputVirtual)

Example 3 with InputVirtual

use of io.xol.chunkstories.input.InputVirtual in project chunkstories by Hugobros3.

the class ServerInputsManager method insertInput.

public void insertInput(String type, String name, String value, Collection<String> arguments) {
    Input input;
    // 2deep4me
    if (type.equals("keyBind") || type.equals("virtual")) {
        input = new InputVirtual(name);
    } else
        return;
    inputs.add(input);
    inputsMap.put(input.getHash(), input);
}
Also used : Input(io.xol.chunkstories.api.input.Input) InputVirtual(io.xol.chunkstories.input.InputVirtual)

Example 4 with InputVirtual

use of io.xol.chunkstories.input.InputVirtual in project chunkstories by Hugobros3.

the class ServerInputsManager method reload.

public void reload() {
    inputs.clear();
    inputsMap.clear();
    // Load all keys as virtual ones
    InputsLoaderHelper.loadKeyBindsIntoManager(this, player.getContext().getContent().modsManager());
    // Add virtual mouse buttons
    InputVirtual mouseLeft = new InputVirtual("mouse.left", 0);
    inputs.add(mouseLeft);
    inputsMap.put(mouseLeft.getHash(), mouseLeft);
    InputVirtual mouseRight = new InputVirtual("mouse.right", 1);
    inputs.add(mouseRight);
    inputsMap.put(mouseRight.getHash(), mouseRight);
    InputVirtual mouseMiddle = new InputVirtual("mouse.middle", 2);
    inputs.add(mouseMiddle);
    inputsMap.put(mouseMiddle.getHash(), mouseMiddle);
}
Also used : InputVirtual(io.xol.chunkstories.input.InputVirtual)

Aggregations

InputVirtual (io.xol.chunkstories.input.InputVirtual)4 Input (io.xol.chunkstories.api.input.Input)2 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)1 PlayerInputPressedEvent (io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)1 PlayerInputReleasedEvent (io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent)1 ServerPlayerPacketsProcessor (io.xol.chunkstories.api.server.ServerPacketsProcessor.ServerPlayerPacketsProcessor)1 PacketInput (io.xol.chunkstories.net.packets.PacketInput)1