@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
60 lines (59 loc) • 2.51 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Utilities_1 = __importDefault(require("../../core/Utilities"));
const CreatorToolsHost_1 = __importDefault(require("../CreatorToolsHost"));
class GalleryReader {
defaultProjectImage;
/**
* Maps a GitHub repository name (e.g., "minecraft-samples") to the shortened
* local folder name used under res/samples/<owner>/. These must match the
* `replaceFirstFolderWith` values in app/reslist/*.resources.json.
*
* Falls back to the conventional `<repoName>-<branch>` pattern for unknown repos.
*/
static repoFolderMap = {
"minecraft-samples": "samples",
"minecraft-scripting-samples": "script-samples",
"minecraft-gametests": "gametests",
};
static getLocalRepoFolder(gitHubRepoName, gitHubBranch) {
return GalleryReader.repoFolderMap[gitHubRepoName] ?? gitHubRepoName + "-" + (gitHubBranch ?? "main");
}
constructor(defaultProjectImage) {
this.defaultProjectImage = defaultProjectImage;
}
getStandinImage() {
return this.defaultProjectImage;
}
getGalleryImage(item) {
if (item.logoImage === undefined && item.localLogo === undefined) {
return this.getStandinImage();
}
let imagePath = item.logoImage;
if (imagePath === undefined) {
imagePath = CreatorToolsHost_1.default.getVanillaContentRoot() + "res/latest/van/serve/resource_pack/textures/" + item.localLogo;
}
if (item.logoImage === undefined)
return imagePath;
if (item.gitHubRepoName === "bedrock-samples") {
imagePath = CreatorToolsHost_1.default.getVanillaContentRoot() + Utilities_1.default.ensureEndsWithSlash("res/latest/van/serve/");
}
else {
imagePath =
CreatorToolsHost_1.default.contentWebRoot +
"res/samples/" +
item.gitHubOwner +
"/" +
GalleryReader.getLocalRepoFolder(item.gitHubRepoName ?? "", item.gitHubBranch) +
"/";
}
imagePath += Utilities_1.default.ensureNotStartsWithSlash(item.logoImage);
return imagePath;
}
}
exports.default = GalleryReader;