buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        google()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.0'
        classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "com.badlogicgames.gdx:gdx-tools:1.9.8"
    }
}

allprojects {
    version = 'release'

    ext {
        versionNumber = 'classic'
        versionType = 'release'
        appName = 'Mindustry'
        gdxVersion = '1.9.8'
        roboVMVersion = '2.3.0'
        aiVersion = '1.8.1'

        getVersionString = {
            String buildVersion = getBuildVersion()
            return "$versionNumber-$versionType-$buildVersion"
        }

        getBuildVersion = {
            if(!project.hasProperty("buildversion")) return "custom build"
            return project.getProperties()["buildversion"]
        }

        getPackage = {
            return project.ext.mainClassName.substring(0, project.ext.mainClassName.indexOf("desktop") - 1)
        }

        writeVersion = {
            def pfile = new File('core/assets/version.properties')
            def props = new Properties()

            try{
                pfile.createNewFile()
            }catch (Exception ignored){}

            if(pfile.exists()) {

                props.load(new FileInputStream(pfile))

                String code = getBuildVersion()

                props["name"] = appName
                props["version"] = versionType
                props["code"] = versionNumber
                props["build"] = code

                props.store(pfile.newWriter(), "Autogenerated file. Do not modify.")
            }
        }
    }

    repositories {
        //mavenLocal()
        mavenCentral()
        //maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
       // maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        maven { url 'https://jitpack.io' }
        //google()
        //jcenter()
    }
}

project(":desktop") {
    apply plugin: "java"

    dependencies {
        compile project(":core")
        compile project(":kryonet")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
        compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.1'
    }
}

project(":html") {
    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: "robovm"


    dependencies {
        compile project(":core")
        implementation project(":kryonet")

        compile "com.mobidevelop.robovm:robovm-rt:$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"
    }

}

project(":core") {
    apply plugin: "java"

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
        compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
    }
}

project(":server") {
    apply plugin: "java"

    dependencies {
        compile project(":core")
        compile project(":kryonet")
        compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    }
}

project(":kryonet") {
    apply plugin: "java"

    dependencies {
        compile project(":core")
        compile 'com.github.crykn:kryonet:2.22.1'
        compile "org.java-websocket:Java-WebSocket:1.3.7"
    }
}
