Merge branch '4.0' of https://github.com/Anuken/Mindustry
# Conflicts: # core/assets/bundles/bundle_ko.properties # core/src/io/anuke/mindustry/Vars.java # core/src/io/anuke/mindustry/core/UI.java
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
/core/assets/mindustry-saves/
|
/core/assets/mindustry-saves/
|
||||||
/core/assets/mindustry-maps/
|
/core/assets/mindustry-maps/
|
||||||
|
/core/assets/bundles/output/
|
||||||
/deploy/
|
/deploy/
|
||||||
/desktop/packr-out/
|
/desktop/packr-out/
|
||||||
/desktop/packr-export/
|
/desktop/packr-export/
|
||||||
@@ -9,9 +10,12 @@
|
|||||||
/desktop/mindustry-maps/
|
/desktop/mindustry-maps/
|
||||||
/desktop/gifexport/
|
/desktop/gifexport/
|
||||||
/core/lib/
|
/core/lib/
|
||||||
|
/core/assets-raw/sprites/generated/
|
||||||
/annotations/build/
|
/annotations/build/
|
||||||
/kryonet/build/
|
/kryonet/build/
|
||||||
|
/packer/build/
|
||||||
/server/build/
|
/server/build/
|
||||||
|
/annotations/build/
|
||||||
/android/assets/mindustry-maps/
|
/android/assets/mindustry-maps/
|
||||||
/android/assets/mindustry-saves/
|
/android/assets/mindustry-saves/
|
||||||
/core/assets/gifexport/
|
/core/assets/gifexport/
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ jdk:
|
|||||||
|
|
||||||
android:
|
android:
|
||||||
components:
|
components:
|
||||||
- android-26
|
- android-27
|
||||||
|
|
||||||
# Additional components
|
# Additional components
|
||||||
- extra-google-google_play_services
|
- extra-google-google_play_services
|
||||||
- extra-google-m2repository
|
- extra-google-m2repository
|
||||||
- extra-android-m2repository
|
- extra-android-m2repository
|
||||||
- addon-google_apis-google-26
|
- addon-google_apis-google-27
|
||||||
|
- build-tools-27.0.3
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./gradlew desktop:dist
|
- ./gradlew desktop:dist
|
||||||
|
|||||||
@@ -9,22 +9,58 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:resizeableActivity="false"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:allowBackup="true"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:theme="@style/GdxTheme" >
|
android:isGame="true"
|
||||||
|
android:appCategory="game"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:theme="@style/GdxTheme" android:fullBackupContent="@xml/backup_rules">
|
||||||
<activity
|
<activity
|
||||||
android:name="io.anuke.mindustry.AndroidLauncher"
|
android:name="io.anuke.mindustry.AndroidLauncher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:screenOrientation="sensorLandscape"
|
android:screenOrientation="user"
|
||||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
<data android:mimeType="application/octet-stream"/>
|
||||||
|
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.mmap" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
<data android:mimeType="application/octet-stream"/>
|
||||||
|
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.msav" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
|
||||||
|
<intent-filter android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="Mindustry Map"
|
||||||
|
android:priority="1">
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.mmap" android:mimeType="*/*" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.msav" android:mimeType="*/*" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
|
||||||
<activity android:name=".DonationsActivity"
|
<activity android:name=".DonationsActivity"
|
||||||
android:theme="@style/GdxTheme" />
|
android:theme="@style/GdxTheme" />
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
|
||||||
|
apply plugin: "com.android.application"
|
||||||
|
|
||||||
|
configurations { natives }
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
jcenter()
|
||||||
@@ -8,9 +12,20 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.android.support:support-v4:22.1.1'
|
implementation project(":core")
|
||||||
|
implementation project(":kryonet")
|
||||||
|
implementation 'com.android.support:support-v4:25.3.1'
|
||||||
implementation 'org.sufficientlysecure:donations:2.5'
|
implementation 'org.sufficientlysecure:donations:2.5'
|
||||||
implementation 'com.google.android.gms:play-services-auth:11.8.0'
|
implementation 'com.google.android.gms:play-services-auth:11.8.0'
|
||||||
|
|
||||||
|
implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
|
||||||
|
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
|
||||||
|
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
|
||||||
|
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
|
||||||
|
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
|
||||||
|
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
|
||||||
|
implementation "com.badlogicgames.gdx:gdx-ai:$aiVersion"
|
||||||
|
implementation "com.badlogicgames.gdx:gdx-controllers-android:$gdxVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
task deploy(type: Copy){
|
task deploy(type: Copy){
|
||||||
@@ -22,8 +37,8 @@ task deploy(type: Copy){
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
buildToolsVersion '26.0.2'
|
buildToolsVersion '27.0.3'
|
||||||
compileSdkVersion 26
|
compileSdkVersion 27
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
manifest.srcFile 'AndroidManifest.xml'
|
manifest.srcFile 'AndroidManifest.xml'
|
||||||
@@ -35,7 +50,7 @@ android {
|
|||||||
jniLibs.srcDirs = ['libs']
|
jniLibs.srcDirs = ['libs']
|
||||||
}
|
}
|
||||||
|
|
||||||
instrumentTest.setRoot('tests')
|
androidTest.setRoot('tests')
|
||||||
}
|
}
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
exclude 'META-INF/robovm/ios/robovm.xml'
|
exclude 'META-INF/robovm/ios/robovm.xml'
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/layout_root"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="10dp" >
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/gdxDialogsEditTextInput"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="text"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:maxLength="15"
|
|
||||||
>
|
|
||||||
|
|
||||||
<requestFocus />
|
|
||||||
|
|
||||||
</EditText>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -5,28 +5,7 @@
|
|||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="10dp" >
|
android:padding="10dp" >
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/gdxDialogsEnterTitle"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
|
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
||||||
|
|
||||||
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/gdxDialogsEnterMessage"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
|
|
||||||
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/gdxDialogsEditTextInput"
|
android:id="@+id/gdxDialogsEditTextInput"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="GdxTheme" parent="android:Theme.Material.NoActionBar">
|
<style name="GdxTheme" parent="android:Theme.Material.NoActionBar">
|
||||||
<item name="android:windowBackground">@android:color/transparent</item>
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||||
@@ -9,11 +8,4 @@
|
|||||||
<item name="android:windowContentOverlay">@null</item>
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
<item name="android:windowFullscreen">true</item>
|
<item name="android:windowFullscreen">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="LightBackground" parent="android:Theme.Material.Light" >
|
|
||||||
<item name="android:colorBackground">@android:color/black</item>
|
|
||||||
<item name="android:textColorPrimary">@android:color/white</item>
|
|
||||||
<item name="android:textColorSecondary">@android:color/white</item>
|
|
||||||
<item name="android:textColorSecondaryInverse">@android:color/white</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<full-backup-content>
|
||||||
|
|
||||||
|
</full-backup-content>
|
||||||
@@ -3,14 +3,18 @@ package io.anuke.mindustry;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplication;
|
import com.badlogic.gdx.backends.android.AndroidApplication;
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
|
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
|
||||||
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.utils.Base64Coder;
|
import com.badlogic.gdx.utils.Base64Coder;
|
||||||
import com.google.android.gms.common.GoogleApiAvailability;
|
import com.google.android.gms.common.GoogleApiAvailability;
|
||||||
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
|
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
|
||||||
@@ -19,163 +23,263 @@ import com.google.android.gms.security.ProviderInstaller;
|
|||||||
import io.anuke.kryonet.DefaultThreadImpl;
|
import io.anuke.kryonet.DefaultThreadImpl;
|
||||||
import io.anuke.kryonet.KryoClient;
|
import io.anuke.kryonet.KryoClient;
|
||||||
import io.anuke.kryonet.KryoServer;
|
import io.anuke.kryonet.KryoServer;
|
||||||
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
|
|
||||||
import io.anuke.mindustry.core.Platform;
|
import io.anuke.mindustry.core.Platform;
|
||||||
|
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
|
||||||
|
import io.anuke.mindustry.io.SaveIO;
|
||||||
|
import io.anuke.mindustry.io.Saves.SaveSlot;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.mindustry.ui.dialogs.FileChooser;
|
||||||
|
import io.anuke.ucore.function.Consumer;
|
||||||
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.Bundles;
|
||||||
|
import io.anuke.ucore.util.Strings;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Random;
|
|
||||||
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class AndroidLauncher extends AndroidApplication{
|
public class AndroidLauncher extends AndroidApplication{
|
||||||
boolean doubleScaleTablets = true;
|
public static final int PERMISSION_REQUEST_CODE = 1;
|
||||||
int WRITE_REQUEST_CODE = 1;
|
|
||||||
|
|
||||||
@Override
|
boolean doubleScaleTablets = true;
|
||||||
protected void onCreate(Bundle savedInstanceState){
|
FileChooser chooser;
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
@Override
|
||||||
config.useImmersiveMode = true;
|
protected void onCreate(Bundle savedInstanceState){
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Platform.instance = new Platform(){
|
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||||
DateFormat format = SimpleDateFormat.getDateTimeInstance();
|
config.useImmersiveMode = true;
|
||||||
|
|
||||||
@Override
|
Platform.instance = new Platform(){
|
||||||
public boolean hasDiscord() {
|
DateFormat format = SimpleDateFormat.getDateTimeInstance();
|
||||||
return isPackageInstalled("com.discord");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(Date date){
|
public boolean hasDiscord(){
|
||||||
return format.format(date);
|
return isPackageInstalled("com.discord");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(int number){
|
public String format(Date date){
|
||||||
return NumberFormat.getIntegerInstance().format(number);
|
return format.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDialog(TextField field, int length){
|
public String format(int number){
|
||||||
TextFieldDialogListener.add(field, 0, length);
|
return NumberFormat.getIntegerInstance().format(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLocaleName(Locale locale){
|
public void addDialog(TextField field, int length){
|
||||||
return locale.getDisplayName(locale);
|
TextFieldDialogListener.add(field, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openDonations() {
|
public String getLocaleName(Locale locale){
|
||||||
showDonations();
|
return locale.getDisplayName(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestWritePerms() {
|
public void openDonations(){
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
showDonations();
|
||||||
if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED &&
|
}
|
||||||
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE}, WRITE_REQUEST_CODE);
|
|
||||||
}else{
|
|
||||||
|
|
||||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
@Override
|
||||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_REQUEST_CODE);
|
public ThreadProvider getThreadProvider(){
|
||||||
}
|
return new DefaultThreadImpl();
|
||||||
|
}
|
||||||
|
|
||||||
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
@Override
|
||||||
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, WRITE_REQUEST_CODE);
|
public boolean isDebug(){
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ThreadProvider getThreadProvider() {
|
public String getUUID(){
|
||||||
return new DefaultThreadImpl();
|
try{
|
||||||
}
|
String s = Secure.getString(getContext().getContentResolver(),
|
||||||
|
Secure.ANDROID_ID);
|
||||||
|
|
||||||
@Override
|
int len = s.length();
|
||||||
public boolean isDebug() {
|
byte[] data = new byte[len / 2];
|
||||||
return false;
|
for(int i = 0; i < len; i += 2){
|
||||||
}
|
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
||||||
|
+ Character.digit(s.charAt(i + 1), 16));
|
||||||
@Override
|
|
||||||
public byte[] getUUID() {
|
|
||||||
try {
|
|
||||||
String s = Secure.getString(getContext().getContentResolver(),
|
|
||||||
Secure.ANDROID_ID);
|
|
||||||
|
|
||||||
int len = s.length();
|
|
||||||
byte[] data = new byte[len / 2];
|
|
||||||
for (int i = 0; i < len; i += 2) {
|
|
||||||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
|
||||||
+ Character.digit(s.charAt(i + 1), 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(new String(Base64Coder.encode(data)).equals("AAAAAAAAAOA=")) throw new RuntimeException("Bad UUID.");
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}catch (Exception e){
|
|
||||||
|
|
||||||
String uuid = Settings.getString("uuid", "");
|
|
||||||
if(uuid.isEmpty()){
|
|
||||||
byte[] result = new byte[8];
|
|
||||||
new Random().nextBytes(result);
|
|
||||||
uuid = new String(Base64Coder.encode(result));
|
|
||||||
Settings.putString("uuid", uuid);
|
|
||||||
Settings.save();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
return Base64Coder.decode(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
String result = new String(Base64Coder.encode(data));
|
||||||
ProviderInstaller.installIfNeeded(this);
|
|
||||||
} catch (GooglePlayServicesRepairableException e) {
|
|
||||||
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
|
|
||||||
apiAvailability.getErrorDialog(this, e.getConnectionStatusCode(), 0).show();
|
|
||||||
} catch (GooglePlayServicesNotAvailableException e) {
|
|
||||||
Log.e("SecurityException", "Google Play Services not available.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(doubleScaleTablets && isTablet(this.getContext())){
|
if(result.equals("AAAAAAAAAOA=")) throw new RuntimeException("Bad UUID.");
|
||||||
Unit.dp.addition = 0.5f;
|
|
||||||
}
|
return result;
|
||||||
|
}catch(Exception e){
|
||||||
config.hideStatusBar = true;
|
return super.getUUID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shareFile(FileHandle file){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showFileChooser(String text, String content, Consumer<FileHandle> cons, boolean open, String filetype){
|
||||||
|
chooser = new FileChooser(text, file -> file.extension().equalsIgnoreCase(filetype), open, cons);
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
|
||||||
|
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)){
|
||||||
|
chooser.show();
|
||||||
|
chooser = null;
|
||||||
|
}else{
|
||||||
|
ArrayList<String> perms = new ArrayList<>();
|
||||||
|
|
||||||
|
if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
|
||||||
|
perms.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
|
||||||
|
perms.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestPermissions(perms.toArray(new String[perms.size()]), PERMISSION_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beginForceLandscape(){
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endForceLandscape(){
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDonate(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try{
|
||||||
|
ProviderInstaller.installIfNeeded(this);
|
||||||
|
}catch(GooglePlayServicesRepairableException e){
|
||||||
|
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
|
||||||
|
apiAvailability.getErrorDialog(this, e.getConnectionStatusCode(), 0).show();
|
||||||
|
}catch(GooglePlayServicesNotAvailableException e){
|
||||||
|
Log.e("SecurityException", "Google Play Services not available.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(doubleScaleTablets && isTablet(this.getContext())){
|
||||||
|
Unit.dp.addition = 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.hideStatusBar = true;
|
||||||
|
|
||||||
Net.setClientProvider(new KryoClient());
|
Net.setClientProvider(new KryoClient());
|
||||||
Net.setServerProvider(new KryoServer());
|
Net.setServerProvider(new KryoServer());
|
||||||
|
|
||||||
initialize(new Mindustry(), config);
|
initialize(new Mindustry(), config);
|
||||||
}
|
|
||||||
|
checkFiles(getIntent());
|
||||||
private boolean isPackageInstalled(String packagename) {
|
}
|
||||||
try {
|
|
||||||
getPackageManager().getPackageInfo(packagename, 0);
|
@Override
|
||||||
return true;
|
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults){
|
||||||
} catch (Exception e) {
|
if(requestCode == PERMISSION_REQUEST_CODE){
|
||||||
return false;
|
for(int i : grantResults){
|
||||||
}
|
if(i != PackageManager.PERMISSION_GRANTED) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTablet(Context context) {
|
if(chooser != null){
|
||||||
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
chooser.show();
|
||||||
return manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void showDonations(){
|
|
||||||
Intent intent = new Intent(this, DonationsActivity.class);
|
private void checkFiles(Intent intent){
|
||||||
startActivity(intent);
|
try{
|
||||||
}
|
Uri uri = intent.getData();
|
||||||
|
if(uri != null){
|
||||||
|
File myFile = null;
|
||||||
|
String scheme = uri.getScheme();
|
||||||
|
if(scheme.equals("file")){
|
||||||
|
String fileName = uri.getEncodedPath();
|
||||||
|
myFile = new File(fileName);
|
||||||
|
}else if(!scheme.equals("content")){
|
||||||
|
//error
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean save = uri.getPath().endsWith(saveExtension);
|
||||||
|
boolean map = uri.getPath().endsWith(mapExtension);
|
||||||
|
|
||||||
|
InputStream inStream;
|
||||||
|
if(myFile != null) inStream = new FileInputStream(myFile);
|
||||||
|
else inStream = getContentResolver().openInputStream(uri);
|
||||||
|
|
||||||
|
Gdx.app.postRunnable(() -> {
|
||||||
|
|
||||||
|
if(save){ //open save
|
||||||
|
System.out.println("Opening save.");
|
||||||
|
FileHandle file = Gdx.files.local("temp-save." + saveExtension);
|
||||||
|
file.write(inStream, false);
|
||||||
|
|
||||||
|
if(SaveIO.isSaveValid(file)){
|
||||||
|
try{
|
||||||
|
SaveSlot slot = control.getSaves().importSave(file);
|
||||||
|
ui.load.runLoadSave(slot);
|
||||||
|
}catch(IOException e){
|
||||||
|
ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
ui.showError("$text.save.import.invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(map){ //open map
|
||||||
|
Gdx.app.postRunnable(() -> {
|
||||||
|
System.out.println("Opening map.");
|
||||||
|
if(!ui.editor.isShown()){
|
||||||
|
ui.editor.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.editor.beginEditMap(inStream);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPackageInstalled(String packagename){
|
||||||
|
try{
|
||||||
|
getPackageManager().getPackageInfo(packagename, 0);
|
||||||
|
return true;
|
||||||
|
}catch(Exception e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTablet(Context context){
|
||||||
|
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
return manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showDonations(){
|
||||||
|
Intent intent = new Intent(this, DonationsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,21 +11,20 @@ import android.widget.EditText;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
|
||||||
public class AndroidTextFieldDialog{
|
public class AndroidTextFieldDialog{
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
private EditText userInput;
|
private EditText userInput;
|
||||||
private AlertDialog.Builder builder;
|
private AlertDialog.Builder builder;
|
||||||
private TextPromptListener listener;
|
private TextPromptListener listener;
|
||||||
private boolean isBuild;
|
private boolean isBuild;
|
||||||
|
|
||||||
public AndroidTextFieldDialog() {
|
public AndroidTextFieldDialog(){
|
||||||
this.activity = (Activity)Gdx.app;
|
this.activity = (Activity) Gdx.app;
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidTextFieldDialog show() {
|
public AndroidTextFieldDialog show(){
|
||||||
|
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
Gdx.app.error("Android Dialogs", AndroidTextFieldDialog.class.getSimpleName() + " now shown.");
|
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
|
|
||||||
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
@@ -34,12 +33,12 @@ public class AndroidTextFieldDialog{
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AndroidTextFieldDialog load() {
|
private AndroidTextFieldDialog load(){
|
||||||
|
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
|
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
|
||||||
LayoutInflater li = LayoutInflater.from(activity);
|
LayoutInflater li = LayoutInflater.from(activity);
|
||||||
@@ -48,7 +47,7 @@ public class AndroidTextFieldDialog{
|
|||||||
|
|
||||||
alertDialogBuilder.setView(promptsView);
|
alertDialogBuilder.setView(promptsView);
|
||||||
|
|
||||||
userInput = (EditText) promptsView.findViewById(getResourceId("gdxDialogsEditTextInput", "id"));
|
userInput = promptsView.findViewById(getResourceId("gdxDialogsEditTextInput", "id"));
|
||||||
|
|
||||||
alertDialogBuilder.setCancelable(false);
|
alertDialogBuilder.setCancelable(false);
|
||||||
builder = alertDialogBuilder;
|
builder = alertDialogBuilder;
|
||||||
@@ -56,64 +55,65 @@ public class AndroidTextFieldDialog{
|
|||||||
isBuild = true;
|
isBuild = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait till TextPrompt is built.
|
// Wait till TextPrompt is built.
|
||||||
while (!isBuild) {
|
while(!isBuild){
|
||||||
try {
|
try{
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
} catch (InterruptedException e) { }
|
}catch(InterruptedException e){
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getResourceId(String pVariableName, String pVariableType) {
|
public int getResourceId(String pVariableName, String pVariableType){
|
||||||
try {
|
try{
|
||||||
return activity.getResources().getIdentifier(pVariableName, pVariableType, activity.getPackageName());
|
return activity.getResources().getIdentifier(pVariableName, pVariableType, activity.getPackageName());
|
||||||
} catch (Exception e) {
|
}catch(Exception e){
|
||||||
Gdx.app.error("Android Dialogs", "Cannot find resouce with name: " + pVariableName
|
Gdx.app.error("Android Dialogs", "Cannot find resouce with name: " + pVariableName
|
||||||
+ " Did you copy the layouts to /res/layouts and /res/layouts_v14 ?");
|
+ " Did you copy the layouts to /res/layouts and /res/layouts_v14 ?");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidTextFieldDialog setText(CharSequence value) {
|
public AndroidTextFieldDialog setText(CharSequence value){
|
||||||
userInput.append(value);
|
userInput.append(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidTextFieldDialog setCancelButtonLabel(CharSequence label) {
|
public AndroidTextFieldDialog setCancelButtonLabel(CharSequence label){
|
||||||
builder.setNegativeButton(label, (dialog, id) -> dialog.cancel());
|
builder.setNegativeButton(label, (dialog, id) -> dialog.cancel());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label) {
|
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label){
|
||||||
builder.setPositiveButton(label, (dialog, id) -> {
|
builder.setPositiveButton(label, (dialog, id) -> {
|
||||||
if (listener != null && !userInput.getText().toString().isEmpty()) {
|
if(listener != null && !userInput.getText().toString().isEmpty()){
|
||||||
listener.confirm(userInput.getText().toString());
|
listener.confirm(userInput.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidTextFieldDialog setTextPromptListener(TextPromptListener listener) {
|
public AndroidTextFieldDialog setTextPromptListener(TextPromptListener listener){
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidTextFieldDialog setInputType(int type) {
|
public AndroidTextFieldDialog setInputType(int type){
|
||||||
userInput.setInputType(type);
|
userInput.setInputType(type);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidTextFieldDialog setMaxLength(int length) {
|
public AndroidTextFieldDialog setMaxLength(int length){
|
||||||
userInput.setFilters(new InputFilter[] { new InputFilter.LengthFilter(length) });
|
userInput.setFilters(new InputFilter[]{new InputFilter.LengthFilter(length)});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TextPromptListener{
|
public interface TextPromptListener{
|
||||||
void confirm(String text);
|
void confirm(String text);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,9 @@ import android.support.v4.app.FragmentManager;
|
|||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import org.sufficientlysecure.donations.DonationsFragment;
|
import org.sufficientlysecure.donations.DonationsFragment;
|
||||||
|
|
||||||
public class DonationsActivity extends FragmentActivity {
|
public class DonationsActivity extends FragmentActivity{
|
||||||
DonationsFragment donationsFragment;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Google
|
* Google
|
||||||
*/
|
*/
|
||||||
@@ -21,13 +18,14 @@ public class DonationsActivity extends FragmentActivity {
|
|||||||
private static final String[] GOOGLE_CATALOG = new String[]{
|
private static final String[] GOOGLE_CATALOG = new String[]{
|
||||||
"mindustry.donation.1", "mindustry.donation.2", "mindustry.donation.5",
|
"mindustry.donation.1", "mindustry.donation.2", "mindustry.donation.5",
|
||||||
"mindustry.donation.10", "mindustry.donation.15",
|
"mindustry.donation.10", "mindustry.donation.15",
|
||||||
"mindustry.donation.25", "mindustry.donation.50" };
|
"mindustry.donation.25", "mindustry.donation.50"};
|
||||||
|
DonationsFragment donationsFragment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState){
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setTheme(R.style.GdxTheme);
|
setTheme(R.style.GdxTheme);
|
||||||
@@ -35,7 +33,7 @@ public class DonationsActivity extends FragmentActivity {
|
|||||||
setContentView(R.layout.donations_activity);
|
setContentView(R.layout.donations_activity);
|
||||||
|
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
if (BuildConfig.DONATIONS_GOOGLE) {
|
if(BuildConfig.DONATIONS_GOOGLE){
|
||||||
donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, true, GOOGLE_PUBKEY, GOOGLE_CATALOG,
|
donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, true, GOOGLE_PUBKEY, GOOGLE_CATALOG,
|
||||||
getResources().getStringArray(R.array.donation_google_catalog_values), false, null, null,
|
getResources().getStringArray(R.array.donation_google_catalog_values), false, null, null,
|
||||||
null, false, null, null, false, null);
|
null, false, null, null, false, null);
|
||||||
@@ -48,9 +46,10 @@ public class DonationsActivity extends FragmentActivity {
|
|||||||
|
|
||||||
public void onStart(){
|
public void onStart(){
|
||||||
super.onStart();
|
super.onStart();
|
||||||
Button b = ((Button)findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
Button b = ((Button) findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
||||||
b.setOnClickListener(new View.OnClickListener() {
|
b.setOnClickListener(new View.OnClickListener(){
|
||||||
@Override public void onClick(View view) {
|
@Override
|
||||||
|
public void onClick(View view){
|
||||||
donationsFragment.donateGoogleOnClick(donationsFragment.getView());
|
donationsFragment.donateGoogleOnClick(donationsFragment.getView());
|
||||||
b.setEnabled(false);
|
b.setEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -58,20 +57,19 @@ public class DonationsActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Needed for Google Play In-app Billing. It uses startIntentSenderForResult(). The result is not propagated to
|
* Needed for Google Play In-app Billing. It uses startIntentSenderForResult(). The result is not propagated to
|
||||||
* the Fragment like in startActivityForResult(). Thus we need to propagate manually to our Fragment.
|
* the Fragment like in startActivityForResult(). Thus we need to propagate manually to our Fragment.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
Button b = ((Button)findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
Button b = ((Button) findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
|
||||||
b.setEnabled(true);
|
b.setEnabled(true);
|
||||||
|
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
Fragment fragment = fragmentManager.findFragmentByTag("donationsFragment");
|
Fragment fragment = fragmentManager.findFragmentByTag("donationsFragment");
|
||||||
if (fragment != null) {
|
if(fragment != null){
|
||||||
fragment.onActivityResult(requestCode, resultCode, data);
|
fragment.onActivityResult(requestCode, resultCode, data);
|
||||||
//TODO donation event, set settings?
|
//TODO donation event, set settings?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,57 +11,57 @@ import io.anuke.ucore.scene.event.InputListener;
|
|||||||
import io.anuke.ucore.scene.ui.TextField;
|
import io.anuke.ucore.scene.ui.TextField;
|
||||||
|
|
||||||
public class TextFieldDialogListener extends ClickListener{
|
public class TextFieldDialogListener extends ClickListener{
|
||||||
private TextField field;
|
private TextField field;
|
||||||
private int type;
|
private int type;
|
||||||
private int max;
|
private int max;
|
||||||
|
|
||||||
public static void add(TextField field, int type, int max){
|
//type - 0 is text, 1 is numbers, 2 is decimals
|
||||||
field.addListener(new TextFieldDialogListener(field, type, max));
|
public TextFieldDialogListener(TextField field, int type, int max){
|
||||||
field.addListener(new InputListener(){
|
this.field = field;
|
||||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
this.type = type;
|
||||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
this.max = max;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void add(TextField field){
|
public static void add(TextField field, int type, int max){
|
||||||
add(field, 0, 16);
|
field.addListener(new TextFieldDialogListener(field, type, max));
|
||||||
}
|
field.addListener(new InputListener(){
|
||||||
|
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
|
||||||
|
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//type - 0 is text, 1 is numbers, 2 is decimals
|
public static void add(TextField field){
|
||||||
public TextFieldDialogListener(TextField field, int type, int max){
|
add(field, 0, 16);
|
||||||
this.field = field;
|
}
|
||||||
this.type = type;
|
|
||||||
this.max = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clicked(final InputEvent event, float x, float y){
|
public void clicked(final InputEvent event, float x, float y){
|
||||||
|
|
||||||
if(Gdx.app.getType() == ApplicationType.Desktop) return;
|
|
||||||
|
|
||||||
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
|
|
||||||
|
|
||||||
dialog.setTextPromptListener(text -> {
|
if(Gdx.app.getType() == ApplicationType.Desktop) return;
|
||||||
|
|
||||||
|
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
|
||||||
|
|
||||||
|
dialog.setTextPromptListener(text -> {
|
||||||
field.clearText();
|
field.clearText();
|
||||||
field.appendText(text);
|
field.appendText(text);
|
||||||
field.fire(new ChangeListener.ChangeEvent());
|
field.fire(new ChangeListener.ChangeEvent());
|
||||||
Gdx.graphics.requestRendering();
|
Gdx.graphics.requestRendering();
|
||||||
});
|
});
|
||||||
|
|
||||||
if(type == 0){
|
if(type == 0){
|
||||||
dialog.setInputType(InputType.TYPE_CLASS_TEXT);
|
dialog.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
}else if(type == 1){
|
}else if(type == 1){
|
||||||
dialog.setInputType(InputType.TYPE_CLASS_NUMBER);
|
dialog.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||||
}else if(type == 2){
|
}else if(type == 2){
|
||||||
dialog.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
dialog.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.setConfirmButtonLabel("OK").setText(field.getText());
|
dialog.setConfirmButtonLabel("OK").setText(field.getText());
|
||||||
dialog.setCancelButtonLabel("Cancel");
|
dialog.setCancelButtonLabel("Cancel");
|
||||||
dialog.setMaxLength(max);
|
dialog.setMaxLength(max);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
event.cancel();
|
event.cancel();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Goal: To create a system to send events to the server from the client and vice versa, without creating a new packet type each time.<br>
|
||||||
|
* These events may optionally also trigger on the caller client/server as well.<br>
|
||||||
|
*/
|
||||||
|
public class Annotations{
|
||||||
|
|
||||||
|
public enum PacketPriority{
|
||||||
|
/** Gets put in a queue and processed if not connected. */
|
||||||
|
normal,
|
||||||
|
/** Gets handled immediately, regardless of connection status. */
|
||||||
|
high,
|
||||||
|
/** Does not get handled unless client is connected. */
|
||||||
|
low
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A set of two booleans, one specifying server and one specifying client. */
|
||||||
|
public enum Loc{
|
||||||
|
/** Method can only be invoked on the client from the server. */
|
||||||
|
server(true, false),
|
||||||
|
/** Method can only be invoked on the server from the client. */
|
||||||
|
client(false, true),
|
||||||
|
/** Method can be invoked from anywhere */
|
||||||
|
both(true, true),
|
||||||
|
/** Neither server nor client. */
|
||||||
|
none(false, false);
|
||||||
|
|
||||||
|
/** If true, this method can be invoked ON clients FROM servers. */
|
||||||
|
public final boolean isServer;
|
||||||
|
/** If true, this method can be invoked ON servers FROM clients. */
|
||||||
|
public final boolean isClient;
|
||||||
|
|
||||||
|
Loc(boolean server, boolean client){
|
||||||
|
this.isServer = server;
|
||||||
|
this.isClient = client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Variant{
|
||||||
|
/** Method can only be invoked targeting one player. */
|
||||||
|
one(true, false),
|
||||||
|
/** Method can only be invoked targeting all players. */
|
||||||
|
all(false, true),
|
||||||
|
/** Method targets both one player and all players. */
|
||||||
|
both(true, true);
|
||||||
|
|
||||||
|
public final boolean isOne, isAll;
|
||||||
|
|
||||||
|
Variant(boolean isOne, boolean isAll){
|
||||||
|
this.isOne = isOne;
|
||||||
|
this.isAll = isAll;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Marks a method as invokable remotely across a server/client connection. */
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
public @interface Remote{
|
||||||
|
/** Specifies the locations from which this method can be invoked. */
|
||||||
|
Loc targets() default Loc.server;
|
||||||
|
|
||||||
|
/** Specifies which methods are generated. Only affects server-to-client methods. */
|
||||||
|
Variant variants() default Variant.all;
|
||||||
|
|
||||||
|
/** The local locations where this method is called locally, when invoked. */
|
||||||
|
Loc called() default Loc.none;
|
||||||
|
|
||||||
|
/** Whether to forward this packet to all other clients upon recieval. Client only. */
|
||||||
|
boolean forward() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the packet for this method is sent with UDP instead of TCP.
|
||||||
|
* UDP is faster, but is prone to packet loss and duplication.
|
||||||
|
*/
|
||||||
|
boolean unreliable() default false;
|
||||||
|
|
||||||
|
/** The simple class name where this method is placed. */
|
||||||
|
String in() default "Call";
|
||||||
|
|
||||||
|
/** Priority of this event. */
|
||||||
|
PacketPriority priority() default PacketPriority.normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies that this method will be used to write classes of the type returned by {@link #value()}.<br>
|
||||||
|
* This method must return void and have two parameters, the first being of type {@link java.nio.ByteBuffer} and the second
|
||||||
|
* being the type returned by {@link #value()}.
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
public @interface WriteClass{
|
||||||
|
Class<?> value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies that this method will be used to read classes of the type returned by {@link #value()}. <br>
|
||||||
|
* This method must return the type returned by {@link #value()},
|
||||||
|
* and have one parameter, being of type {@link java.nio.ByteBuffer}.
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
public @interface ReadClass{
|
||||||
|
Class<?> value();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/** Represents a class witha list method entries to include in it. */
|
||||||
|
public class ClassEntry{
|
||||||
|
/** All methods in this generated class. */
|
||||||
|
public final ArrayList<MethodEntry> methods = new ArrayList<>();
|
||||||
|
/** Simple class name. */
|
||||||
|
public final String name;
|
||||||
|
|
||||||
|
public ClassEntry(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import io.anuke.annotations.Annotations.ReadClass;
|
||||||
|
import io.anuke.annotations.Annotations.WriteClass;
|
||||||
|
|
||||||
|
import javax.annotation.processing.RoundEnvironment;
|
||||||
|
import javax.lang.model.element.Element;
|
||||||
|
import javax.lang.model.type.MirroredTypeException;
|
||||||
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class finds reader and writer methods annotated by the {@link io.anuke.annotations.Annotations.WriteClass}
|
||||||
|
* and {@link io.anuke.annotations.Annotations.ReadClass} annotations.
|
||||||
|
*/
|
||||||
|
public class IOFinder{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all class serializers for all types and returns them. Logs errors when necessary.
|
||||||
|
* Maps fully qualified class names to their serializers.
|
||||||
|
*/
|
||||||
|
public HashMap<String, ClassSerializer> findSerializers(RoundEnvironment env){
|
||||||
|
HashMap<String, ClassSerializer> result = new HashMap<>();
|
||||||
|
|
||||||
|
//get methods with the types
|
||||||
|
Set<? extends Element> writers = env.getElementsAnnotatedWith(WriteClass.class);
|
||||||
|
Set<? extends Element> readers = env.getElementsAnnotatedWith(ReadClass.class);
|
||||||
|
|
||||||
|
//look for writers first
|
||||||
|
for(Element writer : writers){
|
||||||
|
WriteClass writean = writer.getAnnotation(WriteClass.class);
|
||||||
|
String typeName = getValue(writean);
|
||||||
|
|
||||||
|
//make sure there's only one read method
|
||||||
|
if(readers.stream().filter(elem -> getValue(elem.getAnnotation(ReadClass.class)).equals(typeName)).count() > 1){
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "Multiple writer methods for type '" + typeName + "'", writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//make sure there's only one write method
|
||||||
|
long count = readers.stream().filter(elem -> getValue(elem.getAnnotation(ReadClass.class)).equals(typeName)).count();
|
||||||
|
if(count == 0){
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "Writer method does not have an accompanying reader: ", writer);
|
||||||
|
}else if(count > 1){
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "Writer method has multiple reader for type: ", writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Element reader = readers.stream().filter(elem -> getValue(elem.getAnnotation(ReadClass.class)).equals(typeName)).findFirst().get();
|
||||||
|
|
||||||
|
//add to result list
|
||||||
|
result.put(typeName, new ClassSerializer(Utils.getMethodName(reader), Utils.getMethodName(writer), typeName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getValue(WriteClass write){
|
||||||
|
try{
|
||||||
|
Class<?> type = write.value();
|
||||||
|
return type.getName();
|
||||||
|
}catch(MirroredTypeException e){
|
||||||
|
return e.getTypeMirror().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getValue(ReadClass read){
|
||||||
|
try{
|
||||||
|
Class<?> type = read.value();
|
||||||
|
return type.getName();
|
||||||
|
}catch(MirroredTypeException e){
|
||||||
|
return e.getTypeMirror().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Information about read/write methods for a specific class type. */
|
||||||
|
public static class ClassSerializer{
|
||||||
|
/** Fully qualified method name of the reader. */
|
||||||
|
public final String readMethod;
|
||||||
|
/** Fully qualified method name of the writer. */
|
||||||
|
public final String writeMethod;
|
||||||
|
/** Fully qualified class type name. */
|
||||||
|
public final String classType;
|
||||||
|
|
||||||
|
public ClassSerializer(String readMethod, String writeMethod, String classType){
|
||||||
|
this.readMethod = readMethod;
|
||||||
|
this.writeMethod = writeMethod;
|
||||||
|
this.classType = classType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
|
import io.anuke.annotations.Annotations.PacketPriority;
|
||||||
|
import io.anuke.annotations.Annotations.Variant;
|
||||||
|
|
||||||
|
import javax.lang.model.element.ExecutableElement;
|
||||||
|
|
||||||
|
/** Class that repesents a remote method to be constructed and put into a class. */
|
||||||
|
public class MethodEntry{
|
||||||
|
/** Simple target class name. */
|
||||||
|
public final String className;
|
||||||
|
/** Fully qualified target method to call. */
|
||||||
|
public final String targetMethod;
|
||||||
|
/** Whether this method can be called on a client/server. */
|
||||||
|
public final Loc where;
|
||||||
|
/**
|
||||||
|
* Whether an additional 'one' and 'all' method variant is generated. At least one of these must be true.
|
||||||
|
* Only applicable to client (server-invoked) methods.
|
||||||
|
*/
|
||||||
|
public final Variant target;
|
||||||
|
/** Whether this method is called locally as well as remotely. */
|
||||||
|
public final Loc local;
|
||||||
|
/** Whether this method is unreliable and uses UDP. */
|
||||||
|
public final boolean unreliable;
|
||||||
|
/** Whether to forward this method call to all other clients when a client invokes it. Server only. */
|
||||||
|
public final boolean forward;
|
||||||
|
/** Unique method ID. */
|
||||||
|
public final int id;
|
||||||
|
/** The element method associated with this entry. */
|
||||||
|
public final ExecutableElement element;
|
||||||
|
/** The assigned packet priority. Only used in clients. */
|
||||||
|
public final PacketPriority priority;
|
||||||
|
|
||||||
|
public MethodEntry(String className, String targetMethod, Loc where, Variant target,
|
||||||
|
Loc local, boolean unreliable, boolean forward, int id, ExecutableElement element, PacketPriority priority){
|
||||||
|
this.className = className;
|
||||||
|
this.forward = forward;
|
||||||
|
this.targetMethod = targetMethod;
|
||||||
|
this.where = where;
|
||||||
|
this.target = target;
|
||||||
|
this.local = local;
|
||||||
|
this.id = id;
|
||||||
|
this.element = element;
|
||||||
|
this.unreliable = unreliable;
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode(){
|
||||||
|
return targetMethod.hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import com.squareup.javapoet.FieldSpec;
|
||||||
|
import com.squareup.javapoet.JavaFile;
|
||||||
|
import com.squareup.javapoet.TypeSpec;
|
||||||
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
|
import io.anuke.annotations.IOFinder.ClassSerializer;
|
||||||
|
|
||||||
|
import javax.annotation.processing.*;
|
||||||
|
import javax.lang.model.SourceVersion;
|
||||||
|
import javax.lang.model.element.Element;
|
||||||
|
import javax.lang.model.element.ExecutableElement;
|
||||||
|
import javax.lang.model.element.Modifier;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
/** The annotation processor for generating remote method call code. */
|
||||||
|
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||||
|
@SupportedAnnotationTypes({
|
||||||
|
"io.anuke.annotations.Annotations.Remote",
|
||||||
|
"io.anuke.annotations.Annotations.WriteClass",
|
||||||
|
"io.anuke.annotations.Annotations.ReadClass",
|
||||||
|
})
|
||||||
|
public class RemoteMethodAnnotationProcessor extends AbstractProcessor{
|
||||||
|
/** Maximum size of each event packet. */
|
||||||
|
public static final int maxPacketSize = 4096;
|
||||||
|
/** Name of the base package to put all the generated classes. */
|
||||||
|
private static final String packageName = "io.anuke.mindustry.gen";
|
||||||
|
|
||||||
|
/** Name of class that handles reading and invoking packets on the server. */
|
||||||
|
private static final String readServerName = "RemoteReadServer";
|
||||||
|
/** Name of class that handles reading and invoking packets on the client. */
|
||||||
|
private static final String readClientName = "RemoteReadClient";
|
||||||
|
|
||||||
|
/** Processing round number. */
|
||||||
|
private int round;
|
||||||
|
|
||||||
|
//class serializers
|
||||||
|
private HashMap<String, ClassSerializer> serializers;
|
||||||
|
//all elements with the Remote annotation
|
||||||
|
private Set<? extends Element> elements;
|
||||||
|
//map of all classes to generate by name
|
||||||
|
private HashMap<String, ClassEntry> classMap;
|
||||||
|
//list of all method entries
|
||||||
|
private ArrayList<MethodEntry> methods;
|
||||||
|
//list of all method entries
|
||||||
|
private ArrayList<ClassEntry> classes;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void init(ProcessingEnvironment processingEnv){
|
||||||
|
super.init(processingEnv);
|
||||||
|
//put all relevant utils into utils class
|
||||||
|
Utils.typeUtils = processingEnv.getTypeUtils();
|
||||||
|
Utils.elementUtils = processingEnv.getElementUtils();
|
||||||
|
Utils.filer = processingEnv.getFiler();
|
||||||
|
Utils.messager = processingEnv.getMessager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv){
|
||||||
|
if(round > 1) return false; //only process 2 rounds
|
||||||
|
|
||||||
|
round++;
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
//round 1: find all annotations, generate *writers*
|
||||||
|
if(round == 1){
|
||||||
|
//get serializers
|
||||||
|
serializers = new IOFinder().findSerializers(roundEnv);
|
||||||
|
|
||||||
|
//last method ID used
|
||||||
|
int lastMethodID = 0;
|
||||||
|
//find all elements with the Remote annotation
|
||||||
|
elements = roundEnv.getElementsAnnotatedWith(Remote.class);
|
||||||
|
//map of all classes to generate by name
|
||||||
|
classMap = new HashMap<>();
|
||||||
|
//list of all method entries
|
||||||
|
methods = new ArrayList<>();
|
||||||
|
//list of all method entries
|
||||||
|
classes = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Element> orderedElements = new ArrayList<>(elements);
|
||||||
|
orderedElements.sort(Comparator.comparing(Object::toString));
|
||||||
|
|
||||||
|
//create methods
|
||||||
|
for(Element element : orderedElements){
|
||||||
|
Remote annotation = element.getAnnotation(Remote.class);
|
||||||
|
|
||||||
|
//check for static
|
||||||
|
if(!element.getModifiers().contains(Modifier.STATIC) || !element.getModifiers().contains(Modifier.PUBLIC)){
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "All @Remote methods must be public and static: ", element);
|
||||||
|
}
|
||||||
|
|
||||||
|
//can't generate none methods
|
||||||
|
if(annotation.targets() == Loc.none){
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "A @Remote method's targets() cannot be equal to 'none':", element);
|
||||||
|
}
|
||||||
|
|
||||||
|
//get and create class entry if needed
|
||||||
|
if(!classMap.containsKey(annotation.in())){
|
||||||
|
ClassEntry clas = new ClassEntry(annotation.in());
|
||||||
|
classMap.put(annotation.in(), clas);
|
||||||
|
classes.add(clas);
|
||||||
|
|
||||||
|
Utils.messager.printMessage(Kind.NOTE, "Generating class '" + clas.name + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassEntry entry = classMap.get(annotation.in());
|
||||||
|
|
||||||
|
//create and add entry
|
||||||
|
MethodEntry method = new MethodEntry(entry.name, Utils.getMethodName(element), annotation.targets(), annotation.variants(),
|
||||||
|
annotation.called(), annotation.unreliable(), annotation.forward(), lastMethodID++, (ExecutableElement) element, annotation.priority());
|
||||||
|
|
||||||
|
entry.methods.add(method);
|
||||||
|
methods.add(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
//create read/write generators
|
||||||
|
RemoteWriteGenerator writegen = new RemoteWriteGenerator(serializers);
|
||||||
|
|
||||||
|
//generate the methods to invoke (write)
|
||||||
|
writegen.generateFor(classes, packageName);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}else if(round == 2){ //round 2: generate all *readers*
|
||||||
|
RemoteReadGenerator readgen = new RemoteReadGenerator(serializers);
|
||||||
|
|
||||||
|
//generate server readers
|
||||||
|
readgen.generateFor(methods.stream().filter(method -> method.where.isClient).collect(Collectors.toList()), readServerName, packageName, true);
|
||||||
|
//generate client readers
|
||||||
|
readgen.generateFor(methods.stream().filter(method -> method.where.isServer).collect(Collectors.toList()), readClientName, packageName, false);
|
||||||
|
|
||||||
|
//create class for storing unique method hash
|
||||||
|
TypeSpec.Builder hashBuilder = TypeSpec.classBuilder("MethodHash").addModifiers(Modifier.PUBLIC);
|
||||||
|
hashBuilder.addField(FieldSpec.builder(int.class, "HASH", Modifier.STATIC, Modifier.PUBLIC, Modifier.FINAL)
|
||||||
|
.initializer("$1L", Objects.hash(methods)).build());
|
||||||
|
|
||||||
|
//build and write resulting hash class
|
||||||
|
TypeSpec spec = hashBuilder.build();
|
||||||
|
JavaFile.builder(packageName, spec).build().writeTo(Utils.filer);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import com.squareup.javapoet.*;
|
||||||
|
import io.anuke.annotations.IOFinder.ClassSerializer;
|
||||||
|
|
||||||
|
import javax.lang.model.element.Modifier;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.lang.model.element.VariableElement;
|
||||||
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** Generates code for reading remote invoke packets on the client and server. */
|
||||||
|
public class RemoteReadGenerator{
|
||||||
|
private final HashMap<String, ClassSerializer> serializers;
|
||||||
|
|
||||||
|
/** Creates a read generator that uses the supplied serializer setup. */
|
||||||
|
public RemoteReadGenerator(HashMap<String, ClassSerializer> serializers){
|
||||||
|
this.serializers = serializers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a class for reading remote invoke packets.
|
||||||
|
*
|
||||||
|
* @param entries List of methods to use/
|
||||||
|
* @param className Simple target class name.
|
||||||
|
* @param packageName Full target package name.
|
||||||
|
* @param needsPlayer Whether this read method requires a reference to the player sender.
|
||||||
|
*/
|
||||||
|
public void generateFor(List<MethodEntry> entries, String className, String packageName, boolean needsPlayer)
|
||||||
|
throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, IOException{
|
||||||
|
|
||||||
|
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC);
|
||||||
|
|
||||||
|
//create main method builder
|
||||||
|
MethodSpec.Builder readMethod = MethodSpec.methodBuilder("readPacket")
|
||||||
|
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||||
|
.addParameter(ByteBuffer.class, "buffer") //buffer to read form
|
||||||
|
.addParameter(int.class, "id") //ID of method type to read
|
||||||
|
.returns(void.class);
|
||||||
|
|
||||||
|
if(needsPlayer){
|
||||||
|
//since the player type isn't loaded yet, creating a type def is necessary
|
||||||
|
//this requires reflection since the TypeName constructor is private for some reason
|
||||||
|
Constructor<TypeName> cons = TypeName.class.getDeclaredConstructor(String.class);
|
||||||
|
cons.setAccessible(true);
|
||||||
|
|
||||||
|
TypeName playerType = cons.newInstance("io.anuke.mindustry.entities.Player");
|
||||||
|
//add player parameter
|
||||||
|
readMethod.addParameter(playerType, "player");
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeBlock.Builder readBlock = CodeBlock.builder(); //start building block of code inside read method
|
||||||
|
boolean started = false; //whether an if() statement has been written yet
|
||||||
|
|
||||||
|
for(MethodEntry entry : entries){
|
||||||
|
//write if check for this entry ID
|
||||||
|
if(!started){
|
||||||
|
started = true;
|
||||||
|
readBlock.beginControlFlow("if(id == " + entry.id + ")");
|
||||||
|
}else{
|
||||||
|
readBlock.nextControlFlow("else if(id == " + entry.id + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
readBlock.beginControlFlow("try");
|
||||||
|
|
||||||
|
//concatenated list of variable names for method invocation
|
||||||
|
StringBuilder varResult = new StringBuilder();
|
||||||
|
|
||||||
|
//go through each parameter
|
||||||
|
for(int i = 0; i < entry.element.getParameters().size(); i++){
|
||||||
|
VariableElement var = entry.element.getParameters().get(i);
|
||||||
|
|
||||||
|
if(!needsPlayer || i != 0){ //if client, skip first parameter since it's always of type player and doesn't need to be read
|
||||||
|
//full type name of parameter
|
||||||
|
String typeName = var.asType().toString();
|
||||||
|
//name of parameter
|
||||||
|
String varName = var.getSimpleName().toString();
|
||||||
|
//captialized version of type name for reading primitives
|
||||||
|
String capName = typeName.equals("byte") ? "" : Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1);
|
||||||
|
|
||||||
|
//write primitives automatically
|
||||||
|
if(Utils.isPrimitive(typeName)){
|
||||||
|
if(typeName.equals("boolean")){
|
||||||
|
readBlock.addStatement("boolean " + varName + " = buffer.get() == 1");
|
||||||
|
}else{
|
||||||
|
readBlock.addStatement(typeName + " " + varName + " = buffer.get" + capName + "()");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//else, try and find a serializer
|
||||||
|
ClassSerializer ser = serializers.get(typeName);
|
||||||
|
|
||||||
|
if(ser == null){ //make sure a serializer exists!
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "No @ReadClass method to read class type: '" + typeName + "'", var);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//add statement for reading it
|
||||||
|
readBlock.addStatement(typeName + " " + varName + " = " + ser.readMethod + "(buffer)");
|
||||||
|
}
|
||||||
|
|
||||||
|
//append variable name to string builder
|
||||||
|
varResult.append(var.getSimpleName());
|
||||||
|
if(i != entry.element.getParameters().size() - 1) varResult.append(", ");
|
||||||
|
}else{
|
||||||
|
varResult.append("player");
|
||||||
|
if(i != entry.element.getParameters().size() - 1) varResult.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//execute the relevant method before the forward
|
||||||
|
//if it throws a ValidateException, the method won't be forwarded
|
||||||
|
readBlock.addStatement("$N." + entry.element.getSimpleName() + "(" + varResult.toString() + ")", ((TypeElement) entry.element.getEnclosingElement()).getQualifiedName().toString());
|
||||||
|
|
||||||
|
//call forwarded method, don't forward on the client reader
|
||||||
|
if(entry.forward && entry.where.isServer && needsPlayer){
|
||||||
|
//call forwarded method
|
||||||
|
readBlock.addStatement(packageName + "." + entry.className + "." + entry.element.getSimpleName() +
|
||||||
|
"__forward(player.con.id" + (varResult.length() == 0 ? "" : ", ") + varResult.toString() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
readBlock.nextControlFlow("catch (java.lang.Exception e)");
|
||||||
|
readBlock.addStatement("throw new java.lang.RuntimeException(\"Failed to to read remote method '" + entry.element.getSimpleName() + "'!\", e)");
|
||||||
|
readBlock.endControlFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
//end control flow if necessary
|
||||||
|
if(started){
|
||||||
|
readBlock.nextControlFlow("else");
|
||||||
|
readBlock.addStatement("throw new $1N(\"Invalid read method ID: \" + id + \"\")", RuntimeException.class.getName()); //handle invalid method IDs
|
||||||
|
readBlock.endControlFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
//add block and method to class
|
||||||
|
readMethod.addCode(readBlock.build());
|
||||||
|
classBuilder.addMethod(readMethod.build());
|
||||||
|
|
||||||
|
//build and write resulting class
|
||||||
|
TypeSpec spec = classBuilder.build();
|
||||||
|
JavaFile.builder(packageName, spec).build().writeTo(Utils.filer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,226 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import com.squareup.javapoet.*;
|
||||||
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
|
import io.anuke.annotations.IOFinder.ClassSerializer;
|
||||||
|
|
||||||
|
import javax.lang.model.element.ExecutableElement;
|
||||||
|
import javax.lang.model.element.Modifier;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.lang.model.element.VariableElement;
|
||||||
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** Generates code for writing remote invoke packets on the client and server. */
|
||||||
|
public class RemoteWriteGenerator{
|
||||||
|
private final HashMap<String, ClassSerializer> serializers;
|
||||||
|
|
||||||
|
/** Creates a write generator that uses the supplied serializer setup. */
|
||||||
|
public RemoteWriteGenerator(HashMap<String, ClassSerializer> serializers){
|
||||||
|
this.serializers = serializers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Generates all classes in this list. */
|
||||||
|
public void generateFor(List<ClassEntry> entries, String packageName) throws IOException{
|
||||||
|
|
||||||
|
for(ClassEntry entry : entries){
|
||||||
|
//create builder
|
||||||
|
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(entry.name).addModifiers(Modifier.PUBLIC);
|
||||||
|
|
||||||
|
//add temporary write buffer
|
||||||
|
classBuilder.addField(FieldSpec.builder(ByteBuffer.class, "TEMP_BUFFER", Modifier.STATIC, Modifier.PRIVATE, Modifier.FINAL)
|
||||||
|
.initializer("ByteBuffer.allocate($1L)", RemoteMethodAnnotationProcessor.maxPacketSize).build());
|
||||||
|
|
||||||
|
//go through each method entry in this class
|
||||||
|
for(MethodEntry methodEntry : entry.methods){
|
||||||
|
//write the 'send event to all players' variant: always happens for clients, but only happens if 'all' is enabled on the server method
|
||||||
|
if(methodEntry.where.isClient || methodEntry.target.isAll){
|
||||||
|
writeMethodVariant(classBuilder, methodEntry, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//write the 'send event to one player' variant, which is only applicable on the server
|
||||||
|
if(methodEntry.where.isServer && methodEntry.target.isOne){
|
||||||
|
writeMethodVariant(classBuilder, methodEntry, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//write the forwarded method version
|
||||||
|
if(methodEntry.where.isServer && methodEntry.forward){
|
||||||
|
writeMethodVariant(classBuilder, methodEntry, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//build and write resulting class
|
||||||
|
TypeSpec spec = classBuilder.build();
|
||||||
|
JavaFile.builder(packageName, spec).build().writeTo(Utils.filer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a specific variant for a method entry. */
|
||||||
|
private void writeMethodVariant(TypeSpec.Builder classBuilder, MethodEntry methodEntry, boolean toAll, boolean forwarded){
|
||||||
|
ExecutableElement elem = methodEntry.element;
|
||||||
|
|
||||||
|
//create builder
|
||||||
|
MethodSpec.Builder method = MethodSpec.methodBuilder(elem.getSimpleName().toString() + (forwarded ? "__forward" : "")) //add except suffix when forwarding
|
||||||
|
.addModifiers(Modifier.STATIC, Modifier.SYNCHRONIZED)
|
||||||
|
.returns(void.class);
|
||||||
|
|
||||||
|
//forwarded methods aren't intended for use, and are not public
|
||||||
|
if(!forwarded){
|
||||||
|
method.addModifiers(Modifier.PUBLIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
//validate client methods to make sure
|
||||||
|
if(methodEntry.where.isClient){
|
||||||
|
if(elem.getParameters().isEmpty()){
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "Client invoke methods must have a first parameter of type Player.", elem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!elem.getParameters().get(0).asType().toString().equals("io.anuke.mindustry.entities.Player")){
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "Client invoke methods should have a first parameter of type Player.", elem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if toAll is false, it's a 'send to one player' variant, so add the player as a parameter
|
||||||
|
if(!toAll){
|
||||||
|
method.addParameter(int.class, "playerClientID");
|
||||||
|
}
|
||||||
|
|
||||||
|
//add sender to ignore
|
||||||
|
if(forwarded){
|
||||||
|
method.addParameter(int.class, "exceptSenderID");
|
||||||
|
}
|
||||||
|
|
||||||
|
//call local method if applicable, shouldn't happen when forwarding method as that already happens by default
|
||||||
|
if(!forwarded && methodEntry.local != Loc.none){
|
||||||
|
//add in local checks
|
||||||
|
if(methodEntry.local != Loc.both){
|
||||||
|
method.beginControlFlow("if(" + getCheckString(methodEntry.local) + " || !io.anuke.mindustry.net.Net.active())");
|
||||||
|
}
|
||||||
|
|
||||||
|
//concatenate parameters
|
||||||
|
int index = 0;
|
||||||
|
StringBuilder results = new StringBuilder();
|
||||||
|
for(VariableElement var : elem.getParameters()){
|
||||||
|
//special case: calling local-only methods uses the local player
|
||||||
|
if(index == 0 && methodEntry.where == Loc.client){
|
||||||
|
results.append("io.anuke.mindustry.Vars.players[0]");
|
||||||
|
}else{
|
||||||
|
results.append(var.getSimpleName());
|
||||||
|
}
|
||||||
|
if(index != elem.getParameters().size() - 1) results.append(", ");
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//add the statement to call it
|
||||||
|
method.addStatement("$N." + elem.getSimpleName() + "(" + results.toString() + ")",
|
||||||
|
((TypeElement) elem.getEnclosingElement()).getQualifiedName().toString());
|
||||||
|
|
||||||
|
if(methodEntry.local != Loc.both){
|
||||||
|
method.endControlFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//start control flow to check if it's actually client/server so no netcode is called
|
||||||
|
method.beginControlFlow("if(" + getCheckString(methodEntry.where) + ")");
|
||||||
|
|
||||||
|
//add statement to create packet from pool
|
||||||
|
method.addStatement("$1N packet = $2N.obtain($1N.class)", "io.anuke.mindustry.net.Packets.InvokePacket", "io.anuke.ucore.util.Pooling");
|
||||||
|
//assign buffer
|
||||||
|
method.addStatement("packet.writeBuffer = TEMP_BUFFER");
|
||||||
|
//assign priority
|
||||||
|
method.addStatement("packet.priority = (byte)" + methodEntry.priority.ordinal());
|
||||||
|
//assign method ID
|
||||||
|
method.addStatement("packet.type = (byte)" + methodEntry.id);
|
||||||
|
//rewind buffer
|
||||||
|
method.addStatement("TEMP_BUFFER.position(0)");
|
||||||
|
|
||||||
|
for(int i = 0; i < elem.getParameters().size(); i++){
|
||||||
|
//first argument is skipped as it is always the player caller
|
||||||
|
if((!methodEntry.where.isServer/* || methodEntry.mode == Loc.both*/) && i == 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
VariableElement var = elem.getParameters().get(i);
|
||||||
|
|
||||||
|
//add parameter to method
|
||||||
|
method.addParameter(TypeName.get(var.asType()), var.getSimpleName().toString());
|
||||||
|
|
||||||
|
//name of parameter
|
||||||
|
String varName = var.getSimpleName().toString();
|
||||||
|
//name of parameter type
|
||||||
|
String typeName = var.asType().toString();
|
||||||
|
//captialized version of type name for writing primitives
|
||||||
|
String capName = typeName.equals("byte") ? "" : Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1);
|
||||||
|
//special case: method can be called from anywhere to anywhere
|
||||||
|
//thus, only write the player when the SERVER is writing data, since the client is the only one who reads it
|
||||||
|
boolean writePlayerSkipCheck = methodEntry.where == Loc.both && i == 0;
|
||||||
|
|
||||||
|
if(writePlayerSkipCheck){ //write begin check
|
||||||
|
method.beginControlFlow("if(io.anuke.mindustry.net.Net.server())");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Utils.isPrimitive(typeName)){ //check if it's a primitive, and if so write it
|
||||||
|
if(typeName.equals("boolean")){ //booleans are special
|
||||||
|
method.addStatement("TEMP_BUFFER.put(" + varName + " ? (byte)1 : 0)");
|
||||||
|
}else{
|
||||||
|
method.addStatement("TEMP_BUFFER.put" +
|
||||||
|
capName + "(" + varName + ")");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//else, try and find a serializer
|
||||||
|
ClassSerializer ser = serializers.get(typeName);
|
||||||
|
|
||||||
|
if(ser == null){ //make sure a serializer exists!
|
||||||
|
Utils.messager.printMessage(Kind.ERROR, "No @WriteClass method to write class type: '" + typeName + "'", var);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//add statement for writing it
|
||||||
|
method.addStatement(ser.writeMethod + "(TEMP_BUFFER, " + varName + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(writePlayerSkipCheck){ //write end check
|
||||||
|
method.endControlFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//assign packet length
|
||||||
|
method.addStatement("packet.writeLength = TEMP_BUFFER.position()");
|
||||||
|
|
||||||
|
String sendString;
|
||||||
|
|
||||||
|
if(forwarded){ //forward packet
|
||||||
|
if(!methodEntry.local.isClient){ //if the client doesn't get it called locally, forward it back after validation
|
||||||
|
sendString = "send(";
|
||||||
|
}else{
|
||||||
|
sendString = "sendExcept(exceptSenderID, ";
|
||||||
|
}
|
||||||
|
}else if(toAll){ //send to all players / to server
|
||||||
|
sendString = "send(";
|
||||||
|
}else{ //send to specific client from server
|
||||||
|
sendString = "sendTo(playerClientID, ";
|
||||||
|
}
|
||||||
|
|
||||||
|
//send the actual packet
|
||||||
|
method.addStatement("io.anuke.mindustry.net.Net." + sendString + "packet, " +
|
||||||
|
(methodEntry.unreliable ? "io.anuke.mindustry.net.Net.SendMode.udp" : "io.anuke.mindustry.net.Net.SendMode.tcp") + ")");
|
||||||
|
|
||||||
|
|
||||||
|
//end check for server/client
|
||||||
|
method.endControlFlow();
|
||||||
|
|
||||||
|
//add method to class, finally
|
||||||
|
classBuilder.addMethod(method.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCheckString(Loc loc){
|
||||||
|
return loc.isClient && loc.isServer ? "io.anuke.mindustry.net.Net.server() || io.anuke.mindustry.net.Net.client()" :
|
||||||
|
loc.isClient ? "io.anuke.mindustry.net.Net.client()" :
|
||||||
|
loc.isServer ? "io.anuke.mindustry.net.Net.server()" : "false";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import javax.annotation.processing.Filer;
|
||||||
|
import javax.annotation.processing.Messager;
|
||||||
|
import javax.lang.model.element.Element;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
|
public class Utils{
|
||||||
|
public static Types typeUtils;
|
||||||
|
public static Elements elementUtils;
|
||||||
|
public static Filer filer;
|
||||||
|
public static Messager messager;
|
||||||
|
|
||||||
|
public static String getMethodName(Element element){
|
||||||
|
return ((TypeElement) element.getEnclosingElement()).getQualifiedName().toString() + "." + element.getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.0'
|
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.0'
|
||||||
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
|
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
|
||||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
classpath 'com.android.tools.build:gradle:3.1.3'
|
||||||
classpath "com.badlogicgames.gdx:gdx-tools:1.9.8"
|
classpath "com.badlogicgames.gdx:gdx-tools:1.9.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,13 +21,13 @@ allprojects {
|
|||||||
version = 'release'
|
version = 'release'
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
versionNumber = '3.5'
|
versionNumber = '4.0'
|
||||||
versionType = 'release'
|
versionType = 'alpha'
|
||||||
appName = 'Mindustry'
|
appName = 'Mindustry'
|
||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
roboVMVersion = '2.3.0'
|
roboVMVersion = '2.3.0'
|
||||||
aiVersion = '1.8.1'
|
aiVersion = '1.8.1'
|
||||||
uCoreVersion = 'd5af97f93813d8767423521b1fcc5a5e0f7241d9'
|
uCoreVersion = 'c502931313'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
@@ -86,6 +86,7 @@ project(":desktop") {
|
|||||||
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:v2.0.0'
|
compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.0'
|
||||||
|
compile 'com.yuvimasory:orange-extensions:1.3.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +97,8 @@ project(":html") {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(":core")
|
compile project(":core")
|
||||||
|
compileOnly project(":annotations")
|
||||||
|
|
||||||
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
|
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
|
||||||
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
|
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
|
||||||
@@ -107,25 +110,10 @@ project(":html") {
|
|||||||
compile "com.sksamuel.gwt:gwt-websockets:1.0.4"
|
compile "com.sksamuel.gwt:gwt-websockets:1.0.4"
|
||||||
compile "com.sksamuel.gwt:gwt-websockets:1.0.4:sources"
|
compile "com.sksamuel.gwt:gwt-websockets:1.0.4:sources"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
project(":android") {
|
compileJava.options.compilerArgs = [
|
||||||
apply plugin: "android"
|
"-processor", "io.anuke.annotations.RemoteMethodAnnotationProcessor"
|
||||||
|
]
|
||||||
configurations { natives }
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation project(":core")
|
|
||||||
implementation project(":kryonet")
|
|
||||||
implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
|
|
||||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
|
|
||||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
|
|
||||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
|
|
||||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
|
|
||||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
|
|
||||||
implementation "com.badlogicgames.gdx:gdx-ai:$aiVersion"
|
|
||||||
implementation "com.badlogicgames.gdx:gdx-controllers-android:$gdxVersion"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":ios") {
|
project(":ios") {
|
||||||
@@ -142,16 +130,14 @@ project(":ios") {
|
|||||||
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
|
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
|
||||||
}
|
}
|
||||||
|
|
||||||
robovm {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":core") {
|
project(":core") {
|
||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly project(":annotations")
|
||||||
|
|
||||||
boolean comp = System.properties["release"] == null || System.properties["release"] == "false"
|
boolean comp = System.properties["release"] == null || System.properties["release"] == "false"
|
||||||
|
|
||||||
if(!comp){
|
if(!comp){
|
||||||
@@ -160,25 +146,35 @@ project(":core") {
|
|||||||
println("Compiling DEBUG build.")
|
println("Compiling DEBUG build.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if(new File('../uCore').exists() && comp){
|
if(new File(projectDir.parent, '../uCore').exists() && comp){
|
||||||
compile project(":uCore")
|
compile project(":uCore")
|
||||||
}else{
|
}else{
|
||||||
compile "com.github.anuken:ucore:$uCoreVersion"
|
compile "com.github.anuken:ucore:$uCoreVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
if(new File('../GDXGifRecorder').exists() && comp) {
|
if(new File(projectDir.parent, '../GDXGifRecorder').exists() && comp) {
|
||||||
compile project(":GDXGifRecorder")
|
compile project(":GDXGifRecorder")
|
||||||
}
|
}
|
||||||
|
|
||||||
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
|
|
||||||
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileJava.options.compilerArgs = [
|
||||||
|
"-processor", "io.anuke.annotations.RemoteMethodAnnotationProcessor"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":server") {
|
project(":server") {
|
||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
compile.exclude module: android
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly project(":annotations")
|
||||||
|
|
||||||
compile project(":core")
|
compile project(":core")
|
||||||
compile project(":kryonet")
|
compile project(":kryonet")
|
||||||
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
|
||||||
@@ -186,6 +182,22 @@ project(":server") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project(":packer") {
|
||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(":core")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project(":annotations") {
|
||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile 'com.squareup:javapoet:1.11.0'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
project(":kryonet") {
|
project(":kryonet") {
|
||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 207 B |
|
Before Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 206 B |
|
Before Width: | Height: | Size: 315 B |
|
Before Width: | Height: | Size: 378 B |
|
Before Width: | Height: | Size: 182 B |
|
Before Width: | Height: | Size: 281 B |
|
Before Width: | Height: | Size: 281 B |
|
Before Width: | Height: | Size: 402 B |
|
Before Width: | Height: | Size: 514 B |
|
Before Width: | Height: | Size: 258 B |
|
Before Width: | Height: | Size: 237 B |
|
Before Width: | Height: | Size: 256 B |
|
Before Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 300 B |
|
Before Width: | Height: | Size: 274 B |
|
Before Width: | Height: | Size: 254 B |
|
Before Width: | Height: | Size: 290 B |
|
Before Width: | Height: | Size: 222 B |
|
Before Width: | Height: | Size: 199 B |
|
Before Width: | Height: | Size: 191 B |
|
Before Width: | Height: | Size: 195 B |
|
Before Width: | Height: | Size: 195 B |
|
Before Width: | Height: | Size: 246 B |
|
Before Width: | Height: | Size: 266 B |
|
After Width: | Height: | Size: 160 B |
|
After Width: | Height: | Size: 177 B |
|
After Width: | Height: | Size: 178 B |
|
After Width: | Height: | Size: 227 B |
|
After Width: | Height: | Size: 197 B |
|
After Width: | Height: | Size: 296 B |
|
Before Width: | Height: | Size: 257 B After Width: | Height: | Size: 257 B |
|
After Width: | Height: | Size: 682 B |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 233 B |
|
After Width: | Height: | Size: 179 B |
|
After Width: | Height: | Size: 189 B |
|
After Width: | Height: | Size: 172 B |
|
After Width: | Height: | Size: 301 B |
|
Before Width: | Height: | Size: 226 B After Width: | Height: | Size: 226 B |
|
Before Width: | Height: | Size: 248 B After Width: | Height: | Size: 248 B |
|
After Width: | Height: | Size: 234 B |
|
After Width: | Height: | Size: 210 B |
|
After Width: | Height: | Size: 346 B |
|
After Width: | Height: | Size: 492 B |
|
Before Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 428 B |
|
Before Width: | Height: | Size: 397 B |
|
Before Width: | Height: | Size: 254 B |
|
Before Width: | Height: | Size: 224 B |
|
Before Width: | Height: | Size: 308 B |
|
After Width: | Height: | Size: 219 B |
|
After Width: | Height: | Size: 298 B |
|
After Width: | Height: | Size: 289 B |
|
After Width: | Height: | Size: 574 B |
|
After Width: | Height: | Size: 174 B |
|
After Width: | Height: | Size: 196 B |
|
After Width: | Height: | Size: 233 B |
|
After Width: | Height: | Size: 261 B |
|
After Width: | Height: | Size: 286 B |
|
After Width: | Height: | Size: 327 B |
|
After Width: | Height: | Size: 239 B |
|
After Width: | Height: | Size: 341 B |
|
After Width: | Height: | Size: 379 B |
|
After Width: | Height: | Size: 473 B |
|
After Width: | Height: | Size: 461 B |
|
After Width: | Height: | Size: 354 B |
|
After Width: | Height: | Size: 296 B |
|
After Width: | Height: | Size: 678 B |
|
After Width: | Height: | Size: 174 B |
|
After Width: | Height: | Size: 188 B |