/* Define the repositories for the project. */
pluginManagement {
	repositories {
		gradlePluginPortal()
		google()

		maven {
			name = 'Fabric'
			url = 'https://maven.fabricmc.net/'
		}
		maven { // Used for Vanilla Minecraft's libraries
			name "Sponge"
			url "https://repo.spongepowered.org/repository/maven-public/"
		}

		/* The fallback repos. */
		mavenCentral()
	}
}

/* Define the name of root project. */
rootProject.name = 'fuji'

/* Include child projects. */
include("common")
include("crowdin")
include("docs")
include("fabric")
include("checker")
include("weaver")
include("evaluator")

/* Define shared variables. */
gradle.ext.languageDirectoryName = "languages"

/* Loads the version_properties file for the currently selected Minecraft version. */
def loadProperties() {
	def defaultMcVersion = "1.20.1"

	def mcVersion = ""
	def mcVers = fileTree("version_properties").files.name // Get all the files in "version_properties"
	for (int i = 0; i < mcVers.size(); i++) {
		mcVers[i] = mcVers[i].replaceAll("\\.properties", "") // As we are getting the file names, we should remove the ".properties" at the end to get the versions
	}

	mcVers.sort() // Sort so it always goes from oldest to newest

	int mcIndex = -1
	println "Avalible MC versions: ${mcVers}"
	if (hasProperty("mcVer")) {
		mcVersion = mcVer
		mcIndex = mcVers.indexOf(mcVer)
	}
	if (mcIndex == -1) {
		println "No mcVer set or the set mcVer is invalid! Defaulting to ${defaultMcVersion}."
		println "Tip: Use -PmcVer=\"${defaultMcVersion}\" in cmd arg to set mcVer."
		mcVersion = defaultMcVersion
		mcIndex = mcVers.indexOf(defaultMcVersion)
		assert mcIndex != -1
	}

	println "Loading properties file at " + mcVersion + ".properties"
	def props = new Properties()
	props.load(new FileInputStream("$rootDir/version_properties/"+"$mcVersion"+".properties"))

	props.each { prop ->
		gradle.ext.set(prop.key, prop.value)
//		println "Add prop in gradle.ext [key:" + prop.key + ", value:" + prop.value + "]"
	}
	gradle.ext.mcVers = mcVers
	gradle.ext.mcIndex = mcIndex
}
loadProperties()

