Skip to content

Commit

Permalink
Add option to show like FG, prevent space in mappings search, add JEI…
Browse files Browse the repository at this point in the history
… and Cloth Config
  • Loading branch information
shedaniel committed Jun 4, 2022
1 parent 78fb200 commit f92fad2
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CFDeps(
name: String,
val modId: Int,
val loaders: (ModFile, String) -> List<String>,
val notation: (String, String) -> String,
val notation: (loader: String, mc: String, version: String) -> String,
val versionGrabber: (ModFile) -> String,
val mavens: List<MavenData>,
) : Deps(name) {
Expand All @@ -21,7 +21,7 @@ class CFDeps(
gameVersion.gameVersionName to it
}
}.groupBy({ it.first }, { it.second }).forEach { (version, files) ->
val file = files.maxByOrNull { it.id } ?: return@forEach
val file = files.filter { it.releaseType != 3 }.maxByOrNull { it.id } ?: return@forEach
val modVersion = versionGrabber(file)
loaders(file, version).forEach { loader ->
val versionIdentifier = VersionIdentifier(
Expand All @@ -34,7 +34,7 @@ class CFDeps(
Dependency(
name = name,
type = DependencyType.Api,
notation = notation(loader, modVersion),
notation = notation(loader, version, modVersion),
version = modVersion
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.shedaniel.linkie.web.deps

import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import me.shedaniel.linkie.utils.info

class CombinedDeps(
name: String,
vararg val deps: Deps,
) : Deps(name) {
override suspend fun provideData(): Map<VersionIdentifier, Data> = coroutineScope {
data class Inner(
val mavens: MutableSet<MavenData> = mutableSetOf(),
val dependencies: MutableList<Dependency> = mutableListOf(),
)

val datas = mutableMapOf<VersionIdentifier, Inner>()
deps.map {
launch {
try {
info("Started dep cycle: ${it.name}")
it.provideData().also { data ->
data.forEach { (versionId, d) ->
val inner = datas.getOrPut(versionId, ::Inner)
inner.mavens.addAll(d.mavens)
inner.dependencies.addAll(d.dependencies)
}
info("Completed dep cycle: ${it.name}")
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}.joinAll()
return@coroutineScope datas.mapValues { (_, inner) ->
Data(
mavens = inner.mavens.toList(),
dependencies = inner.dependencies
)
}
}
}
82 changes: 69 additions & 13 deletions backend/src/main/kotlin/me/shedaniel/linkie/web/deps/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ val allDeps = listOf(
CFDeps(
"Architectury API", 419699,
loaders = { _, _ -> listOf("fabric", "forge") },
notation = { loader, version -> "dev.architectury:architectury-${if (loader == "quilt") "fabric" else loader}:$version" },
notation = { loader, _, version -> "dev.architectury:architectury-${if (loader == "quilt") "fabric" else loader}:$version" },
versionGrabber = { file -> file.displayName.substringAfterLast("v") },
mavens = listOf(
Deps.MavenData(
Expand All @@ -49,25 +49,81 @@ val allDeps = listOf(
),
)
),
CombinedDeps(
"shedaniel",
CFDeps(
"Roughly Enough Items", 310111,
loaders = { _, version ->
when {
version.tryToVersion() == null || version.toVersion().snapshot != null -> listOf("fabric")
version.toVersion() >= "1.16.5".toVersion() -> listOf("fabric", "forge")
version.toVersion() > "1.13.2".toVersion() -> listOf("fabric")
else -> listOf()
}
},
notation = { loader, _, version -> "me.shedaniel:RoughlyEnoughItems-$loader:$version" },
versionGrabber = { file -> file.displayName.substringAfterLast("v").replace(" Build ", "+build.") },
mavens = listOf(
Deps.MavenData(
url = "https://maven.shedaniel.me/",
),
)
),
CFDeps(
"Cloth Config", 348521,
loaders = { _, version ->
when {
version.tryToVersion() == null || version.toVersion().snapshot != null -> listOf("fabric")
version.toVersion() >= "1.16.5".toVersion() -> listOf("fabric", "forge")
else -> listOf("fabric")
}
},
notation = { loader, _, version ->
if ((version.tryToVersion()?.major ?: 0) >= 4 || loader == "forge") {
"me.shedaniel.cloth:cloth-config-$loader:$version"
} else {
"me.shedaniel.cloth:config-2:$version"
}
},
versionGrabber = { file -> file.displayName.substringAfterLast("v").replace(" Build ", "+build.") },
mavens = listOf(
Deps.MavenData(
url = "https://maven.shedaniel.me/",
),
)
),
),
CFDeps(
"Roughly Enough Items", 310111,
loaders = { _, version ->
when {
version.tryToVersion() == null || version.toVersion().snapshot != null -> listOf("fabric")
version.toVersion() >= "1.16.5".toVersion() -> listOf("fabric", "forge")
version.toVersion() > "1.13.2".toVersion() -> listOf("fabric")
else -> listOf()
"Mod Menu", 308702,
loaders = { _, _ -> listOf("fabric") },
notation = { _, _, version ->
if (version.contains("+build.")) {
"io.github.prospector:modmenu:$version"
} else if (version.contains("-")) {
"io.github.prospector.modmenu:ModMenu:$version"
} else {
"com.terraformersmc:modmenu:$version"
}
},
notation = { loader, version -> "me.shedaniel:RoughlyEnoughItems-$loader:$version" },
versionGrabber = { file -> file.displayName.substringAfterLast("v").replace(" Build ", "+build.") },
versionGrabber = { file -> file.fileName.substringAfterLast("-").replace(".jar", "") },
mavens = listOf(
Deps.MavenData(
url = "https://maven.shedaniel.me/",
url = "https://maven.terraformersmc.com/releases/",
),
)
),
CFDeps(
"Just Enough Items", 238222,
loaders = { _, _ -> listOf("forge") },
notation = { _, mc, version -> "mezz.jei:jei-$mc:$version" },
versionGrabber = { file -> file.displayName.substringAfterLast("-").replace(".jar", "") },
mavens = listOf(
Deps.MavenData(
subtitle = "Alternative Maven Repository",
url = "https://maven.architectury.dev/",
url = "https://dvs1.progwml6.com/files/maven/",
),
Deps.MavenData(
subtitle = "Fallback Maven Repository",
url = "https://modmaven.dev",
),
)
),
Expand Down
43 changes: 33 additions & 10 deletions frontend/src/app/dep-format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {usePreferenceStore} from "./preference-store"
import {useDependencySearchStore} from "./dependency-store"

export function formatMaven(url: string): string {
let codeLanguage = usePreferenceStore().codeLanguage
Expand All @@ -11,38 +12,60 @@ export function formatMaven(url: string): string {
}
}

export function formatDepLine(configuration: string, notation: string): string {
function isFG(): boolean {
let {loader, forgeGradle} = useDependencySearchStore()
return loader === "forge" && forgeGradle
}

export function formatDepLine(configuration: string, notation: string, wrap?: string): string {
let codeLanguage = usePreferenceStore().codeLanguage
if (!wrap) wrap = "\"%%\""
if (codeLanguage === "groovy") {
return `${configuration} "${notation}"`
return `${configuration} ${wrap.replace("%%", notation)}`
} else if (codeLanguage === "kotlin") {
return `${configuration}("${notation}")`
return `${configuration}(${wrap.replace("%%", notation)})`
} else {
return notation
}
}

export function formatDep(configuration: string, notation: string, block: boolean): string {
if (!block) return formatDepLine(configuration, notation)
export function formatDep(configuration: string, notation: string, block: boolean, wrap?: string): string {
if (!block) return formatDepLine(configuration, notation, wrap)
return `dependencies {
${formatDepLine(configuration, notation)}
${formatDepLine(configuration, notation, wrap)}
}`
}

export function formatApi(notation: string, block: boolean = true): string {
return formatDep("modApi", notation, block)
if (!isFG()) {
return formatDep("modApi", notation, block)
} else {
return formatDep("api", notation, block, `fg.deobf("%%")`)
}
}

export function formatImpl(notation: string, block: boolean = true): string {
return formatDep("modImplementation", notation, block)
if (!isFG()) {
return formatDep("modImplementation", notation, block)
} else {
return formatDep("implementation", notation, block, `fg.deobf("%%")`)
}
}

export function formatCompileOnly(notation: string, block: boolean = true): string {
return formatDep("modCompileOnly", notation, block)
if (!isFG()) {
return formatDep("modCompileOnly", notation, block)
} else {
return formatDep("compileOnly", notation, block, `fg.deobf("%%")`)
}
}

export function formatRuntimeOnly(notation: string, block: boolean = true): string {
return formatDep("modRuntimeOnly", notation, block)
if (!isFG()) {
return formatDep("modRuntimeOnly", notation, block)
} else {
return formatDep("runtimeOnly", notation, block, `fg.deobf("%%")`)
}
}

export const dependencyTypes = ["Api", "Implementation", "CompileOnly", "RuntimeOnly", "Mappings"] as const
Expand Down
13 changes: 2 additions & 11 deletions frontend/src/app/dependency-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,18 @@ interface State {
loader?: string,
version?: string,
allowSnapshots: boolean,
forgeGradle: boolean,
}

function newState(): State {
return {
allowSnapshots: false,
forgeGradle: false,
}
}

export const useDependencySearchStore = defineStore({
id: "dependency_search",
state: newState,
actions: {
setLoader(modLoader: string | undefined) {
this.loader = modLoader
},
setVersion(version: string | undefined) {
this.version = version
},
setAllowSnapshots(allowSnapshots: boolean) {
this.allowSnapshots = allowSnapshots
},
},
persist: true,
})
5 changes: 0 additions & 5 deletions frontend/src/app/preference-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ function newState(): State {
export const usePreferenceStore = defineStore({
id: "preference",
state: newState,
actions: {
setCodeLanguage(codeLanguage: CodeLanguage) {
this.codeLanguage = codeLanguage
},
},
persist: true,
})
18 changes: 15 additions & 3 deletions frontend/src/components/dependencies/DependencyFilterBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="flex flex-col md:flex-row">
<div class="px-4 whitespace-nowrap h-12">
<span class="align-middle">Loader</span>
<select class="select capitalize font-light rounded-none w-52"
<select class="select font-light rounded-none w-48"
@change="loader = (($event.target as any)?.value?.toLowerCase() ?? loader)" :value="loader ?? ''">
<option disabled selected>Select mod loader</option>
<option v-for="loader in loaders">
Expand All @@ -13,9 +13,21 @@
</select>
</div>

<div class="px-4 whitespace-nowrap h-12" v-if="loader === 'forge'">
<span class="align-middle">Build System</span>
<select class="select font-light rounded-none w-48"
@change="forgeGradle = (($event.target as any)?.value === 'ForgeGradle')" :value="forgeGradle ? 'ForgeGradle' : 'Architectury Loom'">
<option disabled selected>Select build system</option>
<option>Architectury Loom</option>
<option>ForgeGradle</option>
</select>
</div>
</div>

<div class="flex flex-col md:flex-row">
<div class="px-4 whitespace-nowrap h-12">
<span class="align-middle">Version</span>
<select class="select capitalize font-light rounded-none w-52"
<select class="select font-light rounded-none w-48"
@change="version = (($event.target as any)?.value ?? version)" :value="version ?? ''">
<option disabled selected>Select version</option>
<option v-for="v in applicableVersions">
Expand Down Expand Up @@ -47,7 +59,7 @@ import {mapWritableState} from "pinia"
export default defineComponent({
name: "DependencyFilterBlock",
computed: {
...mapWritableState(useDependencySearchStore, ["loader", "version", "allowSnapshots"]),
...mapWritableState(useDependencySearchStore, ["loader", "version", "allowSnapshots", "forgeGradle"]),
loaders(): string[] {
return Object.keys(this.searchData.versions)
},
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/dependencies/tab/CodeLanguageTab.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<template>
<button class="tab capitalize pl-2" :class="codeLanguage === language ? 'tab-active' : ''"
@click="setCodeLanguage(language)">
@click="codeLanguage = language">
{{ language.toLowerCase() }}
</button>
</template>

<script lang="ts">
import {defineComponent} from "vue"
import {mapActions, mapState} from "pinia"
import {mapActions, mapWritableState} from "pinia"
import {usePreferenceStore} from "../../../app/preference-store"
export default defineComponent({
name: "CodeLanguageTab",
computed: {
...mapState(usePreferenceStore, ["codeLanguage"]),
...mapWritableState(usePreferenceStore, ["codeLanguage"]),
},
methods: {
...mapActions(usePreferenceStore, ["setCodeLanguage"]),
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/mappings/MappingsFilterBlock.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="flex flex-col">
<SubHeader :add-padding="false" class="pb-2">Namespace</SubHeader>
<select class="select select-sm capitalize font-light p-0"
<select class="select select-sm font-light p-0"
@change="namespace = ($event.target as any)?.value?.toLowerCase() ?? namespace" :value="namespace ?? ''">
<option disabled selected>Select namespace</option>
<option v-for="namespace in namespaces">
Expand All @@ -19,7 +19,7 @@
</div>
</div>

<select class="select select-sm capitalize font-light p-0"
<select class="select select-sm font-light p-0"
@change="version = ($event.target as any)?.value ?? version" :value="version ?? ''">
<option disabled selected>Select version</option>
<option v-for="v in applicableVersions">
Expand Down Expand Up @@ -49,7 +49,7 @@

<div class="divider mt-0 mb-0"></div>
<SubHeader :add-padding="false" class="pb-2">Translate To</SubHeader>
<select class="select select-sm capitalize font-light p-0"
<select class="select select-sm font-light p-0"
@change="translateAs = ($event.target as any)?.value === 'Do not translate' ? undefined : ($event.target as any)?.value?.toLowerCase()" :value="translateAs ?? 'Do not translate'">
<option disabled selected>Select namespace</option>
<option>Do not translate</option>
Expand Down
Loading

0 comments on commit f92fad2

Please sign in to comment.