import org.gradle.internal.os.OperatingSystem
plugins {
    id 'application'
    id 'java'
}
project.ext.lwjglVersion = "3.4.1"
project.ext.jomlVersion = "1.10.8"
project.ext.jomlprimitivesVersion = "1.10.0"
project.ext.lwjgl3awtVersion = "0.1.8"
project.ext.steamworks4jVersion = "1.9.0"
project.ext.steamworks4jserverVersion = "1.9.0"
project.ext.imguiVersion = "1.92.0"

switch (OperatingSystem.current()) {
	case OperatingSystem.LINUX:
		project.ext.lwjglNatives = "natives-linux"
		def osArch = System.getProperty("os.arch")
		if (osArch.startsWith("arm") || osArch.startsWith("aarch64")) {
			project.ext.lwjglNatives += osArch.contains("64") || osArch.startsWith("armv8") ? "-arm64" : "-arm32"
		} else if  (osArch.startsWith("ppc")) {
			project.ext.lwjglNatives += "-ppc64le"
		} else if  (osArch.startsWith("riscv")) {
			project.ext.lwjglNatives += "-riscv64"
		}
		break
	case OperatingSystem.MAC_OS:
		project.ext.lwjglNatives = System.getProperty("os.arch").startsWith("aarch64") ? "natives-macos-arm64" : "natives-macos"
		break
	case OperatingSystem.WINDOWS:
		def osArch = System.getProperty("os.arch")
		project.ext.lwjglNatives = osArch.contains("64")
			? "natives-windows${osArch.startsWith("aarch64") ? "-arm64" : ""}"
			: "natives-windows-x86"
		break
}

repositories {
	mavenCentral()
}

dependencies {
	implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
	implementation 'org.tinylog:tinylog-api:2.7.0'
	implementation 'org.tinylog:tinylog-impl:2.7.0'
	implementation "org.lwjgl:lwjgl"
	implementation "org.lwjgl:lwjgl-assimp"
	implementation "org.lwjgl:lwjgl-fmod"
	implementation "org.lwjgl:lwjgl-freetype"
	implementation "org.lwjgl:lwjgl-glfw"
	implementation "org.lwjgl:lwjgl-jawt"
	implementation "org.lwjgl:lwjgl-jemalloc"
	implementation "org.lwjgl:lwjgl-llvm"
	implementation "org.lwjgl:lwjgl-lmdb"
	implementation "org.lwjgl:lwjgl-meshoptimizer"
	implementation "org.lwjgl:lwjgl-odbc"
	implementation "org.lwjgl:lwjgl-openal"
	implementation "org.lwjgl:lwjgl-rpmalloc"
	implementation "org.lwjgl:lwjgl-shaderc"
	implementation "org.lwjgl:lwjgl-stb"
	implementation "org.lwjgl:lwjgl-vma"
	implementation "org.lwjgl:lwjgl-vulkan"
	implementation "org.lwjgl:lwjgl::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-assimp::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-freetype::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-glfw::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-jemalloc::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-llvm::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-lmdb::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-meshoptimizer::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-openal::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-rpmalloc::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-remotery:${lwjglVersion}"
	runtimeOnly "org.lwjgl:lwjgl-remotery:${lwjglVersion}:${lwjglNatives}"
	implementation "org.lwjgl:lwjgl-shaderc::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-stb::$lwjglNatives"
	implementation "org.lwjgl:lwjgl-vma::$lwjglNatives"
	if (lwjglNatives == "natives-macos" || lwjglNatives == "natives-macos-arm64") implementation "org.lwjgl:lwjgl-vulkan::$lwjglNatives"
	implementation "org.joml:joml:${jomlVersion}"
	implementation "org.joml:joml-primitives:${jomlprimitivesVersion}"
	implementation "org.lwjglx:lwjgl3-awt:${lwjgl3awtVersion}"
	implementation "com.code-disaster.steamworks4j:steamworks4j:${steamworks4jVersion}"
	implementation "com.code-disaster.steamworks4j:steamworks4j-server:${steamworks4jserverVersion}"
	implementation 'com.google.code.gson:gson:2.14.0'
	implementation "org.jcommander:jcommander:3.0"
	['', '-opengl', '-glfw'].each {
		implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
		implementation "org.lwjgl:lwjgl$it::natives-windows"
	}

	implementation "io.github.spair:imgui-java-binding:$imguiVersion"
	implementation "io.github.spair:imgui-java-lwjgl3:$imguiVersion"

	implementation "io.github.spair:imgui-java-natives-windows:$imguiVersion"
}