ref:main
plugins {
    id "com.github.johnrengelman.shadow" version "8.1.1"
}

architectury {
    platformSetupLoomIde()
    fabric()
}

loom {
    runs {
        server {
            name "Dedicated Server"
            runDir "run/server"
        }
        client {
            name "Client"
            runDir "run/client"
            // Point at localhost dedicated server by default
            programArgs "--server", "localhost"
        }
        gametest {
            inherit server
            name "Game Test"
            vmArg "-Dfabric-api.gametest"
            vmArg "-Dfabric-api.gametest.report-file=${project.buildDir}/gametest/junit.xml"
            runDir "build/gametest"
        }
        visualTest {
            inherit client
            name "Visual Test"
            vmArg "-Dhuorn.visualtest=true"
            runDir "build/visualtest"
        }
    }
}

// Auto-accept EULA for dedicated server run directory
tasks.register('acceptEula') {
    doLast {
        def serverDir = file("run/server")
        serverDir.mkdirs()
        file("run/server/eula.txt").text = "eula=true\n"
    }
}
tasks.named('runServer').configure { dependsOn 'acceptEula' }

configurations {
    common
    shadowCommon
    compileClasspath.extendsFrom common
    runtimeClasspath.extendsFrom common
    developmentFabric.extendsFrom common
}

dependencies {
    modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
    modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
    modImplementation "dev.architectury:architectury-fabric:${rootProject.architectury_version}"
    modImplementation(include("me.lucko:fabric-permissions-api:0.3.1")) {
        exclude group: "net.fabricmc", module: "fabric-loader"
    }

    common(project(path: ":common", configuration: "namedElements")) { transitive = false }
    shadowCommon(project(path: ":common", configuration: "namedElements")) { transitive = false }
}

processResources {
    inputs.property "version", project.version
    filesMatching("fabric.mod.json") {
        expand "version": project.version
    }
}

shadowJar {
    configurations = [project.configurations.shadowCommon]
    archiveClassifier = "dev-shadow"
}

remapJar {
    input.set shadowJar.archiveFile
    dependsOn shadowJar
    archiveClassifier = null
}

jar {
    archiveClassifier = "dev"
}

sourcesJar {
    def commonSources = project(":common").sourcesJar
    dependsOn commonSources
    from commonSources.archiveFile.map { zipTree(it) }
}