Annotation processing done, more work on local multiplayer input
This commit is contained in:
Binary file not shown.
@@ -1,23 +1,47 @@
|
|||||||
package io.anuke.annotations;
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import com.squareup.javapoet.*;
|
||||||
|
import io.anuke.annotations.Annotations.Local;
|
||||||
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
|
|
||||||
import javax.annotation.processing.*;
|
import javax.annotation.processing.*;
|
||||||
import javax.lang.model.SourceVersion;
|
import javax.lang.model.SourceVersion;
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.*;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.lang.model.util.Elements;
|
import javax.lang.model.util.Elements;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||||
@SupportedAnnotationTypes({
|
@SupportedAnnotationTypes({
|
||||||
"java.lang.Override"
|
"io.anuke.annotations.Annotations.Remote",
|
||||||
|
"io.anuke.annotations.Annotations.Local"
|
||||||
})
|
})
|
||||||
public class AnnotationProcessor extends AbstractProcessor {
|
public class AnnotationProcessor extends AbstractProcessor {
|
||||||
|
private static final int maxPacketSize = 128;
|
||||||
|
private static final String fullClassName = "io.anuke.mindustry.gen.CallEvent";
|
||||||
|
private static final String className = fullClassName.substring(1 + fullClassName.lastIndexOf('.'));
|
||||||
|
private static final String packageName = fullClassName.substring(0, fullClassName.lastIndexOf('.'));
|
||||||
|
private static final HashMap<String, String[][]> writeMap = new HashMap<String, String[][]>(){{
|
||||||
|
put("Player", new String[][]{
|
||||||
|
{
|
||||||
|
"rbuffer.putInt(rvalue.id)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rtype rvalue = io.anuke.mindustry.Vars.playerGroup.getByID(buffer.getInt())"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
private Types typeUtils;
|
private Types typeUtils;
|
||||||
private Elements elementUtils;
|
private Elements elementUtils;
|
||||||
private Filer filer;
|
private Filer filer;
|
||||||
private Messager messager;
|
private Messager messager;
|
||||||
|
private boolean done;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void init(ProcessingEnvironment processingEnv) {
|
public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||||
@@ -30,11 +54,174 @@ public class AnnotationProcessor extends AbstractProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Override.class)) {
|
if(done) return false;
|
||||||
messager.printMessage(Kind.ERROR, "an element has the override class: ", annotatedElement);
|
done = true;
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Element element : roundEnv.getElementsAnnotatedWith(Remote.class)) {
|
||||||
|
if(!element.getModifiers().contains(Modifier.STATIC)) {
|
||||||
|
messager.printMessage(Kind.ERROR, "All local/remote methods must be static: ", element);
|
||||||
|
}else if(element.getKind() != ElementKind.METHOD){
|
||||||
|
messager.printMessage(Kind.ERROR, "All local/remote annotations must be on methods: ", element);
|
||||||
|
}else{
|
||||||
|
elements.add(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(className)
|
||||||
|
.addModifiers(Modifier.PUBLIC);
|
||||||
|
|
||||||
|
int id = 0;
|
||||||
|
|
||||||
|
classBuilder.addField(FieldSpec.builder(ByteBuffer.class, "TEMP_BUFFER", Modifier.STATIC, Modifier.PRIVATE, Modifier.FINAL)
|
||||||
|
.initializer("ByteBuffer.allocate($1L)", maxPacketSize).build());
|
||||||
|
|
||||||
|
MethodSpec.Builder readMethod = MethodSpec.methodBuilder("readPacket")
|
||||||
|
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||||
|
.addParameter(ByteBuffer.class, "buffer")
|
||||||
|
.addParameter(int.class, "id")
|
||||||
|
.returns(void.class);
|
||||||
|
|
||||||
|
CodeBlock.Builder writeSwitch = CodeBlock.builder();
|
||||||
|
boolean started = false;
|
||||||
|
|
||||||
|
readMethod.addJavadoc("This method reads and executes a method by ID. For internal use only!");
|
||||||
|
|
||||||
|
for (Element e : elements) {
|
||||||
|
boolean local = e.getAnnotation(Local.class) != null;
|
||||||
|
|
||||||
|
ExecutableElement exec = (ExecutableElement)e;
|
||||||
|
|
||||||
|
MethodSpec.Builder method = MethodSpec.methodBuilder(e.getSimpleName().toString())
|
||||||
|
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||||
|
.returns(void.class);
|
||||||
|
|
||||||
|
for(VariableElement var : exec.getParameters()){
|
||||||
|
method.addParameter(TypeName.get(var.asType()), var.getSimpleName().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(local){
|
||||||
|
//todo
|
||||||
|
int index = 0;
|
||||||
|
StringBuilder results = new StringBuilder();
|
||||||
|
for(VariableElement var : exec.getParameters()){
|
||||||
|
results.append(var.getSimpleName());
|
||||||
|
if(index != exec.getParameters().size() - 1) results.append(", ");
|
||||||
|
index ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
method.addStatement("$N." + exec.getSimpleName() + "(" + results.toString() + ")",
|
||||||
|
((TypeElement)e.getEnclosingElement()).getQualifiedName().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!started){
|
||||||
|
writeSwitch.beginControlFlow("if(id == "+id+")");
|
||||||
|
}else{
|
||||||
|
writeSwitch.nextControlFlow("else if(id == "+id+")");
|
||||||
|
}
|
||||||
|
started = true;
|
||||||
|
|
||||||
|
method.addStatement("$1N packet = new $1N()", "io.anuke.mindustry.net.Packets.InvokePacket");
|
||||||
|
method.addStatement("packet.writeBuffer = TEMP_BUFFER");
|
||||||
|
method.addStatement("TEMP_BUFFER.position(0)");
|
||||||
|
|
||||||
|
for(VariableElement var : exec.getParameters()){
|
||||||
|
String varName = var.getSimpleName().toString();
|
||||||
|
String typeName = var.asType().toString();
|
||||||
|
String bufferName = "TEMP_BUFFER";
|
||||||
|
String simpleTypeName = typeName.contains(".") ? typeName.substring(1 + typeName.lastIndexOf('.')) : typeName;
|
||||||
|
String capName = simpleTypeName.equals("byte") ? "" : Character.toUpperCase(simpleTypeName.charAt(0)) + simpleTypeName.substring(1);
|
||||||
|
|
||||||
|
if(typeUtils.isAssignable(var.asType(), elementUtils.getTypeElement("java.lang.Enum").asType())) {
|
||||||
|
method.addStatement(bufferName + ".put(" + varName + ".ordinal())");
|
||||||
|
}else if(isPrimitive(typeName)) {
|
||||||
|
if(simpleTypeName.equals("boolean")){
|
||||||
|
method.addStatement(bufferName + ".put(" + varName + " ? (byte)1 : 0)");
|
||||||
|
}else{
|
||||||
|
method.addStatement(bufferName + ".put" +
|
||||||
|
capName + "(" + varName + ")");
|
||||||
|
}
|
||||||
|
}else if(writeMap.get(simpleTypeName) != null){
|
||||||
|
String[] values = writeMap.get(simpleTypeName)[0];
|
||||||
|
for(String str : values){
|
||||||
|
method.addStatement(str.replaceAll("rbuffer", bufferName)
|
||||||
|
.replaceAll("rvalue", varName));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
messager.printMessage(Kind.ERROR, "No method for writing type: " + typeName, var);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeUtils.isAssignable(var.asType(), elementUtils.getTypeElement("java.lang.Enum").asType())) {
|
||||||
|
writeSwitch.addStatement(typeName + " " + varName + " = " + typeName + ".values()["+bufferName +".getInt()]");
|
||||||
|
}else if(isPrimitive(typeName)) {
|
||||||
|
if(simpleTypeName.equals("boolean")){
|
||||||
|
writeSwitch.addStatement("boolean " + varName + " = " + bufferName + ".get() == 1");
|
||||||
|
}else{
|
||||||
|
writeSwitch.addStatement(typeName + " " + varName + " = " + bufferName + ".get" + capName + "()");
|
||||||
|
}
|
||||||
|
}else if(writeMap.get(simpleTypeName) != null){
|
||||||
|
String[] values = writeMap.get(simpleTypeName)[1];
|
||||||
|
for(String str : values){
|
||||||
|
writeSwitch.addStatement(str.replaceAll("rbuffer", bufferName)
|
||||||
|
.replaceAll("rvalue", varName)
|
||||||
|
.replaceAll("rtype", simpleTypeName));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
messager.printMessage(Kind.ERROR, "No method for writing type: " + typeName, var);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
method.addStatement("packet.writeLength = TEMP_BUFFER.position()");
|
||||||
|
method.addStatement("io.anuke.mindustry.net.Net.send(packet, io.anuke.mindustry.net.Net.SendMode.tcp)");
|
||||||
|
|
||||||
|
classBuilder.addMethod(method.build());
|
||||||
|
|
||||||
|
FieldSpec var = FieldSpec.builder(TypeName.INT, "ID_METHOD_" + exec.getSimpleName().toString().toUpperCase())
|
||||||
|
.initializer("$1L", id).addModifiers(Modifier.FINAL, Modifier.PRIVATE, Modifier.STATIC).build();
|
||||||
|
|
||||||
|
classBuilder.addField(var);
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
StringBuilder results = new StringBuilder();
|
||||||
|
for(VariableElement writevar : exec.getParameters()){
|
||||||
|
results.append(writevar.getSimpleName());
|
||||||
|
if(index != exec.getParameters().size() - 1) results.append(", ");
|
||||||
|
index ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeSwitch.addStatement("com.badlogic.gdx.Gdx.app.postRunnable(() -> $N." + exec.getSimpleName() + "(" + results.toString() + "))",
|
||||||
|
((TypeElement)e.getEnclosingElement()).getQualifiedName().toString());
|
||||||
|
|
||||||
|
id ++;
|
||||||
|
|
||||||
|
//TODO add params from the method and invoke it
|
||||||
|
}
|
||||||
|
|
||||||
|
if(started){
|
||||||
|
writeSwitch.endControlFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
readMethod.addCode(writeSwitch.build());
|
||||||
|
classBuilder.addMethod(readMethod.build());
|
||||||
|
|
||||||
|
TypeSpec spec = classBuilder.build();
|
||||||
|
|
||||||
|
JavaFile.builder(packageName, spec).build().writeTo(filer);
|
||||||
|
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPrimitive(String type){
|
||||||
|
return type.equals("boolean") || type.equals("byte") || type.equals("short") || type.equals("int")
|
||||||
|
|| type.equals("long") || type.equals("float") || type.equals("double") || type.equals("char");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
19
annotations/src/io/anuke/annotations/Annotations.java
Normal file
19
annotations/src/io/anuke/annotations/Annotations.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
public class Annotations {
|
||||||
|
|
||||||
|
/**Marks a method as invokable remotely.*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
public @interface Remote{}
|
||||||
|
|
||||||
|
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
public @interface Local{}
|
||||||
|
}
|
||||||
4
annotations/src/io/anuke/annotations/Serializers.java
Normal file
4
annotations/src/io/anuke/annotations/Serializers.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
public class Serializers {
|
||||||
|
}
|
||||||
10
build.gradle
10
build.gradle
@@ -85,7 +85,8 @@ project(":desktop") {
|
|||||||
compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||||
compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
|
||||||
compile 'com.github.MinnDevelopment:java-discord-rpc:v1.3.2'
|
//todo uncomment
|
||||||
|
//compile 'com.github.MinnDevelopment:java-discord-rpc:v1.3.2'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,8 +175,7 @@ project(":core") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileJava.options.compilerArgs = [
|
compileJava.options.compilerArgs = [
|
||||||
"-proc:only",
|
"-processor", "io.anuke.annotations.AnnotationProcessor"
|
||||||
"-processor", "io.anuke.annotations.AnnotationProcessor"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +193,9 @@ project(":server") {
|
|||||||
project(":annotations") {
|
project(":annotations") {
|
||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
dependencies {}
|
dependencies {
|
||||||
|
compile 'com.squareup:javapoet:1.11.0'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":kryonet") {
|
project(":kryonet") {
|
||||||
|
|||||||
@@ -2,15 +2,11 @@ package io.anuke.mindustry.core;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.Input.Buttons;
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
import io.anuke.mindustry.content.Weapons;
|
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.game.EventType.*;
|
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.AndroidInput;
|
||||||
import io.anuke.mindustry.input.DefaultKeybinds;
|
import io.anuke.mindustry.input.DefaultKeybinds;
|
||||||
import io.anuke.mindustry.input.DesktopInput;
|
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.io.Saves;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.ucore.UCore;
|
|
||||||
import io.anuke.ucore.core.*;
|
import io.anuke.ucore.core.*;
|
||||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
|
||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
|
import io.anuke.ucore.input.InputProxy;
|
||||||
import io.anuke.ucore.modules.Module;
|
import io.anuke.ucore.modules.Module;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
|
||||||
import io.anuke.ucore.util.*;
|
import io.anuke.ucore.util.*;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
@@ -271,6 +265,8 @@ public class Control extends Module{
|
|||||||
|
|
||||||
saves.update();
|
saves.update();
|
||||||
|
|
||||||
|
triggerUpdateInput();
|
||||||
|
|
||||||
if(!state.is(State.menu)){
|
if(!state.is(State.menu)){
|
||||||
for(InputHandler input : inputs){
|
for(InputHandler input : inputs){
|
||||||
input.update();
|
input.update();
|
||||||
|
|||||||
@@ -150,15 +150,10 @@ public class NetClient extends Module {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Net.handleClient(InvokePacket.class, packet -> {
|
Net.handleClient(InvokePacket.class, packet -> {
|
||||||
try{
|
//TODO invoke it
|
||||||
packet.method.invoke(null, packet.args);
|
|
||||||
}catch (ReflectionException e){
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handleClient(StateSyncPacket.class, packet -> {
|
Net.handleClient(StateSyncPacket.class, packet -> {
|
||||||
|
|
||||||
System.arraycopy(packet.items, 0, state.inventory.writeItems(), 0, packet.items.length);
|
System.arraycopy(packet.items, 0, state.inventory.writeItems(), 0, packet.items.length);
|
||||||
|
|
||||||
state.enemies = packet.enemies;
|
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.BulletType;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.SyncEntity;
|
import io.anuke.mindustry.entities.SyncEntity;
|
||||||
|
import io.anuke.mindustry.gen.CallEvent;
|
||||||
import io.anuke.mindustry.io.Platform;
|
import io.anuke.mindustry.io.Platform;
|
||||||
import io.anuke.mindustry.io.Version;
|
import io.anuke.mindustry.io.Version;
|
||||||
import io.anuke.mindustry.net.*;
|
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.Stack;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
import io.anuke.ucore.util.Bundles;
|
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.Log;
|
||||||
import io.anuke.ucore.util.Strings;
|
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.event.Touchable;
|
||||||
import io.anuke.ucore.scene.ui.TextField;
|
import io.anuke.ucore.scene.ui.TextField;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
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.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
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.Axis;
|
||||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||||
import io.anuke.ucore.core.KeyBinds;
|
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 class DefaultKeybinds {
|
||||||
|
|
||||||
public static void load(){
|
public static void load(){
|
||||||
KeyBinds.defaults(
|
String[] sections = {"player_1", "player_2", "player_3", "player_4"};
|
||||||
"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
|
|
||||||
);
|
|
||||||
|
|
||||||
KeyBinds.defaults(
|
for(String section : sections) {
|
||||||
DeviceType.controller,
|
|
||||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
KeyBinds.defaultSection(section, DeviceType.keyboard,
|
||||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
new Category("General"),
|
||||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
"move_x", new Axis(Input.A, Input.D),
|
||||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
"move_y", new Axis(Input.S, Input.W),
|
||||||
"select", Input.CONTROLLER_R_BUMPER,
|
"select", Input.MOUSE_LEFT,
|
||||||
"break", Input.CONTROLLER_L_BUMPER,
|
"break", Input.MOUSE_RIGHT,
|
||||||
"shoot", Input.CONTROLLER_R_TRIGGER,
|
"shoot", Input.MOUSE_LEFT,
|
||||||
"zoom_hold", Input.ANY_KEY,
|
"rotate_alt", new Axis(Input.R, Input.E),
|
||||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
"rotate", new Axis(Input.SCROLL),
|
||||||
"menu", Input.CONTROLLER_X,
|
"dash", Input.SHIFT_LEFT,
|
||||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
new Category("View"),
|
||||||
"dash", Input.CONTROLLER_Y,
|
"zoom_hold", Input.CONTROL_LEFT,
|
||||||
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
|
"zoom", new Axis(Input.SCROLL),
|
||||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
|
||||||
"player_list", Input.CONTROLLER_START,
|
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||||
"chat", Input.ENTER,
|
"pause", Input.SPACE,
|
||||||
"chat_history_prev", Input.UP,
|
"toggle_menus", Input.C,
|
||||||
"chat_history_next", Input.DOWN,
|
"block_info", Input.CONTROL_LEFT,
|
||||||
"chat_scroll", new Axis(Input.SCROLL),
|
"item_withdraw", Input.SHIFT_LEFT,
|
||||||
"console", Input.GRAVE,
|
new Category("Multiplayer"),
|
||||||
"weapon_1", Input.NUM_1,
|
"player_list", Input.TAB,
|
||||||
"weapon_2", Input.NUM_2,
|
"chat", Input.ENTER,
|
||||||
"weapon_3", Input.NUM_3,
|
"chat_history_prev", Input.UP,
|
||||||
"weapon_4", Input.NUM_4,
|
"chat_history_next", Input.DOWN,
|
||||||
"weapon_5", Input.NUM_5,
|
"chat_scroll", new Axis(Input.SCROLL),
|
||||||
"weapon_6", Input.NUM_6
|
"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 enableHold = false;
|
||||||
private boolean beganBreak;
|
private boolean beganBreak;
|
||||||
private boolean controlling;
|
private boolean controlling;
|
||||||
|
private final int index;
|
||||||
|
private final String section;
|
||||||
|
|
||||||
public DesktopInput(Player player){
|
public DesktopInput(Player player){
|
||||||
super(player);
|
super(player);
|
||||||
|
this.index = player.playerIndex;
|
||||||
|
this.section = "player_" + (player.playerIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public float getCursorEndX(){ return endx; }
|
@Override public float getCursorEndX(){ return endx; }
|
||||||
@@ -42,21 +46,21 @@ public class DesktopInput extends InputHandler{
|
|||||||
|
|
||||||
if(player.isDead()) return;
|
if(player.isDead()) return;
|
||||||
|
|
||||||
if(Inputs.keyRelease("select")){
|
if(Inputs.keyRelease(section, "select")){
|
||||||
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
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());
|
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Inputs.keyDown("select")){
|
if(!Inputs.keyDown(section, "select")){
|
||||||
shooting = false;
|
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);
|
Vector2 vec = Graphics.screen(player.x, player.y);
|
||||||
if(vec.dst(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()) <= playerSelectRange){
|
if(vec.dst(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()) <= playerSelectRange){
|
||||||
canBeginShoot = false;
|
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());
|
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
|
||||||
mousex = vec.x;
|
mousex = vec.x;
|
||||||
mousey = vec.y;
|
mousey = vec.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Inputs.keyDown("select") && !Inputs.keyDown("break")){
|
if(!Inputs.keyDown(section, "select") && !Inputs.keyDown(section, "break")){
|
||||||
mousex = Graphics.mouseWorld().x;
|
mousex = Graphics.mouseWorld().x;
|
||||||
mousey = Graphics.mouseWorld().y;
|
mousey = Graphics.mouseWorld().y;
|
||||||
}
|
}
|
||||||
@@ -78,21 +82,21 @@ public class DesktopInput extends InputHandler{
|
|||||||
endx = Gdx.input.getX();
|
endx = Gdx.input.getX();
|
||||||
endy = Gdx.input.getY();
|
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()){
|
&& !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.getAxisTapped(section,"rotate_alt");
|
||||||
rotation += Inputs.getAxis("rotate");
|
rotation += Inputs.getAxis(section,"rotate");
|
||||||
|
|
||||||
rotation = Mathf.mod(rotation, 4);
|
rotation = Mathf.mod(rotation, 4);
|
||||||
|
|
||||||
if(Inputs.keyDown("break")){
|
if(Inputs.keyDown(section,"break")){
|
||||||
breakMode = PlaceMode.areaDelete;
|
breakMode = PlaceMode.areaDelete;
|
||||||
}else{
|
}else{
|
||||||
breakMode = PlaceMode.hold;
|
breakMode = PlaceMode.hold;
|
||||||
@@ -117,24 +121,24 @@ public class DesktopInput extends InputHandler{
|
|||||||
Tile target = cursor == null ? null : cursor.target();
|
Tile target = cursor == null ? null : cursor.target();
|
||||||
boolean showCursor = false;
|
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());
|
dropItem(target, player.inventory.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(droppingItem && (!Inputs.keyDown("select") || player.inventory.isEmpty())){
|
if(droppingItem && (!Inputs.keyDown(section,"select") || player.inventory.isEmpty())){
|
||||||
droppingItem = false;
|
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;
|
showCursor = true;
|
||||||
if(Inputs.keyTap("select")){
|
if(Inputs.keyTap(section,"select")){
|
||||||
canBeginShoot = false;
|
canBeginShoot = false;
|
||||||
frag.inv.showFor(target);
|
frag.inv.showFor(target);
|
||||||
Cursors.restoreCursor();
|
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();
|
frag.inv.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +146,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
showCursor = true;
|
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(target.block().isConfigurable(target)){
|
||||||
if((!frag.config.isShown()
|
if((!frag.config.isShown()
|
||||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor))) {
|
|| 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(Net.active()) NetEvents.handleBlockTap(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyTap("break")){
|
if(Inputs.keyTap(section,"break")){
|
||||||
frag.config.hideConfig();
|
frag.config.hideConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyRelease("break")){
|
if(Inputs.keyRelease(section,"break")){
|
||||||
beganBreak = false;
|
beganBreak = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(recipe != null && Inputs.keyTap("break")){
|
if(recipe != null && Inputs.keyTap(section,"break")){
|
||||||
beganBreak = true;
|
beganBreak = true;
|
||||||
recipe = null;
|
recipe = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//block breaking
|
//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();
|
breaktime += Timers.delta();
|
||||||
if(breaktime >= cursor.getBreakTime()){
|
if(breaktime >= cursor.getBreakTime()){
|
||||||
breakBlock(cursor.x, cursor.y, true);
|
breakBlock(cursor.x, cursor.y, true);
|
||||||
@@ -199,7 +203,6 @@ public class DesktopInput extends InputHandler{
|
|||||||
Cursors.restoreCursor();
|
Cursors.restoreCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,17 +223,21 @@ public class DesktopInput extends InputHandler{
|
|||||||
void updateController(){
|
void updateController(){
|
||||||
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
||||||
|
|
||||||
if(KeyBinds.getSection("default").device.type == DeviceType.controller && !mousemove){
|
if(KeyBinds.getSection(section).device.type == DeviceType.controller && (!mousemove || player.playerIndex > 0)){
|
||||||
if(Inputs.keyTap("select")){
|
if(player.playerIndex > 0){
|
||||||
|
controlling = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Inputs.keyTap(section,"select")){
|
||||||
Inputs.getProcessor().touchDown(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
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);
|
Inputs.getProcessor().touchUp(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
float xa = Inputs.getAxis("cursor_x");
|
float xa = Inputs.getAxis(section, "cursor_x");
|
||||||
float ya = Inputs.getAxis("cursor_y");
|
float ya = Inputs.getAxis(section, "cursor_y");
|
||||||
|
|
||||||
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
|
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
|
||||||
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
|
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.ClassReflection;
|
||||||
import com.badlogic.gdx.utils.reflect.Method;
|
import com.badlogic.gdx.utils.reflect.Method;
|
||||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
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.Vars;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
@@ -39,10 +41,7 @@ public class Invoke {
|
|||||||
method.invoke(null, args);
|
method.invoke(null, args);
|
||||||
}
|
}
|
||||||
InvokePacket packet = new InvokePacket();
|
InvokePacket packet = new InvokePacket();
|
||||||
packet.args = args;
|
|
||||||
packet.type = type;
|
|
||||||
packet.method = method;
|
|
||||||
packet.args = args;
|
|
||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
}catch (ReflectionException e){
|
}catch (ReflectionException e){
|
||||||
throw new RuntimeException(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;
|
package io.anuke.mindustry.net;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.Pools;
|
import com.badlogic.gdx.utils.Pools;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
import io.anuke.annotations.Annotations.Local;
|
||||||
import com.badlogic.gdx.utils.reflect.Method;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.mindustry.Vars;
|
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.SyncEntity;
|
import io.anuke.mindustry.entities.SyncEntity;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
import io.anuke.mindustry.net.Invoke.Local;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.net.Invoke.Remote;
|
import io.anuke.mindustry.gen.CallEvent;
|
||||||
import io.anuke.mindustry.net.Net.SendMode;
|
import io.anuke.mindustry.net.Net.SendMode;
|
||||||
import io.anuke.mindustry.net.Packets.*;
|
import io.anuke.mindustry.net.Packets.*;
|
||||||
import io.anuke.mindustry.resource.Upgrade;
|
import io.anuke.mindustry.resource.Upgrade;
|
||||||
import io.anuke.mindustry.resource.Weapon;
|
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.ucore.entities.Entity;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class NetEvents {
|
public class NetEvents {
|
||||||
|
|
||||||
|
@Remote
|
||||||
|
@Local
|
||||||
public static void friendlyFireChange(boolean enabled){
|
public static void friendlyFireChange(boolean enabled){
|
||||||
state.friendlyFire = enabled;
|
state.friendlyFire = enabled;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.reflect.ReflectionException;
|
|||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.SyncEntity;
|
import io.anuke.mindustry.entities.SyncEntity;
|
||||||
|
import io.anuke.mindustry.gen.CallEvent;
|
||||||
import io.anuke.mindustry.io.Version;
|
import io.anuke.mindustry.io.Version;
|
||||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||||
@@ -33,28 +34,28 @@ public class Packets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class InvokePacket implements Packet{
|
public static class InvokePacket implements Packet{
|
||||||
public Object[] args;
|
public byte type;
|
||||||
public Method method;
|
|
||||||
public Class type;
|
public ByteBuffer writeBuffer;
|
||||||
|
public int writeLength;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ByteBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
IOUtils.writeString(buffer, method.getName());
|
type = buffer.get();
|
||||||
IOUtils.writeString(buffer, type.getName());
|
|
||||||
Invoke.writeObjects(buffer, args);
|
if(Net.client()){
|
||||||
|
CallEvent.readPacket(buffer, type);
|
||||||
|
}else{
|
||||||
|
buffer.position(buffer.position() + writeLength);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
String methodname = IOUtils.readString(buffer);
|
buffer.put(type);
|
||||||
String typename = IOUtils.readString(buffer);
|
writeBuffer.position(0);
|
||||||
|
for(int i = 0; i < writeLength; i ++){
|
||||||
try {
|
buffer.put(writeBuffer.get());
|
||||||
type = Invoke.findClass(typename);
|
|
||||||
method = Invoke.getMethod(type, methodname);
|
|
||||||
args = Invoke.readObjects(buffer, method.getParameterTypes());
|
|
||||||
}catch (ReflectionException e){
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package io.anuke.mindustry.desktop;
|
package io.anuke.mindustry.desktop;
|
||||||
|
|
||||||
import club.minnced.discord.rpc.DiscordEventHandlers;
|
//import club.minnced.discord.rpc.DiscordEventHandlers;
|
||||||
import club.minnced.discord.rpc.DiscordRPC;
|
//import club.minnced.discord.rpc.DiscordRPC;
|
||||||
import club.minnced.discord.rpc.DiscordRichPresence;
|
//import club.minnced.discord.rpc.DiscordRichPresence;
|
||||||
import com.badlogic.gdx.utils.Base64Coder;
|
import com.badlogic.gdx.utils.Base64Coder;
|
||||||
import io.anuke.kryonet.DefaultThreadImpl;
|
import io.anuke.kryonet.DefaultThreadImpl;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
@@ -24,7 +24,7 @@ import java.util.Locale;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
//TODO uncomment discord related stuff
|
||||||
public class DesktopPlatform extends Platform {
|
public class DesktopPlatform extends Platform {
|
||||||
final static boolean useDiscord = UCore.getPropertyNotNull("sun.arch.data.model").equals("64");
|
final static boolean useDiscord = UCore.getPropertyNotNull("sun.arch.data.model").equals("64");
|
||||||
final static String applicationId = "398246104468291591";
|
final static String applicationId = "398246104468291591";
|
||||||
@@ -35,8 +35,8 @@ public class DesktopPlatform extends Platform {
|
|||||||
this.args = args;
|
this.args = args;
|
||||||
|
|
||||||
if(useDiscord) {
|
if(useDiscord) {
|
||||||
DiscordEventHandlers handlers = new DiscordEventHandlers();
|
// DiscordEventHandlers handlers = new DiscordEventHandlers();
|
||||||
DiscordRPC.INSTANCE.Discord_Initialize(applicationId, handlers, true, "");
|
// DiscordRPC.INSTANCE.Discord_Initialize(applicationId, handlers, true, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +62,7 @@ public class DesktopPlatform extends Platform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateRPC() {
|
public void updateRPC() {
|
||||||
|
/*
|
||||||
if(!useDiscord) return;
|
if(!useDiscord) return;
|
||||||
|
|
||||||
DiscordRichPresence presence = new DiscordRichPresence();
|
DiscordRichPresence presence = new DiscordRichPresence();
|
||||||
@@ -86,12 +87,12 @@ public class DesktopPlatform extends Platform {
|
|||||||
|
|
||||||
presence.largeImageKey = "logo";
|
presence.largeImageKey = "logo";
|
||||||
|
|
||||||
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);
|
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGameExit() {
|
public void onGameExit() {
|
||||||
if(useDiscord) DiscordRPC.INSTANCE.Discord_Shutdown();
|
//if(useDiscord) DiscordRPC.INSTANCE.Discord_Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user