-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
github-actions
committed
Apr 12, 2024
1 parent
3791b7e
commit bc0fa7d
Showing
49 changed files
with
2,862 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Architectury Template Generator</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
|
||
<body> | ||
<h1>Architectury Template Generator</h1> | ||
|
||
<div class="horizontal-flow"> | ||
<fieldset> | ||
<legend>Mod properties</legend> | ||
|
||
<h2>Mod name</h2> | ||
<label for="mod-name-input" class="property-description">The human-readable name of your mod.</label> | ||
<input type="text" id="mod-name-input"> | ||
|
||
<h2>Mod ID (optional)</h2> | ||
<label for="mod-id-input" id="mod-id-label" class="property-description">A unique ID for your mod.</label> | ||
<input type="text" id="mod-id-input"> | ||
|
||
<h2>Package name</h2> | ||
<label for="package-input" class="property-description">A unique package name for your mod.</label> | ||
<input type="text" id="package-input"> | ||
|
||
<h2><label for="minecraft-version-select">Minecraft version</label></h2> | ||
<select id="minecraft-version-select"> | ||
</select> | ||
|
||
<h2>Mappings</h2> | ||
<span class="property-description">The set of names used for Minecraft code.</span> | ||
<div> | ||
<input type="radio" name="mappings" id="mojang-mappings-input" mappingset="Mojang" checked> | ||
<label for="mojang-mappings-input"> | ||
<span class="label-heading">Official Mojang mappings</span> | ||
<span class="property-description">The official obfuscation maps published by Mojang.</span> | ||
</label> | ||
</div> | ||
<div> | ||
<input type="radio" name="mappings" mappingset="Yarn" id="yarn-input"> | ||
<label for="yarn-input"> | ||
<span class="label-heading">Yarn</span> | ||
<span class="property-description">A libre mapping set maintained by FabricMC.</span> | ||
</label> | ||
</div> | ||
</fieldset> | ||
|
||
<div class="vertical-flow"> | ||
<fieldset> | ||
<legend>Mod loaders</legend> | ||
|
||
<h2>Project type</h2> | ||
<div id="project-type-toggles"> | ||
<label class="toggle-button"> | ||
<input type="radio" name="project-type" id="multiplatform-input" projecttype="Multiplatform" | ||
checked>Multiplatform | ||
</label><label class="toggle-button"> | ||
<input type="radio" name="project-type" id="neoforge-project-input" | ||
projecttype="NeoForge">NeoForge | ||
</label><label class="toggle-button"> | ||
<input type="radio" name="project-type" id="forge-project-input" projecttype="Forge">Forge | ||
</label> | ||
</div> | ||
|
||
<div id="multiplatform-settings"> | ||
<h2>Subprojects</h2> | ||
<div class="multicol"> | ||
<div> | ||
<div> | ||
<input type="checkbox" id="fabric-loader-input"> | ||
<label for="fabric-loader-input">Fabric</label> | ||
</div> | ||
<div> | ||
<input type="checkbox" id="forge-loader-input"> | ||
<label for="forge-loader-input">Forge</label> | ||
</div> | ||
<div> | ||
<input type="checkbox" id="neoforge-loader-input"> | ||
<label for="neoforge-loader-input">NeoForge</label> | ||
</div> | ||
<div> | ||
<input type="checkbox" id="quilt-loader-input"> | ||
<label for="quilt-loader-input">Quilt</label> | ||
</div> | ||
</div> | ||
<hr> | ||
<div> | ||
<h3>Additional subprojects</h3> | ||
<div> | ||
<input type="checkbox" id="fabric-like-input"> | ||
<label for="fabric-like-input"> | ||
<span class="label-heading">Fabric-like</span> | ||
<span class="property-description">Shared code between Fabric and Quilt.</span> | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h2>Dependencies</h2> | ||
<div> | ||
<input type="checkbox" id="architectury-api-input" checked> | ||
<label for="architectury-api-input">Architectury API</label> | ||
</div> | ||
</div> | ||
</fieldset> | ||
|
||
<fieldset> | ||
<legend>Generate</legend> | ||
|
||
<button id="generate-button">Generate template</button> | ||
<div id="error-message-container" class="hidden"></div> | ||
</fieldset> | ||
</div> | ||
</div> | ||
|
||
<script type="module" src="script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import init, { create_state, generate, is_valid_mod_id, list_all_minecraft_versions, supports_neoforge, to_mod_id, validate_mod_id } from "./templateer.js"; | ||
await init(); | ||
|
||
const state = create_state(); | ||
|
||
// Set up Minecraft version dropdown with contents | ||
const mcSelect = document.getElementById("minecraft-version-select"); | ||
mcSelect.onchange = refreshAvailablePlatforms; | ||
|
||
for (const version of list_all_minecraft_versions().reverse()) { | ||
const option = document.createElement("option"); | ||
option.textContent = version; | ||
mcSelect.appendChild(option); | ||
} | ||
|
||
// Hide multiplatform settings when deselected | ||
const projectTypeToggles = document.getElementById("project-type-toggles").getElementsByTagName("input"); | ||
const multiplatformInput = document.getElementById("multiplatform-input"); | ||
const multiplatformSettings = document.getElementById("multiplatform-settings"); | ||
|
||
for (const input of projectTypeToggles) { | ||
input.onchange = refreshDisplayedProjectType; | ||
}; | ||
|
||
// Add listeners to Fabric and Quilt checkboxes for controlling the Fabric-like checkbox, | ||
// and refresh the Fabric-like status according to the default state. | ||
document.getElementById("fabric-loader-input").onchange = refreshFabricLikeCheckbox; | ||
document.getElementById("quilt-loader-input").onchange = refreshFabricLikeCheckbox; | ||
refreshFabricLikeCheckbox(); | ||
|
||
// Add generated mod id placeholder when not specified manually | ||
const modNameInput = document.getElementById("mod-name-input"); | ||
const modIdInput = document.getElementById("mod-id-input"); | ||
|
||
modNameInput.oninput = () => { | ||
refreshModIdPlaceholder(); | ||
validateModId(); | ||
}; | ||
|
||
function refreshModIdPlaceholder() { | ||
modIdInput.placeholder = to_mod_id(modNameInput.value) ?? ""; | ||
} | ||
|
||
// Validate mod ids | ||
const modIdLabel = document.getElementById("mod-id-label"); | ||
modIdInput.oninput = validateModId; | ||
|
||
function validateModId() { | ||
const validation = validate_mod_id(getModId()); | ||
|
||
if (validation[0]) { | ||
modIdLabel.removeAttribute("error"); | ||
} else { | ||
modIdLabel.setAttribute("error", validation[1]); | ||
} | ||
} | ||
|
||
function isModIdValid() { | ||
return is_valid_mod_id(getModId()); | ||
} | ||
|
||
function getModId() { | ||
let value = modIdInput.value; | ||
if (value === "") { | ||
value = modIdInput.placeholder; | ||
} | ||
return value; | ||
} | ||
|
||
function getProjectType() { | ||
for (const input of projectTypeToggles) { | ||
if (input.checked) { | ||
return input.getAttribute("projecttype"); | ||
} | ||
} | ||
} | ||
|
||
function getMappingSet() { | ||
for (const input of document.getElementsByTagName("input")) { | ||
if (input.name !== "mappings") continue; | ||
if (input.checked) { | ||
return input.getAttribute("mappingset"); | ||
} | ||
} | ||
} | ||
|
||
function updateState() { | ||
state.mod_name = modNameInput.value; | ||
state.mod_id = getModId(); | ||
state.package_name = document.getElementById("package-input").value; | ||
state.game_version = mcSelect.value; | ||
state.project_type = getProjectType(); | ||
state.mapping_set = getMappingSet(); | ||
state.subprojects.fabric = document.getElementById("fabric-loader-input").checked; | ||
state.subprojects.forge = document.getElementById("forge-loader-input").checked; | ||
state.subprojects.neoforge = document.getElementById("neoforge-loader-input").checked && isNeoForgeAvailable(); | ||
state.subprojects.quilt = document.getElementById("quilt-loader-input").checked; | ||
state.subprojects.fabric_likes = document.getElementById("fabric-like-input").checked && isFabricLikeAvailable(); | ||
state.dependencies.architectury_api = document.getElementById("architectury-api-input").checked; | ||
} | ||
|
||
function showError(error) { | ||
let container = document.getElementById("error-message-container"); | ||
container.textContent = error; | ||
container.classList.remove("hidden"); | ||
} | ||
|
||
function clearError() { | ||
let container = document.getElementById("error-message-container"); | ||
container.textContent = ""; | ||
container.classList.add("hidden"); | ||
} | ||
|
||
function refreshDisplayedProjectType() { | ||
if (multiplatformInput.checked) { | ||
multiplatformSettings.classList.remove("hidden"); | ||
} else { | ||
multiplatformSettings.classList.add("hidden"); | ||
} | ||
} | ||
|
||
function isFabricLikeAvailable() { | ||
const fabricInput = document.getElementById("fabric-loader-input"); | ||
const quiltInput = document.getElementById("quilt-loader-input"); | ||
return fabricInput.checked && quiltInput.checked; | ||
} | ||
|
||
function isNeoForgeAvailable() { | ||
const version = mcSelect.value; | ||
return supports_neoforge(version); | ||
} | ||
|
||
function refreshAvailablePlatforms() { | ||
const hasNeoForge = isNeoForgeAvailable(); | ||
const neoForgeProjectInput = document.getElementById("neoforge-project-input"); | ||
const neoForgeLoaderInput = document.getElementById("neoforge-loader-input"); | ||
neoForgeProjectInput.disabled = !hasNeoForge; | ||
neoForgeLoaderInput.disabled = !hasNeoForge; | ||
|
||
// Change project type if Neo is not available. | ||
if (!hasNeoForge && neoForgeProjectInput.checked) { | ||
multiplatformInput.checked = true; | ||
neoForgeProjectInput.checked = false; | ||
refreshDisplayedProjectType(); | ||
} | ||
} | ||
|
||
// Enables/disables the Fabric-like checkbox based on whether it can be selected for the current state. | ||
function refreshFabricLikeCheckbox() { | ||
const hasFabricLike = isFabricLikeAvailable(); | ||
const fabricLikeInput = document.getElementById("fabric-like-input"); | ||
fabricLikeInput.disabled = !hasFabricLike; | ||
} | ||
|
||
document.getElementById("generate-button").onclick = async () => { | ||
updateState(); | ||
|
||
if (state.mod_name === "") { | ||
showError("Mod name is empty"); | ||
return; | ||
} else if (!isModIdValid()) { | ||
showError("Mod ID is not valid"); | ||
return; | ||
} else if (state.package_name === "") { | ||
showError("Package name is empty"); | ||
return; | ||
} | ||
|
||
clearError(); | ||
await generate(state); | ||
}; | ||
|
||
// Apply initial state | ||
modNameInput.value = state.mod_name; | ||
modIdInput.value = state.mod_id; | ||
refreshModIdPlaceholder(); | ||
document.getElementById("package-input").value = state.package_name; | ||
document.getElementById("architectury-api-input").checked = state.dependencies.architectury_api; |
Oops, something went wrong.