Annotation processing done, more work on local multiplayer input
This commit is contained in:
@@ -2,15 +2,11 @@ package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.content.Weapons;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.Tutorial;
|
||||
import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.input.DefaultKeybinds;
|
||||
import io.anuke.mindustry.input.DesktopInput;
|
||||
@@ -20,12 +16,10 @@ import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.io.Saves;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.input.InputProxy;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -271,6 +265,8 @@ public class Control extends Module{
|
||||
|
||||
saves.update();
|
||||
|
||||
triggerUpdateInput();
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
for(InputHandler input : inputs){
|
||||
input.update();
|
||||
|
||||
@@ -150,15 +150,10 @@ public class NetClient extends Module {
|
||||
});
|
||||
|
||||
Net.handleClient(InvokePacket.class, packet -> {
|
||||
try{
|
||||
packet.method.invoke(null, packet.args);
|
||||
}catch (ReflectionException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//TODO invoke it
|
||||
});
|
||||
|
||||
Net.handleClient(StateSyncPacket.class, packet -> {
|
||||
|
||||
System.arraycopy(packet.items, 0, state.inventory.writeItems(), 0, packet.items.length);
|
||||
|
||||
state.enemies = packet.enemies;
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.gen.CallEvent;
|
||||
import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.*;
|
||||
|
||||
@@ -28,7 +28,7 @@ import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.layout.Stack;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Input;
|
||||
import io.anuke.ucore.input.Input;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Input;
|
||||
import io.anuke.ucore.input.Input;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
|
||||
@@ -5,70 +5,64 @@ import com.badlogic.gdx.Gdx;
|
||||
import io.anuke.ucore.core.Inputs.Axis;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.core.KeyBinds;
|
||||
import io.anuke.ucore.util.Input;
|
||||
import io.anuke.ucore.core.KeyBinds.Category;
|
||||
import io.anuke.ucore.input.Input;
|
||||
|
||||
public class DefaultKeybinds {
|
||||
|
||||
public static void load(){
|
||||
KeyBinds.defaults(
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
"select", Input.MOUSE_LEFT,
|
||||
"break", Input.MOUSE_RIGHT,
|
||||
"shoot", Input.MOUSE_LEFT,
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"dash", Input.SHIFT_LEFT,
|
||||
"rotate_alt", new Axis(Input.R, Input.E),
|
||||
"rotate", new Axis(Input.SCROLL),
|
||||
"toggle_menus", Input.C,
|
||||
"block_info", Input.CONTROL_LEFT,
|
||||
"player_list", Input.TAB,
|
||||
"item_withdraw", Input.SHIFT_LEFT,
|
||||
"chat", Input.ENTER,
|
||||
"chat_history_prev", Input.UP,
|
||||
"chat_history_next", Input.DOWN,
|
||||
"chat_scroll", new Axis(Input.SCROLL),
|
||||
"console", Input.GRAVE,
|
||||
"weapon_1", Input.NUM_1,
|
||||
"weapon_2", Input.NUM_2,
|
||||
"weapon_3", Input.NUM_3,
|
||||
"weapon_4", Input.NUM_4,
|
||||
"weapon_5", Input.NUM_5,
|
||||
"weapon_6", Input.NUM_6
|
||||
);
|
||||
String[] sections = {"player_1", "player_2", "player_3", "player_4"};
|
||||
|
||||
KeyBinds.defaults(
|
||||
DeviceType.controller,
|
||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||
"select", Input.CONTROLLER_R_BUMPER,
|
||||
"break", Input.CONTROLLER_L_BUMPER,
|
||||
"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
||||
"dash", Input.CONTROLLER_Y,
|
||||
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
|
||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||
"player_list", Input.CONTROLLER_START,
|
||||
"chat", Input.ENTER,
|
||||
"chat_history_prev", Input.UP,
|
||||
"chat_history_next", Input.DOWN,
|
||||
"chat_scroll", new Axis(Input.SCROLL),
|
||||
"console", Input.GRAVE,
|
||||
"weapon_1", Input.NUM_1,
|
||||
"weapon_2", Input.NUM_2,
|
||||
"weapon_3", Input.NUM_3,
|
||||
"weapon_4", Input.NUM_4,
|
||||
"weapon_5", Input.NUM_5,
|
||||
"weapon_6", Input.NUM_6
|
||||
);
|
||||
for(String section : sections) {
|
||||
|
||||
KeyBinds.defaultSection(section, DeviceType.keyboard,
|
||||
new Category("General"),
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
"select", Input.MOUSE_LEFT,
|
||||
"break", Input.MOUSE_RIGHT,
|
||||
"shoot", Input.MOUSE_LEFT,
|
||||
"rotate_alt", new Axis(Input.R, Input.E),
|
||||
"rotate", new Axis(Input.SCROLL),
|
||||
"dash", Input.SHIFT_LEFT,
|
||||
new Category("View"),
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"toggle_menus", Input.C,
|
||||
"block_info", Input.CONTROL_LEFT,
|
||||
"item_withdraw", Input.SHIFT_LEFT,
|
||||
new Category("Multiplayer"),
|
||||
"player_list", Input.TAB,
|
||||
"chat", Input.ENTER,
|
||||
"chat_history_prev", Input.UP,
|
||||
"chat_history_next", Input.DOWN,
|
||||
"chat_scroll", new Axis(Input.SCROLL),
|
||||
"console", Input.GRAVE
|
||||
);
|
||||
|
||||
KeyBinds.defaultSection(section, DeviceType.controller,
|
||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||
"select", Input.CONTROLLER_R_BUMPER,
|
||||
"break", Input.CONTROLLER_L_BUMPER,
|
||||
"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
||||
"dash", Input.CONTROLLER_Y,
|
||||
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
|
||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||
"player_list", Input.CONTROLLER_START
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
KeyBinds.setSectionAlias("default", "player_1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,13 @@ public class DesktopInput extends InputHandler{
|
||||
private boolean enableHold = false;
|
||||
private boolean beganBreak;
|
||||
private boolean controlling;
|
||||
private final int index;
|
||||
private final String section;
|
||||
|
||||
public DesktopInput(Player player){
|
||||
super(player);
|
||||
this.index = player.playerIndex;
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
}
|
||||
|
||||
@Override public float getCursorEndX(){ return endx; }
|
||||
@@ -42,21 +46,21 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(player.isDead()) return;
|
||||
|
||||
if(Inputs.keyRelease("select")){
|
||||
if(Inputs.keyRelease(section, "select")){
|
||||
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("break") && !beganBreak){
|
||||
if(Inputs.keyRelease(section, "break") && !beganBreak){
|
||||
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown("select")){
|
||||
if(!Inputs.keyDown(section, "select")){
|
||||
shooting = false;
|
||||
}
|
||||
|
||||
boolean canBeginShoot = Inputs.keyTap("select") && canShoot();
|
||||
boolean canBeginShoot = Inputs.keyTap(section, "select") && canShoot();
|
||||
|
||||
if(Inputs.keyTap("select") && recipe == null && player.inventory.hasItem()){
|
||||
if(Inputs.keyTap(section, "select") && recipe == null && player.inventory.hasItem()){
|
||||
Vector2 vec = Graphics.screen(player.x, player.y);
|
||||
if(vec.dst(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()) <= playerSelectRange){
|
||||
canBeginShoot = false;
|
||||
@@ -64,13 +68,13 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}
|
||||
|
||||
if((Inputs.keyTap("select") && recipe != null) || Inputs.keyTap("break")){
|
||||
if((Inputs.keyTap(section, "select") && recipe != null) || Inputs.keyTap(section, "break")){
|
||||
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
|
||||
mousex = vec.x;
|
||||
mousey = vec.y;
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown("select") && !Inputs.keyDown("break")){
|
||||
if(!Inputs.keyDown(section, "select") && !Inputs.keyDown(section, "break")){
|
||||
mousex = Graphics.mouseWorld().x;
|
||||
mousey = Graphics.mouseWorld().y;
|
||||
}
|
||||
@@ -78,21 +82,21 @@ public class DesktopInput extends InputHandler{
|
||||
endx = Gdx.input.getX();
|
||||
endy = Gdx.input.getY();
|
||||
|
||||
boolean controller = KeyBinds.getSection("default").device.type == DeviceType.controller;
|
||||
boolean controller = KeyBinds.getSection(section).device.type == DeviceType.controller;
|
||||
|
||||
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown("zoom_hold") || controller)
|
||||
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown(section,"zoom_hold") || controller)
|
||||
&& !state.is(State.menu) && !ui.hasDialog()){
|
||||
renderer.scaleCamera((int) Inputs.getAxisTapped("zoom"));
|
||||
renderer.scaleCamera((int) Inputs.getAxisTapped(section, "zoom"));
|
||||
}
|
||||
|
||||
renderer.minimap().zoomBy(-(int)Inputs.getAxisTapped("zoom_minimap"));
|
||||
renderer.minimap().zoomBy(-(int)Inputs.getAxisTapped(section,"zoom_minimap"));
|
||||
|
||||
rotation += Inputs.getAxisTapped("rotate_alt");
|
||||
rotation += Inputs.getAxis("rotate");
|
||||
rotation += Inputs.getAxisTapped(section,"rotate_alt");
|
||||
rotation += Inputs.getAxis(section,"rotate");
|
||||
|
||||
rotation = Mathf.mod(rotation, 4);
|
||||
|
||||
if(Inputs.keyDown("break")){
|
||||
if(Inputs.keyDown(section,"break")){
|
||||
breakMode = PlaceMode.areaDelete;
|
||||
}else{
|
||||
breakMode = PlaceMode.hold;
|
||||
@@ -117,24 +121,24 @@ public class DesktopInput extends InputHandler{
|
||||
Tile target = cursor == null ? null : cursor.target();
|
||||
boolean showCursor = false;
|
||||
|
||||
if(droppingItem && Inputs.keyRelease("select") && !player.inventory.isEmpty() && target != null){
|
||||
if(droppingItem && Inputs.keyRelease(section,"select") && !player.inventory.isEmpty() && target != null){
|
||||
dropItem(target, player.inventory.getItem());
|
||||
}
|
||||
|
||||
if(droppingItem && (!Inputs.keyDown("select") || player.inventory.isEmpty())){
|
||||
if(droppingItem && (!Inputs.keyDown(section,"select") || player.inventory.isEmpty())){
|
||||
droppingItem = false;
|
||||
}
|
||||
|
||||
if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info") && target.block().isAccessible()){
|
||||
if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown(section,"block_info") && target.block().isAccessible()){
|
||||
showCursor = true;
|
||||
if(Inputs.keyTap("select")){
|
||||
if(Inputs.keyTap(section,"select")){
|
||||
canBeginShoot = false;
|
||||
frag.inv.showFor(target);
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap("select")){
|
||||
if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap(section,"select")){
|
||||
frag.inv.hide();
|
||||
}
|
||||
|
||||
@@ -142,7 +146,7 @@ public class DesktopInput extends InputHandler{
|
||||
showCursor = true;
|
||||
}
|
||||
|
||||
if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){
|
||||
if(target != null && Inputs.keyTap(section,"select") && !ui.hasMouse()){
|
||||
if(target.block().isConfigurable(target)){
|
||||
if((!frag.config.isShown()
|
||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor))) {
|
||||
@@ -160,21 +164,21 @@ public class DesktopInput extends InputHandler{
|
||||
if(Net.active()) NetEvents.handleBlockTap(target);
|
||||
}
|
||||
|
||||
if(Inputs.keyTap("break")){
|
||||
if(Inputs.keyTap(section,"break")){
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("break")){
|
||||
if(Inputs.keyRelease(section,"break")){
|
||||
beganBreak = false;
|
||||
}
|
||||
|
||||
if(recipe != null && Inputs.keyTap("break")){
|
||||
if(recipe != null && Inputs.keyTap(section,"break")){
|
||||
beganBreak = true;
|
||||
recipe = null;
|
||||
}
|
||||
|
||||
//block breaking
|
||||
if(enableHold && Inputs.keyDown("break") && cursor != null && validBreak(tilex(), tiley())){
|
||||
if(enableHold && Inputs.keyDown(section,"break") && cursor != null && validBreak(tilex(), tiley())){
|
||||
breaktime += Timers.delta();
|
||||
if(breaktime >= cursor.getBreakTime()){
|
||||
breakBlock(cursor.x, cursor.y, true);
|
||||
@@ -199,7 +203,6 @@ public class DesktopInput extends InputHandler{
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,17 +223,21 @@ public class DesktopInput extends InputHandler{
|
||||
void updateController(){
|
||||
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
||||
|
||||
if(KeyBinds.getSection("default").device.type == DeviceType.controller && !mousemove){
|
||||
if(Inputs.keyTap("select")){
|
||||
if(KeyBinds.getSection(section).device.type == DeviceType.controller && (!mousemove || player.playerIndex > 0)){
|
||||
if(player.playerIndex > 0){
|
||||
controlling = true;
|
||||
}
|
||||
|
||||
if(Inputs.keyTap(section,"select")){
|
||||
Inputs.getProcessor().touchDown(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("select")){
|
||||
if(Inputs.keyRelease(section,"select")){
|
||||
Inputs.getProcessor().touchUp(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
||||
}
|
||||
|
||||
float xa = Inputs.getAxis("cursor_x");
|
||||
float ya = Inputs.getAxis("cursor_y");
|
||||
float xa = Inputs.getAxis(section, "cursor_x");
|
||||
float ya = Inputs.getAxis(section, "cursor_y");
|
||||
|
||||
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
|
||||
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.Method;
|
||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.annotations.Annotations.Local;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
@@ -39,10 +41,7 @@ public class Invoke {
|
||||
method.invoke(null, args);
|
||||
}
|
||||
InvokePacket packet = new InvokePacket();
|
||||
packet.args = args;
|
||||
packet.type = type;
|
||||
packet.method = method;
|
||||
packet.args = args;
|
||||
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}catch (ReflectionException e){
|
||||
throw new RuntimeException(e);
|
||||
@@ -170,12 +169,5 @@ public class Invoke {
|
||||
|
||||
}
|
||||
|
||||
/**Marks a method as invokable remotely with {@link Invoke#on(Class, String, Object...)}*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Remote{}
|
||||
|
||||
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Local{}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.Method;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.annotations.Annotations.Local;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.net.Invoke.Local;
|
||||
import io.anuke.mindustry.net.Invoke.Remote;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.gen.CallEvent;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class NetEvents {
|
||||
|
||||
@Remote
|
||||
@Local
|
||||
public static void friendlyFireChange(boolean enabled){
|
||||
state.friendlyFire = enabled;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.gen.CallEvent;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||
@@ -33,28 +34,28 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class InvokePacket implements Packet{
|
||||
public Object[] args;
|
||||
public Method method;
|
||||
public Class type;
|
||||
public byte type;
|
||||
|
||||
public ByteBuffer writeBuffer;
|
||||
public int writeLength;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
IOUtils.writeString(buffer, method.getName());
|
||||
IOUtils.writeString(buffer, type.getName());
|
||||
Invoke.writeObjects(buffer, args);
|
||||
type = buffer.get();
|
||||
|
||||
if(Net.client()){
|
||||
CallEvent.readPacket(buffer, type);
|
||||
}else{
|
||||
buffer.position(buffer.position() + writeLength);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
String methodname = IOUtils.readString(buffer);
|
||||
String typename = IOUtils.readString(buffer);
|
||||
|
||||
try {
|
||||
type = Invoke.findClass(typename);
|
||||
method = Invoke.getMethod(type, methodname);
|
||||
args = Invoke.readObjects(buffer, method.getParameterTypes());
|
||||
}catch (ReflectionException e){
|
||||
throw new RuntimeException(e);
|
||||
buffer.put(type);
|
||||
writeBuffer.position(0);
|
||||
for(int i = 0; i < writeLength; i ++){
|
||||
buffer.put(writeBuffer.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user