Skip to content

Commit

Permalink
Add pack name setting
Browse files Browse the repository at this point in the history
Also, the in-game pack name will now no longer have "HoloPrint: " at the start, and if the default pack name is > 40 characters it will be shortened.
  • Loading branch information
SuperLlama88888 committed Nov 26, 2024
1 parent e0416da commit 18a4a9e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
22 changes: 18 additions & 4 deletions HoloPrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function makePack(structureFiles, config = {}, resourcePackStack, p
console.info("Finished reading structure NBTs!");
console.log("NBTs:", nbts);
let structureSizes = nbts.map(nbt => nbt["size"].map(x => +x)); // Stored as Number instances: https://github.com/Offroaders123/NBTify/issues/50
let structureNames = structureFiles.map(structureFile => structureFile.name.replace(/(\.holoprint)?\.[^.]+$/, ""));
let packName = config.PACK_NAME ?? getDefaultPackName(structureFiles);

// Make the pack
let loadedStuff = await loadStuff({
Expand Down Expand Up @@ -667,9 +667,9 @@ export async function makePack(structureFiles, config = {}, resourcePackStack, p
}
})));
hudScreenUI["material_list"]["size"][1] = finalisedMaterialList.length * 12 + 12; // 12px for each item + 12px for the heading
hudScreenUI["material_list_heading"]["controls"][1]["pack_name"]["text"] += structureNames.join(", ");
hudScreenUI["material_list_heading"]["controls"][1]["pack_name"]["text"] += packName;

manifest["header"]["name"] = `§uHoloPrint:§r ${structureNames.join(", ")}`;
manifest["header"]["name"] = packName;
manifest["header"]["description"] = `§u★HoloPrint§r resource pack generated on §o${(new Date()).toLocaleString()}§r\nDeveloped by §l§6SuperLlama88888§r`;
if(config.AUTHORS.length) {
manifest["header"]["description"] += `\nStructure made by ${config.AUTHORS.join(" and ")}`;
Expand Down Expand Up @@ -734,7 +734,7 @@ export async function makePack(structureFiles, config = {}, resourcePackStack, p
});
}

return new File([zippedPack], `${structureNames.join("+")}.holoprint.mcpack`);
return new File([zippedPack], `${packName}.holoprint.mcpack`);
}
/**
* Retrieves the structure file from a completed HoloPrint resource pack
Expand Down Expand Up @@ -765,6 +765,18 @@ export async function updatePack(resourcePack, config, resourcePackStack, previe
}
return await makePack(structureFile, config, resourcePackStack, previewCont);
}
/**
* Returns the default pack name that would be used if no pack name is specified.
* @param {Array<File>} structureFiles
* @returns {String}
*/
export function getDefaultPackName(structureFiles) {
let defaultName = structureFiles.map(structureFile => structureFile.name.replace(/(\.holoprint)?\.[^.]+$/, "")).join(", ");
if(defaultName.length > 40) {
defaultName = `${defaultName.slice(0, 19)}...${defaultName.slice(-19)}`
}
return defaultName;
}

/**
* Adds default config options to a potentially incomplete config object.
Expand All @@ -791,6 +803,7 @@ function addDefaultConfig(config) {
SPAWN_ANIMATION_LENGTH: 0.4, // in seconds
WRONG_BLOCK_OVERLAY_COLOR: [1, 0, 0, 0.3],
MATERIAL_LIST_LANGUAGE: "en_US",
PACK_NAME: undefined,
PACK_ICON_BLOB: undefined,
AUTHORS: [],
DESCRIPTION: undefined,
Expand Down Expand Up @@ -1266,6 +1279,7 @@ function stringifyWithFixedDecimals(value) {
* @property {Number} SPAWN_ANIMATION_LENGTH Length of each individual block's spawn animation (seconds)
* @property {Array<Number>} WRONG_BLOCK_OVERLAY_COLOR Clamped colour quartet
* @property {String} MATERIAL_LIST_LANGUAGE The language code, as appearing in `texts/languages.json`
* @property {String|undefined} PACK_NAME The name of the completed pack; will default to the structure file names
* @property {Blob} PACK_ICON_BLOB Blob for `pack_icon.png`
* @property {Array<String>} AUTHORS
* @property {String|undefined} DESCRIPTION
Expand Down
3 changes: 3 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ input[type="number"], input[type="text"], textarea {
outline-width: thin;
accent-color: auto;
}
input[type="text"]::placeholder {
text-overflow: ellipsis;
}
button:not(:disabled):hover, input[type="file"]:not(:disabled):hover::file-selector-button, select:not(:disabled):hover, .buttonlike:hover {
background: #E8C8E8;
}
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ <h1>HoloPrint</h1>
<label for="metadataTab" class="buttonlike">Metadata</label>
<fieldset>
<legend>Metadata</legend>
<label>Pack name: <code><input type="text" name="packName"/></code></label>
<label>Pack icon (<code>*.png</code>): <input type="file" accept=".png" name="packIcon"/></label>
<label>Structure author: <input type="text" placeholder="MinecraftLover123" name="author"/></label>
<label>Description:<br/><textarea placeholder="This is my epic house!" rows="3" cols="20" name="description"></textarea></label>
Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let dropFileNotice;
let generatePackForm;
let generatePackFormSubmitButton;
let structureFilesInput;
let packNameInput;
let logger;

let supabaseLogger;
Expand All @@ -47,6 +48,8 @@ document.onEvent("DOMContentLoaded", async () => {
generatePackForm = selectEl("#generatePackForm");
dropFileNotice = selectEl("#dropFileNotice");
structureFilesInput = generatePackForm.elements.namedItem("structureFiles");
packNameInput = generatePackForm.elements.namedItem("packName");
structureFilesInput.onEventAndNow("input", updatePackNameInputPlaceholder);

if(location.search == "?loadFile") {
window.launchQueue?.setConsumer(async launchParams => {
Expand Down Expand Up @@ -152,16 +155,12 @@ async function handleInputFiles(files) {
[...structureFilesInput.files, ...structureFiles].forEach(structureFile => dataTransfer.items.add(structureFile));
structureFilesInput.files = dataTransfer.files;
}
updatePackNameInputPlaceholder();
}

async function handleLaunchFile(file) {
if(!file.name.endsWith(".mcstructure")) {
console.error(`File is not a structure file: ${file.name}`);
return;
}
let pack = await makePack([file]);
return pack;
function updatePackNameInputPlaceholder() {
packNameInput.setAttribute("placeholder", HoloPrint.getDefaultPackName([...structureFilesInput.files]));
}

async function temporarilyChangeText(el, text, duration = 2000) {
let originalText = el.innerText;
el.innerText = text;
Expand All @@ -188,6 +187,7 @@ async function makePack(structureFiles, localResourcePacks) {
TEXTURE_OUTLINE_ALPHA_DIFFERENCE_MODE: formData.get("textureOutlineAlphaDifferenceMode"),
DO_SPAWN_ANIMATION: formData.get("spawnAnimationEnabled"),
MATERIAL_LIST_LANGUAGE: formData.get("materialListLanguage"),
PACK_NAME: formData.get("packName") || undefined,
PACK_ICON_BLOB: formData.get("packIcon").size? formData.get("packIcon") : undefined,
AUTHORS: authors,
DESCRIPTION: formData.get("description") || undefined
Expand Down

0 comments on commit 18a4a9e

Please sign in to comment.