aboutsummaryrefslogtreecommitdiff
path: root/sharedVariables/src
diff options
context:
space:
mode:
Diffstat (limited to 'sharedVariables/src')
-rw-r--r--sharedVariables/src/MappingStyle.kt6
-rw-r--r--sharedVariables/src/MinecraftVersion.kt25
-rw-r--r--sharedVariables/src/MultiVersionStage.kt43
-rw-r--r--sharedVariables/src/NoOp.kt11
-rw-r--r--sharedVariables/src/ProjectTarget.kt74
-rw-r--r--sharedVariables/src/SHVersionInfo.kt12
-rw-r--r--sharedVariables/src/Util.kt7
7 files changed, 178 insertions, 0 deletions
diff --git a/sharedVariables/src/MappingStyle.kt b/sharedVariables/src/MappingStyle.kt
new file mode 100644
index 000000000..604495ce1
--- /dev/null
+++ b/sharedVariables/src/MappingStyle.kt
@@ -0,0 +1,6 @@
+package at.skyhanni.sharedvariables
+
+enum class MappingStyle(val identifier: String) {
+ SEARGE("srg"),
+ YARN("yarn"),
+}
diff --git a/sharedVariables/src/MinecraftVersion.kt b/sharedVariables/src/MinecraftVersion.kt
new file mode 100644
index 000000000..7384c8fbd
--- /dev/null
+++ b/sharedVariables/src/MinecraftVersion.kt
@@ -0,0 +1,25 @@
+package at.skyhanni.sharedvariables
+
+import org.gradle.jvm.toolchain.JavaLanguageVersion
+
+enum class MinecraftVersion(
+ val versionName: String,
+ val javaVersion: Int,
+) {
+ MC189("1.8.9", 8),
+ MC11200("1.12", 8),
+ MC11202("1.12.2", 8),
+ MC1144("1.14.4", 8),
+ MC11605("1.16.5", 8),
+ MC121("1.21", 21),
+ ;
+
+ val javaLanguageVersion = JavaLanguageVersion.of(javaVersion)
+
+ val versionNumber = run {
+ val parts = versionName.split('.').mapTo(mutableListOf()) { it.toInt() }
+ if (parts.size == 2) parts.add(0)
+ require(parts.size == 3)
+ parts[0] * 10000 + parts[1] * 100 + parts[2]
+ }
+}
diff --git a/sharedVariables/src/MultiVersionStage.kt b/sharedVariables/src/MultiVersionStage.kt
new file mode 100644
index 000000000..78914a91d
--- /dev/null
+++ b/sharedVariables/src/MultiVersionStage.kt
@@ -0,0 +1,43 @@
+package at.skyhanni.sharedvariables
+
+import java.io.File
+import java.util.Properties
+
+enum class MultiVersionStage(val label: String) {
+ OFF("off"),
+ PREPROCESS_ONLY("preprocess-only"),
+ FULL("compile")
+ ;
+
+ fun shouldCompile(projectTarget: ProjectTarget): Boolean {
+ if (projectTarget == ProjectTarget.MAIN) return true
+ return when (this) {
+ OFF -> false
+ PREPROCESS_ONLY -> false
+ FULL -> projectTarget == ProjectTarget.MODERN
+ }
+ }
+
+ fun shouldCreateProject(projectTarget: ProjectTarget): Boolean {
+ if (projectTarget == ProjectTarget.MAIN) return true
+ return when (this) {
+ OFF -> false
+ PREPROCESS_ONLY -> true
+ FULL -> true
+ }
+ }
+
+
+ companion object {
+ lateinit var activeState: MultiVersionStage
+ fun initFrom(file: File) {
+ val prop = Properties()
+ if (file.exists()) {
+ file.inputStream().use(prop::load)
+ }
+ val multiVersion = prop["skyhanni.multi-version"]
+ activeState = MultiVersionStage.values().find { it.label == multiVersion } ?: OFF
+ println("SkyHanni multi version stage loaded: $activeState")
+ }
+ }
+}
diff --git a/sharedVariables/src/NoOp.kt b/sharedVariables/src/NoOp.kt
new file mode 100644
index 000000000..d0103a956
--- /dev/null
+++ b/sharedVariables/src/NoOp.kt
@@ -0,0 +1,11 @@
+package at.skyhanni.sharedvariables
+
+import org.gradle.api.Plugin
+/**
+ * This class is a no op plugin. It can be applied to any project or gradle workspace and serves only as a marker
+ * for gradle to pull in the other classes in the sharedVariables project. We use a subproject rather than buildSrc
+ * since buildSrc is not available during settings configuration time (and also buildSrc tends to be slower).
+ */
+class NoOp : Plugin<Any> {
+ override fun apply(target: Any) {}
+}
diff --git a/sharedVariables/src/ProjectTarget.kt b/sharedVariables/src/ProjectTarget.kt
new file mode 100644
index 000000000..9bf46c781
--- /dev/null
+++ b/sharedVariables/src/ProjectTarget.kt
@@ -0,0 +1,74 @@
+package at.skyhanni.sharedvariables
+
+private fun yarn(version: String): String = "net.fabricmc:yarn:${version}:v2"
+
+enum class ProjectTarget(
+ val projectName: String,
+ val minecraftVersion: MinecraftVersion,
+ val mappingDependency: String,
+ val mappingStyle: MappingStyle,
+ val forgeDep: String?,
+ linkTo: String?,
+) {
+ MAIN(
+ "1.8.9",
+ MinecraftVersion.MC189,
+ "de.oceanlabs.mcp:mcp_stable:22-1.8.9@zip",
+ MappingStyle.SEARGE,
+ "net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9",
+ "BRIDGE112",
+ ),
+ BRIDGE112(
+ "1.12.2",
+ MinecraftVersion.MC11202,
+ "de.oceanlabs.mcp:mcp_stable:39-1.12@zip",
+ MappingStyle.SEARGE,
+ "net.minecraftforge:forge:1.12.2-14.23.5.2847",
+ "BRIDGE116FORGE",
+ ),
+ BRIDGE116FORGE(
+ "1.16.5-forge",
+ MinecraftVersion.MC11605,
+ "official",
+ MappingStyle.SEARGE,
+ "net.minecraftforge:forge:1.16.5-36.2.39",
+ "BRIDGE116FABRIC",
+ ),
+ BRIDGE116FABRIC(
+ "1.16.5",
+ MinecraftVersion.MC11605,
+ yarn("1.16.5+build.10"),
+ MappingStyle.YARN,
+ null,
+ "MODERN",
+ ),
+ MODERN(
+ "1.21",
+ MinecraftVersion.MC121,
+ yarn("1.21+build.9"),
+ MappingStyle.YARN,
+ null,
+ null,
+ )
+ ;
+
+ val isBridge get() = name.contains("bridge")
+
+ val linkTo by lazy {
+ if (linkTo == null) null
+ else {
+ ProjectTarget.values().find { it.name == linkTo }!!
+ }
+ }
+ val parent by lazy {
+ values().find { it.linkTo == this }
+ }
+ val isForge get() = forgeDep != null
+ val isFabric get() = forgeDep == null
+
+ val projectPath get() = ":$projectName"
+
+ companion object {
+ fun activeVersions() = values().filter { MultiVersionStage.activeState.shouldCreateProject(it) }
+ }
+}
diff --git a/sharedVariables/src/SHVersionInfo.kt b/sharedVariables/src/SHVersionInfo.kt
new file mode 100644
index 000000000..2f948897e
--- /dev/null
+++ b/sharedVariables/src/SHVersionInfo.kt
@@ -0,0 +1,12 @@
+package at.skyhanni.sharedvariables
+
+object SHVersionInfo {
+ val gitHash by lazy {
+ val proc = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
+ .redirectOutput(ProcessBuilder.Redirect.PIPE)
+ .redirectInput(ProcessBuilder.Redirect.PIPE)
+ .start()
+ proc.waitFor()
+ proc.inputStream.readBytes().decodeToString().trim()
+ }
+}
diff --git a/sharedVariables/src/Util.kt b/sharedVariables/src/Util.kt
new file mode 100644
index 000000000..750a73cbe
--- /dev/null
+++ b/sharedVariables/src/Util.kt
@@ -0,0 +1,7 @@
+package at.skyhanni.sharedvariables
+
+import org.gradle.jvm.toolchain.JavaLanguageVersion
+
+fun JavaLanguageVersion.versionString() =
+ if (asInt() < 9) "1." + asInt()
+ else asInt().toString()