Merge branch 'master' into GH-v80

This commit is contained in:
(G_H)
2019-06-23 21:07:06 +08:00
committed by GitHub
1849 changed files with 96454 additions and 39768 deletions

20
.gitignore vendored
View File

@@ -1,7 +1,8 @@
##Packr, build stuff logs/
/core/assets/mindustry-saves/ /core/assets/mindustry-saves/
/core/assets/mindustry-maps/ /core/assets/mindustry-maps/
/core/assets/bundles/output/
/core/assets/.gifimages/
/deploy/ /deploy/
/desktop/packr-out/ /desktop/packr-out/
/desktop/packr-export/ /desktop/packr-export/
@@ -9,13 +10,26 @@
/desktop/mindustry-maps/ /desktop/mindustry-maps/
/desktop/gifexport/ /desktop/gifexport/
/core/lib/ /core/lib/
/core/assets-raw/sprites/generated/
/core/assets-raw/sprites_out/
/annotations/build/ /annotations/build/
/kryonet/build/ /annotations/out/
/net/build/
/tools/build/
/tests/build/
/server/build/ /server/build/
/test_files/
/annotations/build/
/android/assets/mindustry-maps/ /android/assets/mindustry-maps/
/android/assets/mindustry-saves/ /android/assets/mindustry-saves/
/core/assets/gifexport/ /core/assets/gifexport/
/core/assets/version.properties /core/assets/version.properties
/core/assets/locales
/ios/src/io/anuke/mindustry/gen/
/core/src/io/anuke/mindustry/gen/
ios/robovm.properties
packr-out/
config/
*.gif *.gif
version.properties version.properties

View File

@@ -1,23 +1,31 @@
language: android
jdk: jdk:
- openjdk8 - openjdk8
script:
android: - git clone --depth=1 --branch=master https://github.com/Anuken/Arc ../Arc
components: - "./gradlew test"
- android-26 - "./gradlew desktop:dist -Pbuildversion=${TRAVIS_TAG:1}"
- "./gradlew server:dist -Pbuildversion=${TRAVIS_TAG:1}"
# Additional components - git config --global user.name "Wiki Updater"
- extra-google-google_play_services - git clone --depth=1 --branch=master https://github.com/MindustryGame/wiki ../wiki
- extra-google-m2repository - git clone --depth=1 --branch=master https://github.com/Anuken/Mindustry-Wiki-Generator ../Mindustry-Wiki-Generator
- extra-android-m2repository - cd ../Mindustry-Wiki-Generator
- addon-google_apis-google-26 - "./gradlew run"
- cd ../wiki
script: - git add .
- ./gradlew desktop:dist - git commit -m "Update to match commit ${TRAVIS_COMMIT}"
- git push https://Anuken:${GH_PUSH_TOKEN}@github.com/MindustryGame/wiki
after_success: deploy:
- chmod +x upload-build.sh provider: releases
- chmod +x cleanup_builds.sh skip_cleanup: true
- ./upload-build.sh draft: false
api_key:
secure: Cv5wFtWt62/A24EvSEQvMow7gKPbZ3oATEFPuSghhB2TQz1dA40Zee3Qvk4LFlpLrhYo4K0ZSczCZRGpR+hCd8+Dpww52bheYEvWuh3ZQfvu/fXtEx2j5PwP1qMpmIgSxETV/gkD7l9FImdh0VzktYiAvQfmi0bEocG9/D4QwjFpNat7iwBdcMiw1MvAygpdIWRsjiw0RKlB2mWarmoHhQ7Gu7qlU3j50uaEvcrtmU0pBUPggNQwQRv32i9NPvNFxrqqlUjDLIS8JFea99zCkp8BwYqbEvBIMzd+Qip1/stLJJA3+cDUClbsDtg8rAVetzpOrdLEEBmqShFe5MDl2yEHcsgpN9CFsyTaUfvB3P3rVjizvycMm42IsUkXQiarm5xTQ/TIA8Rd8AHiSKuweNCg1Fd5SFaRtKy8JVLXuxyfUccmyje6hhz2L4lS2Wfj3mAG7sqZUCXhWP79EKdGkiPOjKv4CwXEKmuH3BMVqPlNUZJr9Eg3sV1FG0h2l+MVOOnR635qdUbb49sYojYxVruMLX0BH1c4ZCu230m8CUoWA1Em1QNI75ya7+9Y5T6AsgWDVpBvdUo9fWNbdp+VQ0GskFQsJD5wtnxbcbHeFiERAgGBm7z6qt9u9LrQpBH+dsW52ADvYsu3L4nQEa+sdMHwTTwmGY+iUvsxu0DqxGg=
file:
- desktop/build/libs/desktop-release.jar
- server/build/libs/server-release.jar
on:
repo: Anuken/Mindustry
tags: true
env:
global:
secure: TqlUl/ojjkCMVOGbCTKz7Cnr4F08UyWzY/CiJ0vvUOGJGZ1qm7XavAlDf5XT0egU4mvr37THubFO8vojbqmrmy0oZnYh3njKFA8axgyZ8PyKkjGHOfd0i6qyEWsOr9H90/2X8r3LwEeLaDFyHpu3wljIGBjweg53g2qwmDwCFa9UR80FJZ+xDB+rD6B3cXT0DTEkCoLZXLqXm0Y3HvBdSuBL1LR/FNb2BSxNq+tNLGiz1kdQZV5erausbbZypBoGxzz63xAnyz2kkFz73A8xQYVTzGbFodTPz7HM13GVZ5s43I03Y+HYyHBgBaSLziO2hi2kzVJccOwzBp7wS4fs1MqsFY5+IeWJ9k+hm89NiYT7+6zlEgoUMlIniny1qLqWTzx7btUeuC/y/h5TVBNgaV+z0jmHycHfeSyq5I+vmX4J8qe3wmaN8TcdqYKU5nIznOTk3CM5Fzu0Bs9vkCkOxmormmcjMFW1RbdOLc/hpZWZggsBA88sNEAI8eq+r5QEeqzeCx8YKoZDjdrsqvgLMc3El3gS9oMGxkn0Y/TEcqs9Tc4BXtTkqIA68hD0DYzlAxYjVbbkAI9Hh9lHNvV3Dr/oCkGXQ/HflM143kj1L3tSBZpqeqQE2XhngB5nqpS3OZTmZbMTQ8qD2luU18yaTGMLF5tJS/fdKPRx0gQ1kL8=

View File

@@ -1,41 +1,45 @@
![Imgur](https://i.imgur.com/w4N0yhv.png) ![Imgur](https://i.imgur.com/w4N0yhv.png)
[![Build Status](https://travis-ci.org/Anuken/Mindustry.svg?branch=master)](https://travis-ci.org/Anuken/Mindustry) [![Build Status](https://travis-ci.org/Anuken/Mindustry.svg?branch=master)](https://travis-ci.org/Anuken/Mindustry)
[![Waffle.io - Columns and their card count](https://badge.waffle.io/Anuken/Mindustry.svg?columns=all)](https://waffle.io/Anuken/Mindustry) [![Discord](https://img.shields.io/discord/391020510269669376.svg)](https://discord.gg/mindustry)
A pixelated sandbox tower defense game made using [LibGDX](https://libgdx.badlogicgames.com/). Winner of the [GDL Metal Monstrosity Jam](https://itch.io/jam/gdl---metal-monstrosity-jam). A sandbox tower defense game written in Java.
_[Issue tracker](https://waffle.io/Anuken/Mindustry)_
_[Trello Board](https://trello.com/b/aE2tcUwF/mindustry-40-plans)_ _[Trello Board](https://trello.com/b/aE2tcUwF/mindustry-40-plans)_
_[Wiki](http://mindustry.wikia.com/wiki/Mindustry_Wiki)_ _[Wiki](http://mindustry.wikia.com/wiki/Mindustry_Wiki)_
_[Discord](https://discord.gg/r8BkXNd)_
### Building ### Building
Bleeding-edge live builds are generated automatically for every commit. You can see them [here](https://github.com/Anuken/Mindustry/wiki). Bleeding-edge live builds are generated automatically for every commit. You can see them [here](https://jenkins.hellomouse.net/job/mindustry/).
If you'd rather compile on your own, follow these instructions. If you'd rather compile on your own, follow these instructions.
First, make sure you have Java 8 and JDK 8 installed. Open a terminal in the root directory, and run the following commands: First, make sure you have Java 8 and JDK 8 installed. Open a terminal in the root directory, `cd` to the Mindustry folder and run the following commands:
#### Windows
**_Windows_** _Running:_ `gradlew desktop:run`
_Building:_ `gradlew desktop:dist`
_Running:_ `gradlew.bat desktop:run` #### Linux/Mac OS
_Building:_ `gradlew.bat desktop:dist`
**_Linux_**
_Running:_ `./gradlew desktop:run` _Running:_ `./gradlew desktop:run`
_Building:_ `./gradlew desktop:dist` _Building:_ `./gradlew desktop:dist`
#### Server
Server builds are bundled with each released build (in Releases). If you'd rather compile on your own, replace 'desktop' with 'server', e.g. `gradlew server:dist`.
##### Troubleshooting
If the terminal returns `Permission denied` or `Command not found` on Mac/Linux, run `chmod +x ./gradlew` before running `./gradlew`. *This is a one-time procedure.*
--- ---
Gradle may take up to several minutes to download files. Be patient. <br> Gradle may take up to several minutes to download files. Be patient. <br>
After building, the output .JAR file should be in the output JAR file should be in `/desktop/build/libs/desktop-release.jar.` After building, the output .JAR file should be in `/desktop/build/libs/desktop-release.jar` for desktop builds, and in `/server/build/libs/server-release.jar` for server builds.
### Downloads ### Downloads
<a href="https://anuke.itch.io/mindustry"><img src="https://i.imgur.com/sk26hTV.png" width="auto" height="75"></a> <a href="https://anuke.itch.io/mindustry"><img src="https://static.itch.io/images/badge.svg" width="auto" height="75"></a>
<a href="https://play.google.com/store/apps/details?id=io.anuke.mindustry&hl=en"><img src="https://i.imgur.com/8dF6l81.png" width="auto" height="75"></a> <a href="https://play.google.com/store/apps/details?id=io.anuke.mindustry&hl=en"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Get_it_on_Google_play.svg/1280px-Get_it_on_Google_play.svg.png" width="auto" height="75"></a>

39
TRANSLATING.md Normal file
View File

@@ -0,0 +1,39 @@
## Translating for Mindustry
**DISCLAIMER:** *Currently, 4.0 is far from done, which means that things such as block names, descriptions, and core text will be changing often. If you begin translating now, you might have to re-do large chunks of the bundle before final release.*
To begin, log in to your GitHub account, or if you don't have one yet, create it [here](https://github.com/).
Consult [this list](https://www.science.co.il/language/Locale-codes.php) to find the locale code for your language. Once you've found it,
head over to the translation bundle folder and check the [list of bundles](https://github.com/Anuken/Mindustry/tree/master/core/assets/bundles) that have already been created.
You're looking for a file called "`bundle_`(insert locale code here)`.properties`". If you don't find one, create one manually (more info below).
#### Editing an existing translation
If a translation bundle already exists, that means someone has already started working on a translation. To edit it or translate text, simply click the file and press the edit (pencil) button in the top right. Once you're done editing, press the green "propose file change" button at the bottom, then "create pull request" (twice).
Once this is done, all you need to do is wait for me to approve your changes.
#### Creating a new translation bundle
If a translation bundle for your language *doesn't* exist, you need to create one yourself.
In the folder with all the bundles in it, click the *'create new file'* button, and name it `bundle_(locale code here).properties`.
Then, copy-paste the entire contents of the [English translation bundle](https://raw.githubusercontent.com/Anuken/Mindustry/master/core/assets/bundles/bundle.properties) into the file, and translate all the necessary text to your language.
Once you are done, press the *propose new file* button at the bottom, then 'create pull request' twice.
#### Useful Information
- When you see text surrounded by square brackets, such as `[RED]`, `[]` or `[accent]`, this indicates a color code. Don't translate it.
- `{0}` means an argument that will be replaced when the text is displayed. For example, `Wave: {0}` will replace the `{0}` with whatever wave you are in.
- Empty lines are fine, and it doesn't matter in what order you place the text.
- `\n` means "new line". If you want to split text into multiple lines, use `\n` to do it.
#### Testing your translation bundle
There are two ways to test the translation bundle:
1) Assuming you have the PC version downloaded, download your bundle file, name it `bundle.properties`, then place it in the same folder as the Mindustry desktop executable and run it. *You should get a popup message in-game confirming that you have loaded an external translation.*
2) For advanced users: simply download your fork of mindustry and compile/run the game.
**And that's it.**
*(...of course, that's never really it. Bother me on Discord when something inevitably goes wrong.)*

View File

@@ -1,33 +1,65 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.anuke.mindustry"> package="io.anuke.mindustry">
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <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"
<activity android:appCategory="game"
android:name="io.anuke.mindustry.AndroidLauncher"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="sensorLandscape" android:theme="@style/GdxTheme" android:fullBackupContent="@xml/backup_rules">
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> <meta-data android:name="android.max_aspect" android:value="2.1"/>
<activity
android:name="io.anuke.mindustry.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="user"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout">
<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>
<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> </intent-filter>
</activity> </activity>
<activity android:name=".DonationsActivity"
android:theme="@style/GdxTheme" />
</application> </application>
</manifest> </manifest>

View File

@@ -1,31 +1,59 @@
buildscript{
repositories{
mavenLocal()
mavenCentral()
google()
maven{ url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
repositories { dependencies{
mavenCentral() classpath 'com.android.tools.build:gradle:3.4.1'
jcenter()
maven {
url "https://maven.google.com"
} }
} }
dependencies { apply plugin: "com.android.application"
implementation 'com.android.support:support-v4:22.1.1'
implementation 'org.sufficientlysecure:donations:2.5' configurations{ natives }
implementation 'com.google.android.gms:play-services-auth:11.8.0'
repositories{
mavenCentral()
jcenter()
maven{
url "https://maven.google.com"
}
}
dependencies{
implementation project(":core")
implementation project(":net")
implementation arcModule("backends:backend-android")
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"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
} }
task deploy(type: Copy){ task deploy(type: Copy){
dependsOn "assembleRelease" dependsOn "assembleRelease"
from "build/outputs/apk/google/release/android-google-release.apk" from "build/outputs/apk/release/android-release.apk"
into "../deploy/"; into "../deploy/"
rename ("android-google-release.apk", appName + "-android-" + getVersionString() + ".apk"); rename("android-release.apk", appName + "-android-" + getVersionString() + ".apk")
} }
android { android{
buildToolsVersion '26.0.2' buildToolsVersion '28.0.3'
compileSdkVersion 26 compileSdkVersion 28
sourceSets { sourceSets{
main { main{
manifest.srcFile 'AndroidManifest.xml' manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src'] java.srcDirs = ['src']
aidl.srcDirs = ['src'] aidl.srcDirs = ['src']
@@ -35,13 +63,13 @@ 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'
} }
defaultConfig { defaultConfig{
def vfile = file('../core/assets/version.properties') def vfile = file('../core/assets/version.properties')
def code = 0 def code = 0
@@ -60,62 +88,58 @@ android {
applicationId "io.anuke.mindustry" applicationId "io.anuke.mindustry"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 27 targetSdkVersion 28
versionCode code versionCode code
versionName versionNameResult versionName versionNameResult
} }
compileOptions { compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
flavorDimensions "google" flavorDimensions "google"
productFlavors { signingConfigs{
google { release{
buildConfigField "boolean", "DONATIONS_GOOGLE", "true" if(project.hasProperty("RELEASE_STORE_FILE")){
}
}
signingConfigs {
release {
if(project.hasProperty("RELEASE_STORE_FILE")) {
storeFile file(RELEASE_STORE_FILE) storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD keyPassword RELEASE_KEY_PASSWORD
}else{ }else{
println("No keystore info property found!"); println("No keystore info property found!")
} }
} }
} }
buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) {
release { buildTypes {
signingConfig signingConfigs.release release {
signingConfig signingConfigs.release
}
} }
} }
} }
// called every time gradle gets executed, takes the native dependencies of // called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders // the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK. // so they get packed with the APK.
task copyAndroidNatives() { task copyAndroidNatives(){
file("libs/armeabi/").mkdirs(); file("libs/armeabi/").mkdirs()
file("libs/armeabi-v7a/").mkdirs(); file("libs/armeabi-v7a/").mkdirs()
file("libs/arm64-v8a/").mkdirs(); file("libs/arm64-v8a/").mkdirs()
file("libs/x86_64/").mkdirs(); file("libs/x86_64/").mkdirs()
file("libs/x86/").mkdirs(); file("libs/x86/").mkdirs()
configurations.natives.files.each { jar -> configurations.natives.files.each{ jar ->
def outputDir = null def outputDir = null
if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a") if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a") if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi") if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if (jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64") if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86") if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if (outputDir != null) { if(outputDir != null){
copy { copy{
from zipTree(jar) from zipTree(jar)
into outputDir into outputDir
include "*.so" include "*.so"
@@ -123,76 +147,25 @@ task copyAndroidNatives() {
} }
} }
} }
task run(type: Exec) {
task run(type: Exec){
def path def path
def localProperties = project.file("../local.properties") def localProperties = project.file("../local.properties")
if (localProperties.exists()) { if(localProperties.exists()){
Properties properties = new Properties() Properties properties = new Properties()
localProperties.withInputStream { instr -> localProperties.withInputStream{ instr ->
properties.load(instr) properties.load(instr)
} }
def sdkDir = properties.getProperty('sdk.dir') def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) { if(sdkDir){
path = sdkDir path = sdkDir
} else { }else{
path = "$System.env.ANDROID_HOME" path = "$System.env.ANDROID_HOME"
} }
} else { }else{
path = "$System.env.ANDROID_HOME" path = "$System.env.ANDROID_HOME"
} }
def adb = path + "/platform-tools/adb" def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'io.anuke.mindustry/io.anuke.mindustry.AndroidLauncher' commandLine "$adb", 'shell', 'am', 'start', '-n', 'io.anuke.mindustry/io.anuke.mindustry.AndroidLauncher'
} }
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
classpath {
plusConfigurations += [project.configurations.compile]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [COMPILE: [plus: [project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value: "true")
}
}
}
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 76 KiB

View File

@@ -20,26 +20,10 @@
#} #}
-verbose -verbose
-verbose
-dontwarn android.support.** -ignorewarnings
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication -keep class io.anuke.mindustry.game.Rules
-dontwarn com.badlogic.gdx.utils.GdxBuild -keep class io.anuke.mindustry.desktop.DesktopLauncher
-dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild -keepclasseswithmembers public class * {
-dontwarn com.badlogic.gdx.jnigen.BuildTarget* public static void main(java.lang.String[]);
-dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild
-keep class com.badlogic.gdx.controllers.android.AndroidControllers
-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
<init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}
-keepclassmembers class com.badlogic.gdx.physics.box2d.World {
boolean contactFilter(long, long);
void beginContact(long);
void endContact(long);
void preSolve(long, long);
void postSolve(long, long);
boolean reportFixture(long);
float reportRayFixture(long, float, float, float, float, float);
} }

View File

@@ -9,6 +9,5 @@
# #
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target. # Project target.
target=android-19 target=android-19

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 911 B

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -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>

View File

@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:adjustViewBounds="false"
android:contentDescription="background"
android:cropToPadding="false"
android:scaleType="centerCrop"
android:src="@drawable/background" />
<LinearLayout
android:id="@+id/donations_activity_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@@ -1,43 +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" >
<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
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>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 553 B

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -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>

View File

@@ -2,14 +2,5 @@
<resources> <resources>
<string name="app_name">Mindustry</string> <string name="app_name">Mindustry</string>
<string-array name="donation_google_catalog_values">
<item>1 Dollar</item>
<item>2 Dollars</item>
<item>5 Dollars</item>
<item>10 Dollars</item>
<item>15 Dollars</item>
<item>25 Dollars</item>
<item>50 Dollars</item>
</string-array>
</resources> </resources>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
</full-backup-content>

View File

@@ -3,179 +3,184 @@ 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 io.anuke.arc.Core;
import com.badlogic.gdx.backends.android.AndroidApplication; import io.anuke.arc.backends.android.surfaceview.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import io.anuke.arc.backends.android.surfaceview.AndroidApplicationConfiguration;
import com.badlogic.gdx.utils.Base64Coder; import io.anuke.arc.files.FileHandle;
import com.google.android.gms.common.GoogleApiAvailability; import io.anuke.arc.function.Consumer;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException; import io.anuke.arc.function.Predicate;
import com.google.android.gms.common.GooglePlayServicesRepairableException; import io.anuke.arc.scene.ui.layout.Unit;
import com.google.android.gms.security.ProviderInstaller; import io.anuke.arc.util.Strings;
import io.anuke.kryonet.DefaultThreadImpl; import io.anuke.arc.util.serialization.Base64Coder;
import io.anuke.kryonet.KryoClient;
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.net.Net; import io.anuke.mindustry.game.Saves.SaveSlot;
import io.anuke.ucore.core.Settings; import io.anuke.mindustry.io.SaveIO;
import io.anuke.ucore.scene.ui.TextField; import io.anuke.mindustry.net.*;
import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.mindustry.ui.dialogs.FileChooser;
import java.text.DateFormat; import java.io.*;
import java.text.NumberFormat; import java.util.ArrayList;
import java.text.SimpleDateFormat;
import java.util.Date; import static io.anuke.mindustry.Vars.*;
import java.util.Locale;
import java.util.Random;
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; boolean doubleScaleTablets = true;
FileChooser chooser;
@Override @Override
protected void onCreate(Bundle savedInstanceState){ protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useImmersiveMode = true;
config.depth = 0;
Platform.instance = new Platform(){
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); @Override
config.useImmersiveMode = true; public void hide(){
moveTaskToBack(true);
}
Platform.instance = new Platform(){ @Override
DateFormat format = SimpleDateFormat.getDateTimeInstance(); public String getUUID(){
try{
@Override String s = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
public boolean hasDiscord() { int len = s.length();
return isPackageInstalled("com.discord"); 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)
@Override + Character.digit(s.charAt(i + 1), 16));
public String format(Date date){
return format.format(date);
}
@Override
public String format(int number){
return NumberFormat.getIntegerInstance().format(number);
}
@Override
public void addDialog(TextField field, int length){
TextFieldDialogListener.add(field, 0, length);
}
@Override
public String getLocaleName(Locale locale){
return locale.getDisplayName(locale);
}
@Override
public void openDonations() {
showDonations();
}
@Override
public void requestWritePerms() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
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) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_REQUEST_CODE);
}
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, WRITE_REQUEST_CODE);
}
}
}
}
@Override
public ThreadProvider getThreadProvider() {
return new DefaultThreadImpl();
}
@Override
public boolean isDebug() {
return false;
}
@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); String result = new String(Base64Coder.encode(data));
} if(result.equals("AAAAAAAAAOA=")) throw new RuntimeException("Bad UUID.");
} return result;
}; }catch(Exception e){
return super.getUUID();
}
}
try { @Override
ProviderInstaller.installIfNeeded(this); public void shareFile(FileHandle file){
} 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())){ @Override
Unit.dp.addition = 0.5f; public void showFileChooser(String text, String content, Consumer<FileHandle> cons, boolean open, Predicate<String> filetype){
} chooser = new FileChooser(text, file -> filetype.test(file.extension().toLowerCase()), open, cons);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
config.hideStatusBar = true; 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[0]), PERMISSION_REQUEST_CODE);
}
}
Net.setClientProvider(new KryoClient()); @Override
Net.setServerProvider(new KryoServer()); public void beginForceLandscape(){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
@Override
public void endForceLandscape(){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
@Override
public boolean canDonate(){
return true;
}
};
if(doubleScaleTablets && isTablet(this.getContext())){
Unit.dp.addition = 0.5f;
}
config.hideStatusBar = true;
Net.setClientProvider(new ArcNetClient());
Net.setServerProvider(new ArcNetServer());
initialize(new Mindustry(), config); initialize(new Mindustry(), config);
} checkFiles(getIntent());
}
private boolean isPackageInstalled(String packagename) {
try { @Override
getPackageManager().getPackageInfo(packagename, 0); public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
return true; if(requestCode == PERMISSION_REQUEST_CODE){
} catch (Exception e) { for(int i : grantResults){
return false; if(i != PackageManager.PERMISSION_GRANTED) return;
} }
} if(chooser != null){
chooser.show();
private boolean isTablet(Context context) { }
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); }
return manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE; }
}
private void checkFiles(Intent intent){
private void showDonations(){ try{
Intent intent = new Intent(this, DonationsActivity.class); Uri uri = intent.getData();
startActivity(intent); 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);
Core.app.post(() -> {
if(save){ //open save
System.out.println("Opening save.");
FileHandle file = Core.files.local("temp-save." + saveExtension);
file.write(inStream, false);
if(SaveIO.isSaveValid(file)){
try{
SaveSlot slot = control.saves.importSave(file);
ui.load.runLoadSave(slot);
}catch(IOException e){
ui.showError(Core.bundle.format("save.import.fail", Strings.parseException(e, true)));
}
}else{
ui.showError("$save.import.invalid");
}
}else if(map){ //open map
FileHandle file = Core.files.local("temp-map." + mapExtension);
file.write(inStream, false);
Core.app.post(() -> {
System.out.println("Opening map.");
if(!ui.editor.isShown()){
ui.editor.show();
}
ui.editor.beginEditMap(file);
});
}
});
}
}catch(IOException e){
e.printStackTrace();
}
}
private boolean isTablet(Context context){
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
return manager != null && manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE;
}
} }

View File

@@ -1,119 +0,0 @@
package io.anuke.mindustry;
import android.app.Activity;
import android.app.AlertDialog;
import android.text.InputFilter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.EditText;
import com.badlogic.gdx.Gdx;
public class AndroidTextFieldDialog{
private Activity activity;
private EditText userInput;
private AlertDialog.Builder builder;
private TextPromptListener listener;
private boolean isBuild;
public AndroidTextFieldDialog() {
this.activity = (Activity)Gdx.app;
load();
}
public AndroidTextFieldDialog show() {
activity.runOnUiThread(() -> {
Gdx.app.error("Android Dialogs", AndroidTextFieldDialog.class.getSimpleName() + " now shown.");
AlertDialog dialog = builder.create();
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
});
return this;
}
private AndroidTextFieldDialog load() {
activity.runOnUiThread(() -> {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
LayoutInflater li = LayoutInflater.from(activity);
View promptsView = li.inflate(getResourceId("gdxdialogs_inputtext", "layout"), null);
alertDialogBuilder.setView(promptsView);
userInput = (EditText) promptsView.findViewById(getResourceId("gdxDialogsEditTextInput", "id"));
alertDialogBuilder.setCancelable(false);
builder = alertDialogBuilder;
isBuild = true;
});
// Wait till TextPrompt is built.
while (!isBuild) {
try {
Thread.sleep(10);
} catch (InterruptedException e) { }
}
return this;
}
public int getResourceId(String pVariableName, String pVariableType) {
try {
return activity.getResources().getIdentifier(pVariableName, pVariableType, activity.getPackageName());
} catch (Exception e) {
Gdx.app.error("Android Dialogs", "Cannot find resouce with name: " + pVariableName
+ " Did you copy the layouts to /res/layouts and /res/layouts_v14 ?");
e.printStackTrace();
return -1;
}
}
public AndroidTextFieldDialog setText(CharSequence value) {
userInput.append(value);
return this;
}
public AndroidTextFieldDialog setCancelButtonLabel(CharSequence label) {
builder.setNegativeButton(label, (dialog, id) -> dialog.cancel());
return this;
}
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label) {
builder.setPositiveButton(label, (dialog, id) -> {
if (listener != null && !userInput.getText().toString().isEmpty()) {
listener.confirm(userInput.getText().toString());
}
});
return this;
}
public AndroidTextFieldDialog setTextPromptListener(TextPromptListener listener) {
this.listener = listener;
return this;
}
public AndroidTextFieldDialog setInputType(int type) {
userInput.setInputType(type);
return this;
}
public AndroidTextFieldDialog setMaxLength(int length) {
userInput.setFilters(new InputFilter[] { new InputFilter.LengthFilter(length) });
return this;
}
public interface TextPromptListener{
void confirm(String text);
}
}

View File

@@ -1,79 +0,0 @@
package io.anuke.mindustry;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Button;
import org.sufficientlysecure.donations.DonationsFragment;
public class DonationsActivity extends FragmentActivity {
DonationsFragment donationsFragment;
/**
* Google
*/
private static final String GOOGLE_PUBKEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzG93KhpfBPKTo2jF0yxbWkkmMKwsPNM4SsMj1aDq7vv6n3R+mqJVfprOJxFfJh7JchXTflLIgiaKXFAiU70gJbMTniEWnEaFSxAeF09a7U0RjOwN+7rFwjCG91c2CpYxPanBTQP4zasc1ODPVzq4q6/4ByjhenN71V4WmR08NFIAodcfFPrOkDPil7i8y7cgcd1Ky53U0TS+LLYJttAK3XdTK4s7VE3I5IKoeNa4uwCmIM59R67q2k3cXjLk/nP6MP+y++EzHN/PTiR1sVg4dMP8K31RPw/1QNLPQwJz6Wc872oWwb7xo5gkoXbDc5WPPydsi8F3SyKNaYwzN6CDFQIDAQAB";
private static final String[] GOOGLE_CATALOG = new String[]{
"mindustry.donation.1", "mindustry.donation.2", "mindustry.donation.5",
"mindustry.donation.10", "mindustry.donation.15",
"mindustry.donation.25", "mindustry.donation.50" };
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.GdxTheme);
setContentView(R.layout.donations_activity);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (BuildConfig.DONATIONS_GOOGLE) {
donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, true, GOOGLE_PUBKEY, GOOGLE_CATALOG,
getResources().getStringArray(R.array.donation_google_catalog_values), false, null, null,
null, false, null, null, false, null);
}
ft.replace(R.id.donations_activity_container, donationsFragment, "donationsFragment");
ft.commit();
}
public void onStart(){
super.onStart();
Button b = ((Button)findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
b.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
donationsFragment.donateGoogleOnClick(donationsFragment.getView());
b.setEnabled(false);
}
});
}
/**
* 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.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Button b = ((Button)findViewById(org.sufficientlysecure.donations.R.id.donations__google_android_market_donate_button));
b.setEnabled(true);
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag("donationsFragment");
if (fragment != null) {
fragment.onActivityResult(requestCode, resultCode, data);
//TODO donation event, set settings?
}
}
}

View File

@@ -1,67 +0,0 @@
package io.anuke.mindustry;
import android.text.InputType;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import io.anuke.ucore.scene.event.ChangeListener;
import io.anuke.ucore.scene.event.ClickListener;
import io.anuke.ucore.scene.event.InputEvent;
import io.anuke.ucore.scene.event.InputListener;
import io.anuke.ucore.scene.ui.TextField;
public class TextFieldDialogListener extends ClickListener{
private TextField field;
private int type;
private int max;
public static void add(TextField field, int type, int max){
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;
}
});
}
public static void add(TextField field){
add(field, 0, 16);
}
//type - 0 is text, 1 is numbers, 2 is decimals
public TextFieldDialogListener(TextField field, int type, int max){
this.field = field;
this.type = type;
this.max = max;
}
public void clicked(final InputEvent event, float x, float y){
if(Gdx.app.getType() == ApplicationType.Desktop) return;
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
dialog.setTextPromptListener(text -> {
field.clearText();
field.appendText(text);
field.fire(new ChangeListener.ChangeEvent());
Gdx.graphics.requestRendering();
});
if(type == 0){
dialog.setInputType(InputType.TYPE_CLASS_TEXT);
}else if(type == 1){
dialog.setInputType(InputType.TYPE_CLASS_NUMBER);
}else if(type == 2){
dialog.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
}
dialog.setConfirmButtonLabel("OK").setText(field.getText());
dialog.setCancelButtonLabel("Cancel");
dialog.setMaxLength(max);
dialog.show();
event.cancel();
}
}

6
annotations/build.gradle Normal file
View File

@@ -0,0 +1,6 @@
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = ["src/main/java/"]
sourceSets.main.resources.srcDirs = ["src/main/resources/"]

View File

@@ -0,0 +1,150 @@
package io.anuke.annotations;
import java.lang.annotation.*;
public class Annotations{
/** Indicates that a method should always call its super version. */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface CallSuper{
}
/** Annotation that allows overriding CallSuper annotation. To be used on method that overrides method with CallSuper annotation from parent class.*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface OverrideCallSuper {
}
/** Indicates that a method return or field can be null.*/
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface Nullable{
}
/** Indicates that a method return or field cannot be null.*/
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.SOURCE)
public @interface NonNull{
}
/** Marks a class as serializable. */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Serialize{
}
/** Marks a class as a special value type struct. Class name must end in 'Struct'. */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Struct{
}
/** Marks a field of a struct. Optional. */
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface StructField{
/** Size of a struct field in bits. Not valid on booleans or floating point numbers. */
int value();
}
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.SOURCE)
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;
/** 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.SOURCE)
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.SOURCE)
public @interface ReadClass{
Class<?> value();
}
}

View File

@@ -0,0 +1,65 @@
package io.anuke.annotations;
import com.sun.source.util.TreePath;
import com.sun.source.util.Trees;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCExpressionStatement;
import io.anuke.annotations.Annotations.OverrideCallSuper;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
import java.util.List;
import java.util.Set;
@SupportedAnnotationTypes("java.lang.Override")
public class CallSuperAnnotationProcessor extends AbstractProcessor{
private Trees trees;
@Override
public void init (ProcessingEnvironment pe) {
super.init(pe);
trees = Trees.instance(pe);
}
public boolean process (Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element e : roundEnv.getElementsAnnotatedWith(Override.class)) {
if (e.getAnnotation(OverrideCallSuper.class) != null) return false;
CodeAnalyzerTreeScanner codeScanner = new CodeAnalyzerTreeScanner();
codeScanner.setMethodName(e.getSimpleName().toString());
TreePath tp = trees.getPath(e.getEnclosingElement());
codeScanner.scan(tp, trees);
if (codeScanner.isCallSuperUsed()) {
List list = codeScanner.getMethod().getBody().getStatements();
if (!doesCallSuper(list, codeScanner.getMethodName())) {
processingEnv.getMessager().printMessage(Kind.ERROR, "Overriding method '" + codeScanner.getMethodName() + "' must explicitly call super method from its parent class.", e);
}
}
}
return false;
}
private boolean doesCallSuper (List list, String methodName) {
for (Object object : list) {
if (object instanceof JCTree.JCExpressionStatement) {
JCTree.JCExpressionStatement expr = (JCExpressionStatement) object;
String exprString = expr.toString();
if (exprString.startsWith("super." + methodName) && exprString.endsWith(");")) return true;
}
}
return false;
}
@Override
public SourceVersion getSupportedSourceVersion () {
return SourceVersion.RELEASE_8;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,98 @@
package io.anuke.annotations;
import com.sun.source.tree.*;
import com.sun.source.util.TreePathScanner;
import com.sun.source.util.Trees;
import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
import io.anuke.annotations.Annotations.CallSuper;
import java.lang.annotation.Annotation;
class CodeAnalyzerTreeScanner extends TreePathScanner<Object, Trees> {
private String methodName;
private MethodTree method;
private boolean callSuperUsed;
@Override
public Object visitClass (ClassTree classTree, Trees trees) {
Tree extendTree = classTree.getExtendsClause();
if (extendTree instanceof JCTypeApply) { //generic classes case
JCTypeApply generic = (JCTypeApply) extendTree;
extendTree = generic.clazz;
}
if (extendTree instanceof JCIdent) {
JCIdent tree = (JCIdent) extendTree;
Scope members = tree.sym.members();
if (checkScope(members))
return super.visitClass(classTree, trees);
if (checkSuperTypes((ClassType) tree.type))
return super.visitClass(classTree, trees);
}
callSuperUsed = false;
return super.visitClass(classTree, trees);
}
public boolean checkSuperTypes (ClassType type) {
if (type.supertype_field != null && type.supertype_field.tsym != null) {
if (checkScope(type.supertype_field.tsym.members()))
return true;
else
return checkSuperTypes((ClassType) type.supertype_field);
}
return false;
}
public boolean checkScope (Scope members) {
for (Symbol s : members.getElements()) {
if (s instanceof MethodSymbol) {
MethodSymbol ms = (MethodSymbol) s;
if (ms.getSimpleName().toString().equals(methodName)) {
Annotation annotation = ms.getAnnotation(CallSuper.class);
if (annotation != null) {
callSuperUsed = true;
return true;
}
}
}
}
return false;
}
@Override
public Object visitMethod (MethodTree methodTree, Trees trees) {
if (methodTree.getName().toString().equals(methodName))
method = methodTree;
return super.visitMethod(methodTree, trees);
}
public void setMethodName (String methodName) {
this.methodName = methodName;
}
public String getMethodName () {
return methodName;
}
public MethodTree getMethod () {
return method;
}
public boolean isCallSuperUsed () {
return callSuperUsed;
}
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,51 @@
package io.anuke.annotations;
import io.anuke.annotations.Annotations.*;
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();
}
}

View File

@@ -0,0 +1,154 @@
package io.anuke.annotations;
import com.squareup.javapoet.*;
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.*;
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;
/** Warning on top of each autogenerated file. */
public static final String autogenWarning = "Autogenerated file. Do not modify!\n";
/** 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";
/** Simple class name of generated class name. */
private static final String callLocation = "Call";
/** 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(callLocation)){
ClassEntry clas = new ClassEntry(callLocation);
classMap.put(callLocation, clas);
classes.add(clas);
}
ClassEntry entry = classMap.get(callLocation);
//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.addJavadoc(autogenWarning);
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;
}
}

View File

@@ -0,0 +1,144 @@
package io.anuke.annotations;
import com.squareup.javapoet.*;
import io.anuke.annotations.IOFinder.ClassSerializer;
import javax.lang.model.element.*;
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);
classBuilder.addJavadoc(RemoteMethodAnnotationProcessor.autogenWarning);
//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.type.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);
}
}

View File

@@ -0,0 +1,224 @@
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.*;
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);
classBuilder.addJavadoc(RemoteMethodAnnotationProcessor.autogenWarning);
//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.type.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.player");
}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, $1N::new)", "io.anuke.mindustry.net.Packets.InvokePacket", "io.anuke.arc.util.pooling.Pools");
//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";
}
}

View File

@@ -0,0 +1,128 @@
package io.anuke.annotations;
import com.squareup.javapoet.*;
import io.anuke.annotations.Annotations.Serialize;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.ElementFilter;
import java.io.*;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Set;
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes("io.anuke.annotations.Annotations.Serialize")
public class SerializeAnnotationProcessor extends AbstractProcessor{
/** Target class name. */
private static final String className = "Serialization";
/** Name of the base package to put all the generated classes. */
private static final String packageName = "io.anuke.mindustry.gen";
private int round;
@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++ != 0) return false; //only process 1 round
try{
Set<TypeElement> elements = ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(Serialize.class));
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC);
classBuilder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "\"unchecked\"").build());
classBuilder.addJavadoc(RemoteMethodAnnotationProcessor.autogenWarning);
MethodSpec.Builder method = MethodSpec.methodBuilder("init").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
for(TypeElement elem : elements){
TypeName type = TypeName.get(elem.asType());
String simpleTypeName = type.toString().substring(type.toString().lastIndexOf('.') + 1);
TypeSpec.Builder serializer = TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ParameterizedTypeName.get(
ClassName.bestGuess("io.anuke.arc.Settings.TypeSerializer"), type));
MethodSpec.Builder writeMethod = MethodSpec.methodBuilder("write")
.returns(void.class)
.addParameter(DataOutput.class, "stream")
.addParameter(type, "object")
.addException(IOException.class)
.addModifiers(Modifier.PUBLIC);
MethodSpec.Builder readMethod = MethodSpec.methodBuilder("read")
.returns(type)
.addParameter(DataInput.class, "stream")
.addException(IOException.class)
.addModifiers(Modifier.PUBLIC);
readMethod.addStatement("$L object = new $L()", type, type);
List<VariableElement> fields = ElementFilter.fieldsIn(Utils.elementUtils.getAllMembers(elem));
for(VariableElement field : fields){
if(field.getModifiers().contains(Modifier.STATIC) || field.getModifiers().contains(Modifier.TRANSIENT) || field.getModifiers().contains(Modifier.PRIVATE))
continue;
String name = field.getSimpleName().toString();
String typeName = Utils.typeUtils.erasure(field.asType()).toString().replace('$', '.');
String capName = Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1);
if(field.asType().getKind().isPrimitive()){
writeMethod.addStatement("stream.write" + capName + "(object." + name + ")");
readMethod.addStatement("object." + name + "= stream.read" + capName + "()");
}else{
writeMethod.addStatement("io.anuke.arc.Core.settings.getSerializer(" + typeName + ".class).write(stream, object." + name + ")");
readMethod.addStatement("object." + name + " = (" + typeName + ")io.anuke.arc.Core.settings.getSerializer(" + typeName + ".class).read(stream)");
}
}
readMethod.addStatement("return object");
serializer.addMethod(writeMethod.build());
serializer.addMethod(readMethod.build());
method.addStatement("io.anuke.arc.Core.settings.setSerializer($N, $L)", Utils.elementUtils.getBinaryName(elem).toString().replace('$', '.') + ".class", serializer.build());
name(writeMethod, "write" + simpleTypeName);
name(readMethod, "read" + simpleTypeName);
writeMethod.addModifiers(Modifier.STATIC);
readMethod.addModifiers(Modifier.STATIC);
classBuilder.addMethod(writeMethod.build());
classBuilder.addMethod(readMethod.build());
}
classBuilder.addMethod(method.build());
//write result
JavaFile.builder(packageName, classBuilder.build()).build().writeTo(Utils.filer);
return true;
}catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e);
}
}
static void name(MethodSpec.Builder builder, String name){
try{
Field field = builder.getClass().getDeclaredField("name");
field.setAccessible(true);
field.set(builder, name);
}catch(Exception e){
throw new RuntimeException(e);
}
}
}

View File

@@ -0,0 +1,226 @@
package io.anuke.annotations;
import com.squareup.javapoet.*;
import io.anuke.annotations.Annotations.Struct;
import io.anuke.annotations.Annotations.StructField;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.TypeKind;
import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic.Kind;
import java.util.List;
import java.util.Set;
/**
* Generates ""value types"" classes that are packed into integer primitives of the most aproppriate size.
* It would be nice if Java didn't make crazy hacks like this necessary.
*/
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes({
"io.anuke.annotations.Annotations.Struct"
})
public class StructAnnotationProcessor extends AbstractProcessor{
/** Name of the base package to put all the generated classes. */
private static final String packageName = "io.anuke.mindustry.gen";
private int round;
@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++ != 0) return false; //only process 1 round
try{
Set<TypeElement> elements = ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(Struct.class));
for(TypeElement elem : elements){
if(!elem.getSimpleName().toString().endsWith("Struct")){
Utils.messager.printMessage(Kind.ERROR, "All classes annotated with @Struct must have their class names end in 'Struct'.", elem);
continue;
}
String structName = elem.getSimpleName().toString().substring(0, elem.getSimpleName().toString().length() - "Struct".length());
String structParam = structName.toLowerCase();
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(structName)
.addModifiers(Modifier.FINAL, Modifier.PUBLIC);
try{
List<VariableElement> variables = ElementFilter.fieldsIn(elem.getEnclosedElements());
int structSize = variables.stream().mapToInt(StructAnnotationProcessor::varSize).sum();
int structTotalSize = (structSize <= 8 ? 8 : structSize <= 16 ? 16 : structSize <= 32 ? 32 : 64);
if(variables.size() == 0){
Utils.messager.printMessage(Kind.ERROR, "making a struct with no fields is utterly pointles.", elem);
continue;
}
//obtain type which will be stored
Class<?> structType = typeForSize(structSize);
//[constructor] get(fields...) : structType
MethodSpec.Builder constructor = MethodSpec.methodBuilder("get")
.addModifiers(Modifier.STATIC, Modifier.PUBLIC)
.returns(structType);
StringBuilder cons = new StringBuilder();
StringBuilder doc = new StringBuilder();
doc.append("Bits used: ").append(structSize).append(" / ").append(structTotalSize).append("\n");
int offset = 0;
for(VariableElement var : variables){
int size = varSize(var);
TypeName varType = TypeName.get(var.asType());
String varName = var.getSimpleName().toString();
//add val param to constructor
constructor.addParameter(varType, varName);
//[get] field(structType) : fieldType
MethodSpec.Builder getter = MethodSpec.methodBuilder(var.getSimpleName().toString())
.addModifiers(Modifier.STATIC, Modifier.PUBLIC)
.returns(varType)
.addParameter(structType, structParam);
//[set] field(structType, fieldType) : structType
MethodSpec.Builder setter = MethodSpec.methodBuilder(var.getSimpleName().toString())
.addModifiers(Modifier.STATIC, Modifier.PUBLIC)
.returns(structType)
.addParameter(structType, structParam).addParameter(varType, "value");
//[getter]
if(varType == TypeName.BOOLEAN){
//bools: single bit, is simplified
getter.addStatement("return ($L & (1L << $L)) != 0", structParam, offset);
}else if(varType == TypeName.FLOAT){
//floats: need conversion
getter.addStatement("return Float.intBitsToFloat((int)(($L >>> $L) & $L))", structParam, offset, bitString(size, structTotalSize));
}else{
//bytes, shorts, chars, ints
getter.addStatement("return ($T)(($L >>> $L) & $L)", varType, structParam, offset, bitString(size, structTotalSize));
}
//[setter] + [constructor building]
if(varType == TypeName.BOOLEAN){
cons.append(" | (").append(varName).append(" ? ").append("1L << ").append(offset).append("L : 0)");
//bools: single bit, needs special case to clear things
setter.beginControlFlow("if(value)");
setter.addStatement("return ($T)(($L & ~(1L << $LL)))", structType, structParam, offset);
setter.nextControlFlow("else");
setter.addStatement("return ($T)(($L & ~(1L << $LL)) | (1L << $LL))", structType, structParam, offset, offset);
setter.endControlFlow();
}else if(varType == TypeName.FLOAT){
cons.append(" | (").append("(").append(structType).append(")").append("Float.floatToIntBits(").append(varName).append(") << ").append(offset).append("L)");
//floats: need conversion
setter.addStatement("return ($T)(($L & $L) | (($T)Float.floatToIntBits(value) << $LL))", structType, structParam, bitString(offset, size, structTotalSize), structType, offset);
}else{
cons.append(" | (((").append(structType).append(")").append(varName).append(" << ").append(offset).append("L)").append(" & ").append(bitString(offset, size, structTotalSize)).append(")");
//bytes, shorts, chars, ints
setter.addStatement("return ($T)(($L & $L) | (($T)value << $LL))", structType, structParam, bitString(offset, size, structTotalSize), structType, offset);
}
doc.append("<br> ").append(varName).append(" [").append(offset).append("..").append(size + offset).append("]\n");
//add finished methods
classBuilder.addMethod(getter.build());
classBuilder.addMethod(setter.build());
offset += size;
}
classBuilder.addJavadoc(doc.toString());
//add constructor final statement + add to class and build
constructor.addStatement("return ($T)($L)", structType, cons.toString().substring(3));
classBuilder.addMethod(constructor.build());
JavaFile.builder(packageName, classBuilder.build()).build().writeTo(Utils.filer);
}catch(IllegalArgumentException e){
e.printStackTrace();
Utils.messager.printMessage(Kind.ERROR, e.getMessage(), elem);
}
}
return true;
}catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e);
}
}
static String bitString(int offset, int size, int totalSize){
StringBuilder builder = new StringBuilder();
for(int i = 0; i < offset; i++) builder.append('0');
for(int i = 0; i < size; i++) builder.append('1');
for(int i = 0; i < totalSize - size - offset; i++) builder.append('0');
return "0b" + builder.reverse().toString() + "L";
}
static String bitString(int size, int totalSize){
StringBuilder builder = new StringBuilder();
for(int i = 0; i < size; i++) builder.append('1');
for(int i = 0; i < totalSize - size; i++) builder.append('0');
return "0b" + builder.reverse().toString() + "L";
}
static int varSize(VariableElement var) throws IllegalArgumentException{
if(!var.asType().getKind().isPrimitive()){
throw new IllegalArgumentException("All struct fields must be primitives: " + var);
}
StructField an = var.getAnnotation(StructField.class);
if(var.asType().getKind() == TypeKind.BOOLEAN && an != null && an.value() != 1){
throw new IllegalArgumentException("Booleans can only be one bit long... why would you do this?");
}
if(var.asType().getKind() == TypeKind.FLOAT && an != null && an.value() != 32){
throw new IllegalArgumentException("Float size can't be changed. Very sad.");
}
return an == null ? typeSize(var.asType().getKind()) : an.value();
}
static Class<?> typeForSize(int size) throws IllegalArgumentException{
if(size <= 8){
return byte.class;
}else if(size <= 16){
return short.class;
}else if(size <= 32){
return int.class;
}else if(size <= 64){
return long.class;
}
throw new IllegalArgumentException("Too many fields, must fit in 64 bits. Curent size: " + size);
}
/** returns a type's element size in bits. */
static int typeSize(TypeKind kind) throws IllegalArgumentException{
switch(kind){
case BOOLEAN:
return 1;
case BYTE:
return 8;
case SHORT:
return 16;
case FLOAT:
case CHAR:
case INT:
return 32;
default:
throw new IllegalArgumentException("Invalid type kind: " + kind + ". Note that doubles and longs are not supported.");
}
}
}

View File

@@ -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");
}
}

View File

@@ -0,0 +1,4 @@
io.anuke.annotations.RemoteMethodAnnotationProcessor
io.anuke.annotations.SerializeAnnotationProcessor
io.anuke.annotations.StructAnnotationProcessor
io.anuke.annotations.CallSuperAnnotationProcessor

View File

@@ -1,37 +1,65 @@
buildscript { buildscript{
repositories { repositories{
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
google() google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } maven{ url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter() jcenter()
} }
dependencies {
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.0' dependencies{
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.6'
classpath 'com.android.tools.build:gradle:3.0.1' classpath "com.badlogicgames.gdx:gdx-tools:1.9.9"
classpath "com.badlogicgames.gdx:gdx-tools:1.9.8" classpath "com.badlogicgames.packr:packr:2.1-SNAPSHOT"
} }
} }
allprojects { allprojects{
apply plugin: "eclipse"
apply plugin: "idea"
version = 'release' version = 'release'
ext { ext{
versionNumber = '3.5' versionNumber = '4'
versionType = 'release' versionModifier = 'beta'
if(!project.hasProperty("versionType")) versionType = 'official'
appName = 'Mindustry' appName = 'Mindustry'
gdxVersion = '1.9.8' gdxVersion = '1.9.9'
roboVMVersion = '2.3.0' roboVMVersion = '2.3.6'
aiVersion = '1.8.1' arcHash = null
uCoreVersion = 'd5af97f93813d8767423521b1fcc5a5e0f7241d9'
debugged = {
return new File(projectDir.parent, '../debug').exists() && !project.hasProperty("release") && project.hasProperty("args")
}
localArc = {
return (!project.hasProperty("release")) && new File(projectDir.parent, '../Arc').exists()
}
getArcHash = {
//get latest commit hash from gtihub since JITPack's '-snapshot' version doesn't work correctly
if(arcHash == null){
try{
arcHash = 'git ls-remote https://github.com/Anuken/Arc.git'.execute().text.split("\t")[0]
}catch(e){
e.printStackTrace()
arcHash = "-SNAPSHOT"
}
}
return arcHash
}
arcModule = { String name ->
if(localArc()){
return project(":Arc:$name")
}else{
//skip to last submodule
if(name.contains(':')) name = name.split(':').last()
return "com.github.Anuken.Arc:$name:${getArcHash()}"
}
}
getVersionString = { getVersionString = {
String buildVersion = getBuildVersion() String buildVersion = getBuildVersion()
return "$versionNumber-$versionType-$buildVersion" return "$versionNumber-$versionModifier-$buildVersion"
} }
getBuildVersion = { getBuildVersion = {
@@ -43,159 +71,203 @@ allprojects {
return project.ext.mainClassName.substring(0, project.ext.mainClassName.indexOf("desktop") - 1) return project.ext.mainClassName.substring(0, project.ext.mainClassName.indexOf("desktop") - 1)
} }
generateLocales = {
def output = 'en\n'
def bundles = new File(project(':core').projectDir, 'assets/bundles/')
bundles.listFiles().each{ other ->
if(other.name == "bundle.properties") return
output += other.name.substring("bundle".length() + 1, other.name.lastIndexOf('.')) + "\n"
}
new File(project(':core').projectDir, 'assets/locales').text = output
}
writeVersion = { writeVersion = {
def pfile = new File('core/assets/version.properties') def pfile = new File(project(':core').projectDir, 'assets/version.properties')
def props = new Properties() def props = new Properties()
try{ try{
pfile.createNewFile() pfile.createNewFile()
}catch (Exception e){} }catch(Exception ignored){
}
if(pfile.exists()) {
if(pfile.exists()){
props.load(new FileInputStream(pfile)) props.load(new FileInputStream(pfile))
String code = getBuildVersion() String buildid = getBuildVersion()
props["name"] = appName props["type"] = versionType
props["version"] = versionType props["number"] = versionNumber
props["code"] = versionNumber props["modifier"] = versionModifier
props["build"] = code props["build"] = buildid
props.store(pfile.newWriter(), "Autogenerated file. Do not modify.") props.store(pfile.newWriter(), "Autogenerated file. Do not modify.")
} }
} }
} }
repositories { repositories{
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } maven{ url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" } maven{ url "https://oss.sonatype.org/content/repositories/releases/" }
maven { url 'https://jitpack.io' } maven{ url 'https://jitpack.io' }
jcenter()
} }
tasks.withType(Javadoc).all{ enabled = false }
} }
project(":desktop") { project(":desktop"){
apply plugin: "java" apply plugin: "java"
dependencies { dependencies{
compile project(":core") compile project(":core")
compile project(":kryonet") compile project(":net")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
if(debugged()) compile project(":debug")
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-freetype-platform:$gdxVersion:natives-desktop"
compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.0'
compile arcModule("backends:backend-lwjgl3")
compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.2'
} }
} }
project(":html") { project(":ios"){
apply plugin: "gwt"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion:sources"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion:sources"
compile "com.sksamuel.gwt:gwt-websockets:1.0.4"
compile "com.sksamuel.gwt:gwt-websockets:1.0.4:sources"
}
}
project(":android") {
apply plugin: "android"
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") {
apply plugin: "java" apply plugin: "java"
apply plugin: "robovm" apply plugin: "robovm"
task incrementConfig{
def vfile = file('robovm.properties')
dependencies { def props = new Properties()
if(vfile.exists()){
props.load(new FileInputStream(vfile))
}
props['app.id'] = 'io.anuke.mindustry'
props['app.version'] = '4.0'
props['app.mainclass'] = 'io.anuke.mindustry.IOSLauncher'
props['app.executable'] = 'IOSLauncher'
props['app.name'] = 'Mindustry'
props['app.build'] = (!props.containsKey("app.build") ? 40 : props['app.build'].toInteger() + 1) + ""
props.store(vfile.newWriter(), null)
}
dependencies{
compile project(":core") compile project(":core")
implementation project(":kryonet") compile project(":net")
compileOnly project(":annotations")
compile arcModule("backends:backend-robovm")
compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion" compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion" compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
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"
} compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
robovm {
} }
} }
project(":core") { project(":core"){
apply plugin: "java" apply plugin: "java"
dependencies { task finish{
boolean comp = System.properties["release"] == null || System.properties["release"] == "false" generateLocales()
}
if(!comp){ dependencies{
println("NOTICE: Compiling release build.") if(System.properties["user.name"] == "anuke"){
}else{ task cleanGen{
println("Compiling DEBUG build.") doFirst{
delete{
delete "../core/src/io/anuke/mindustry/gen/"
}
}
}
task copyGen{
doLast{
copy{
from("../core/build/generated/sources/annotationProcessor/java/main/io/anuke/mindustry/gen"){
include "**/*.java"
}
into "../core/src/io/anuke/mindustry/gen"
}
}
}
compileJava.dependsOn(cleanGen)
compileJava.finalizedBy(copyGen)
} }
if(new File('../uCore').exists() && comp){ compile arcModule("arc-core")
compile project(":uCore") compile arcModule("extensions:freetype")
}else{ compile arcModule("extensions:arcnet")
compile "com.github.anuken:ucore:$uCoreVersion" if(localArc() && debugged()) compile arcModule("extensions:recorder")
}
if(new File('../GDXGifRecorder').exists() && comp) { compileOnly project(":annotations")
compile project(":GDXGifRecorder") annotationProcessor project(":annotations")
}
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
} }
} }
project(":server") { project(":server"){
apply plugin: "java" apply plugin: "java"
dependencies { dependencies{
compile project(":core") compile project(":core")
compile project(":kryonet") compile project(":net")
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion" compile arcModule("backends:backend-headless")
}
}
project(":tests"){
apply plugin: "java"
dependencies{
testImplementation project(":core")
testImplementation "org.junit.jupiter:junit-jupiter-params:5.3.1"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.1"
compile arcModule("backends:backend-headless")
}
test{
useJUnitPlatform()
workingDir = new File("../core/assets")
}
}
project(":tools"){
apply plugin: "java"
dependencies{
compile project(":core")
//for render tests
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile arcModule("backends:backend-lwjgl3")
} }
} }
project(":kryonet") { project(":annotations"){
apply plugin: "java" apply plugin: "java"
dependencies { dependencies{
compile project(":core") compile 'com.squareup:javapoet:1.11.0'
compile 'com.github.crykn:kryonet:2.22.1' compile files("${System.getProperty('java.home')}/../lib/tools.jar")
compile "org.java-websocket:Java-WebSocket:1.3.7"
} }
} }
tasks.eclipse.doLast { project(":net"){
delete ".project" apply plugin: "java"
dependencies{
compile project(":core")
compile "org.lz4:lz4-java:1.4.1"
compile 'com.github.Anuken:WaifUPnP:05eb46bc577fd7674596946ba288c96c0cedd893'
}
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 514 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 B

Some files were not shown because too many files have changed in this diff Show More