dmclc
Version:
Dolphin Minecraft Launcher Core
53 lines (52 loc) • 1.73 kB
JavaScript
export function modDisplayInfoToString(launcher, mod) {
let str = `${launcher.i18n("mod.id")}: ${mod.id}\n` +
`${launcher.i18n("mod.version")}: ${mod.version}\n`;
if (mod.name)
str += `${launcher.i18n("mod.name")}: ${mod.name}\n`;
if (mod.description)
str += `${launcher.i18n("mod.description")}: ${mod.description}\n`;
if (mod.license)
str += `${launcher.i18n("mod.license")}: ${mod.license}`;
return str;
}
export class ModInfo {
loader;
data;
launcher;
constructor(loader, data, launcher) {
this.loader = loader;
this.data = data;
this.launcher = launcher;
}
getInfo() {
return this.launcher.loaders.get(this.loader).getModInfo(this.data);
}
}
export class ModJarInfo {
path;
launcher;
// Some mod jars may have two or more manifests for many loaders.
// For example, there are both META-INF/mods.toml and fabric.mod.json in a jar.
manifests = [];
constructor(path, launcher) {
this.path = path;
this.launcher = launcher;
// do nothing
}
static async of(path, launcher, loaders) {
const obj = new ModJarInfo(path, launcher);
for (const name of loaders) {
const loader = launcher.loaders.get(name);
obj.manifests.push(...await loader.findModInfos(path));
}
return obj;
}
async tryGetModOnline(service) {
const contentService = this.launcher.contentServices.get(service);
if (contentService == undefined) {
await this.launcher.error("content_service.not_found");
return null;
}
return contentService.getVersionFromFile(this.path);
}
}