import org.teavm.gradle.api.OptimizationLevel

plugins {
    id "java"
    id "org.teavm" version "0.10.2"
}

sourceSets {
    main {
        java {
            srcDirs(
                "src/main/java",
                "src/teavm/java",
                "sp-server/src/ipc/java"
            )
        }
    }
}

repositories {
    mavenCentral()
}

tasks.withType(JavaCompile) {
    options.warnings = false
    options.compilerArgs << "-Xmaxerrs" << "1000"
}

//sourceSets.main.resources.srcDirs += 'src/lwjgl/java/javazoom/jl/decoder'

dependencies {
    //implementation fileTree(dir: './lwjgl-rundir/', include: '*.jar')

    teavm(teavm.libs.jso)
    teavm(teavm.libs.jsoApis)
    compileOnly "org.teavm:teavm-core:0.10.2" // workaround for a few hacks
}

def folder = "javascript"
def name = "classes.js"

teavm.js {
    obfuscated = true
    sourceMap = true
    targetFileName = "../" + name
    optimization = OptimizationLevel.AGGRESSIVE
    outOfProcess = false
    fastGlobalAnalysis = false
    processMemory = 512
    entryPointName = "main"
    mainClass = "net.lax1dude.eaglercraft.Client"
    outputDir = file(folder)
    properties = [ "java.util.TimeZone.autodetect": "true" ]
    debugInformation = false
}
/*
tasks.register('copyDebugJar', Copy) {
    project.delete("lwjgl-rundir/eaglercraft.jar")
    from layout.buildDirectory.file("eaglercraft.jar")
    into ("lwjgl-rundir/")
}
*/
