allprojects {
    repositories {
        mavenCentral()
        maven {
            name = "swt-repo"
            url = "https://maven-eclipse.github.io/maven"
        }
        maven {
            name = "jitpack.io"
            url = "https://jitpack.io"
        }
        maven {
            name = "brigadier"
            url = "https://libraries.minecraft.net"
        }
        maven {
            name = "tigr.dev"
            url = "https://maven.tigr.dev"
            metadataSources { // needed for baritone
                mavenPom()
                artifact()
                ignoreGradleMetadataRedirection()
            }
        }
        maven {
            name = "spongepowered-repo"
            url = "https://repo.spongepowered.org/repository/maven-public/"
        }
        maven {
            name = "impactdevelopment-repo"
            url = "https://impactdevelopment.github.io/maven/"
        }
        maven {
            name = "Fabric"
            url = "https://maven.fabricmc.net/"
        }
    }
}

subprojects {
    apply plugin: "java"

    group = project.modGroup
    archivesBaseName = project.name
    version = project.aresVersion

    sourceCompatibility = targetCompatibility = JavaVersion.VERSION_16

    // copy artifacts to root build folder after build
    tasks.getByName("build").doLast {
        String version = project.name == "ares-installer" ? project.installerVersion : project.aresVersion
        copy {
            from "${project.rootProject.rootDir}/${project.name}/build/libs/${project.name}-$version-release.jar"
            into "${project.rootProject.rootDir}/build"
        }
    }
}

task testForge(type: GradleBuild) {
    group = "ares"
    description = "builds the forge version of Ares, then copies the jar into the mods folder"

    tasks = [":ares-forge:build"]

    doLast {
        copy {
            from "build/ares-forge-${project.aresVersion}-release.jar"
            into getModsFolder()
        }
    }
}

task testFabric(type: GradleBuild) {
    group = "ares"
    description = "builds the fabric version of Ares, then copies the jar into the mods folder"

    tasks = [":ares-fabric:build"]

    doLast {
        copy {
            from "build/ares-fabric-${project.aresVersion}-release.jar"
            into getModsFolder()
        }
    }
}

task testFabric_1_16(type: GradleBuild) {
    group = "ares"
    description = "builds the fabric 1.16 version of Ares, then copies the jar into the mods folder"

    tasks = [":ares-fabric-1.16:build"]

    doLast {
        copy {
            from "build/ares-fabric-1.16-${project.aresVersion}-release.jar"
            into getModsFolder()
        }
    }
}

task testFabric_1_17(type: GradleBuild) {
    group = "ares"
    description = "builds the fabric 1.17 version of Ares, then copies the jar into the mods folder"

    tasks = [":ares-fabric-1.17:build"]

    doLast {
        copy {
            from "build/ares-fabric-1.17-${project.aresVersion}-release.jar"
            into getModsFolder()
        }
    }
}


task setupWorkspace(type: GradleBuild) {
    group = "ares"
    description = "sets up all development environments for all versions of ares"

    tasks = [":ares-forge:classes", ":ares-fabric:genSources", ":ares-fabric-1.16:genSources", ":ares-fabric-1.17:genSources"]
}

private static String getModsFolder() {
    if(System.getProperty("os.name").toLowerCase().contains("nux")) {
        return System.getProperty("user.home") + "/.minecraft/mods/"
    } else if(System.getProperty("os.name").toLowerCase().contains("darwin") || System.getProperty("os.name").toLowerCase().contains("mac")) {
        return System.getProperty("user.home") + "/Library/Application Support/minecraft/mods/"
    } else if(System.getProperty("os.name").toLowerCase().contains("win")) {
        return System.getenv("APPDATA") + File.separator + ".minecraft" + File.separator + "mods" + File.separator
    }
    throw new RuntimeException("OS NOT FOUND")
}
