apply plugin: "java"

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceCompatibility = targetCompatibility = appJavaCompatibility

ext.mainClass = "com.shatteredpixel.shatteredpixeldungeon.desktop.DesktopLauncher"
sourceSets.main.resources.srcDirs = [new File(project(':core').projectDir, "/src/main/assets"),
                                     new File(project(':desktop').projectDir,"/src/main/assets")]

sourceSets {
    debug
    release
}

task debug(dependsOn: classes, type: JavaExec) {
    classpath = sourceSets.debug.runtimeClasspath + sourceSets.main.runtimeClasspath
    ignoreExitValue = true

    main = mainClass
    systemProperty 'Specification-Title', appName
    systemProperty 'Specification-Version', appVersionName + "-INDEV"
    systemProperty 'Implementation-Version', appVersionCode

    dependencies {
        debugImplementation project(':services:updates:debugUpdates')
    }
}

//need a separate task to compile dependencies first, seeing as we're setting them up in an odd way
task compileForRelease(dependsOn: classes, type: JavaCompile){
    classpath = sourceSets.release.runtimeClasspath + sourceSets.main.runtimeClasspath
}

task release(dependsOn: compileForRelease, type: Jar) {
    from sourceSets.main.output
    from { sourceSets.release.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) } }
    from { configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) } }

    manifest {
        attributes 'Main-Class': mainClass
        attributes 'Specification-Title': appName
        attributes 'Specification-Version': appVersionName
        attributes 'Implementation-Version': appVersionCode
    }

    dependencies {
        releaseImplementation project(':services:updates:githubUpdates')
    }
}

dependencies {
    implementation project(':core')

    implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
    implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    implementation "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"

    //Need these at compile time to prevent errors there.
    // The actual dependency used at runtime will vary based on source set.
    compileOnly project(':services:updates:debugUpdates')
}