Skip to content

Commit

Permalink
feat: added curseforge links to mods on modpack mods page #716
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Apr 10, 2024
1 parent c80bf42 commit 7eafb71
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
29 changes: 20 additions & 9 deletions src/components/templates/modpack/ModpackMods.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
<loader v-if="!packInstalled && modsLoading" />
<template v-if="!packInstalled">
<recycle-scroller :items="simpleMods" key-field="fileId" :item-size="70" class="select-text scroller" v-slot="{ item }">
<div class=" flex gap-6 items-start mb-4" :key="item.fileId">
<img v-if="item.icon" :src="item.icon" class="rounded mt-2" width="40" alt="">
<div class="placeholder bg-black rounded mt-2" style="width: 40px; height: 40px" v-else-if="item.fileName !== ''"></div>
<div class="main">
<b class="mb-1 block">{{item.name || item.filename}}</b>
<p class="only-one-line">{{item.synopsis}}</p>
<div class="flex items-center gap-6 mb-4" :key="item.fileId">
<div class="flex gap-6 items-start flex-1">
<img v-if="item.icon" :src="item.icon" class="rounded mt-2" width="40" alt="">
<div class="placeholder bg-black rounded mt-2" style="width: 40px; height: 40px" v-else-if="item.fileName !== ''"></div>
<div class="main">
<b class="mb-1 block">{{item.name || item.filename}}</b>
<p class="only-one-line">{{item.synopsis}}</p>
</div>
</div>
<div>
<a @click="openExternal" class="curse-btn cursor-pointer" aria-label="Open on CurseForge" data-balloon-pos="down-right" v-if="item.curseSlug" :href="`https://curseforge.com/minecraft/mc-mods/${item.curseSlug}`">
<img src="../../../assets/curse-logo.svg" width="24" alt="Open on CurseForge" />
</a>
</div>
</div>
</recycle-scroller>
Expand All @@ -30,11 +37,15 @@
<div class="placeholder bg-black rounded mt-2" style="width: 40px; height: 40px" v-else-if="file.fileName !== ''"></div>

<div class="main flex-1 transition-opacity duration-200" :class="{'opacity-50': !file.enabled}">
<b class="mb-1 block">{{file.curse?.name || file.fileName.replace(".jar", "")}}</b>
<p class="only-one-line">{{file.curse?.synopsis ?? ""}}</p>
<b class="mb-1 block select-text">{{file.curse?.name || file.fileName.replace(".jar", "")}}</b>
<p class="only-one-line select-text" v-if="file.curse?.synopsis">{{file.curse?.synopsis}}</p>
<p class="only-one-line text-muted italic" v-else>(Not found on CurseForge)</p>
</div>

<div class="meta flex gap-4 items-center">
<div class="meta flex gap-6 items-center">
<a @click="openExternal" class="curse-btn cursor-pointer" aria-label="Open on CurseForge" data-balloon-pos="down-right" v-if="file.curse?.slug" :href="`https://curseforge.com/minecraft/mc-mods/${file.curse.slug}`">
<img src="../../../assets/curse-logo.svg" width="24" alt="Open on CurseForge" />
</a>
<div class="update" v-if="!instance.locked && modUpdatesAvailableKeys.includes(file.sha1) && !updatingModShas.includes(file.sha1)" :aria-label="`Update available (${modUpdates[file.sha1][0].fileName} -> ${modUpdates[file.sha1][1].name})`" data-balloon-pos="down-right" @click="updateMod(file.sha1)">
<font-awesome-icon icon="download" :fixed-width="true" />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/core/@types/javaApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ export interface CurseMetadata {
curseProject: number;
curseFile: number;
name: string;
slug: string;
synopsis: string;
icon: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private static CompletableFuture<Void> pollMod(InstanceModsData data, Completabl
manifest.getId(),
version.getId(),
version.getName(),
curseData.slug(),
curseData.synopsis(),
curseData.icon()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ public record CurseMetadata(
long curseProject,
long curseFile,
@Nullable String name,
@Nullable String slug,
@Nullable String synopsis,
@Nullable String icon
) {

public static CurseMetadata basic(long project, long file) {
return new CurseMetadata(Type.BASIC, project, file, null, null, null);
return new CurseMetadata(Type.BASIC, project, file, null, null, null, null);
}

public static CurseMetadata full(long project, long file, @Nullable String name, @Nullable String synopsis, @Nullable String icon) {
return new CurseMetadata(Type.FULL, project, file, name, synopsis, icon);
public static CurseMetadata full(long project, long file, @Nullable String name, @Nullable String slug, @Nullable String synopsis, @Nullable String icon) {
return new CurseMetadata(Type.FULL, project, file, name, slug, synopsis, icon);
}

public enum Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public CurseMetadataCache(Path file) {
String name = mod.getName();
String synopsis = mod.getSynopsis();
String icon = mod.getIcon();
return CurseMetadata.full(projectId, fileId, name, synopsis, icon);
String slug = mod.getCurseSlug();
return CurseMetadata.full(projectId, fileId, name, slug, synopsis, icon);
}

FileMetadata metadata = queryMetadata(sha1);
Expand All @@ -87,12 +88,23 @@ public CurseMetadataCache(Path file) {
version = mod.findVersion(curseFile);
}

if (version == null) return CurseMetadata.full(curseProject, curseFile, null, null, null);

if (version == null) return CurseMetadata.full(curseProject, curseFile, null, null, null, null);

var curseSlug = mod.getLinks()
.stream()
.filter(e -> e.getType().equals("curseforge"))
.map(e -> {
var parts = e.getLink().split("/");
return parts[parts.length - 1];
})
.findFirst()
.orElse(null);

return CurseMetadata.full(
curseProject,
curseFile,
mod.getName(),
curseSlug,
mod.getSynopsis(),
!mod.getArt().isEmpty() ? mod.getArt().get(0).getUrl() : null // TODO, this is so dumb.
);
Expand Down Expand Up @@ -182,7 +194,7 @@ public record FileMetadata(
) {

public CurseMetadata toCurseInfo() {
return CurseMetadata.full(curseProject, curseFile, name, synopsis, icon);
return CurseMetadata.full(curseProject, curseFile, name, curseSlug, synopsis, icon);
}
}

Expand Down

0 comments on commit 7eafb71

Please sign in to comment.