plugins {
    id 'java'
    id 'application'
}

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

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

sourceSets {
    main {
        resources {
            srcDirs = ['src/main/resources', 'assets']
        }
    }
}

application {
    mainClass = 'de.blight.game.BlightApp'
    // jMonkeyEngine benötigt den headless-Flag nicht; nativer Fenstermodus
    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 {
    // jMonkeyEngine core
    implementation "org.jmonkeyengine:jme3-core:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-desktop:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-lwjgl3:${jmeVersion}"

    // Terrain, Effects, Plugins
    implementation "org.jmonkeyengine:jme3-terrain:${jmeVersion}"
    implementation "org.jmonkeyengine:jme3-effects:${jmeVersion}"

    // Bullet-Physik (nativ)
    implementation "org.jmonkeyengine:jme3-jbullet:${jmeVersion}"

    // Testdaten / eingebaute Assets (Primitiv-Modelle, Skybox etc.)
    implementation "org.jmonkeyengine:jme3-testdata:${jmeVersion}"

    // JSON für Key-Binding-Konfiguration
    implementation 'com.google.code.gson:gson:2.11.0'
}

// Native Libraries automatisch entpacken
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
    }
}
