plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.1.0'
}

group   = 'de.blight'
version = '0.1.0'

java {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

javafx {
    version = '21'
    modules = ['javafx.controls', 'javafx.swing']
}

application {
    mainClass = 'de.blight.editor.EditorLauncher'
    applicationDefaultJvmArgs = [
        '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
        '--add-opens', 'java.desktop/sun.awt=ALL-UNNAMED',
        '-Djava.library.path=${rootDir}/build/natives',
    ]
}

repositories {
    mavenCentral()
}

ext {
    jmeVersion = '3.7.0-stable'
}

dependencies {
    implementation "org.jmonkeyengine:jme3-core:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-desktop:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-lwjgl3:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-terrain:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-effects:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-testdata:${jmeVersion}"
}

tasks.register('extractNatives', Copy) {
    def nativeConf = configurations.runtimeClasspath.resolvedConfiguration
        .resolvedArtifacts
        .findAll { it.name.contains('natives') }
        .collect { zipTree(it.file) }

    from nativeConf
    into "${buildDir}/natives"
    duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

run {
    dependsOn extractNatives
    workingDir = rootDir
}

jar {
    manifest {
        attributes 'Main-Class': application.mainClass
    }
}
