Skip to content

Commit

Permalink
Disable Architectury API where a Forge port does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiancc committed Dec 4, 2024
1 parent 216995d commit 6c4b274
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
30 changes: 28 additions & 2 deletions res/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import init, {
list_all_minecraft_versions,
supports_forge,
supports_neoforge,
arch_api_supports_forge,
to_mod_id,
validate_mod_id
} from "./templateer.js";
Expand All @@ -35,6 +36,10 @@ for (const input of projectTypeToggles) {
input.onchange = refreshDisplayedProjectType;
};

// Add listeners to Forge checkboxes for controlling the Architectury API checkbox.
document.getElementById("forge-loader-input").onchange = refreshArchitecturySupport;
refreshArchitecturySupport()

// 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;
Expand Down Expand Up @@ -109,7 +114,7 @@ function updateState() {
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;
state.dependencies.architectury_api = document.getElementById("architectury-api-input").checked && isArchitecturyApiAvailable();
}

function showError(error) {
Expand Down Expand Up @@ -148,9 +153,20 @@ function isForgeAvailable() {
return supports_forge(version);
}

function isArchitecturyApiAvailable() {
const version = mcSelect.value;
if (document.getElementById("forge-loader-input").checked) {
return arch_api_supports_forge(version)
}
else {
return true;
}
}

function refreshAvailablePlatforms() {
refreshForgeLikePlatform(isNeoForgeAvailable(), "neoforge");
refreshForgeLikePlatform(isForgeAvailable(), "forge");
refreshArchitecturySupport()
}

function refreshForgeLikePlatform(available, id) {
Expand All @@ -167,6 +183,16 @@ function refreshForgeLikePlatform(available, id) {
}
}

function refreshArchitecturySupport() {
console.log(isArchitecturyApiAvailable())
if (!isArchitecturyApiAvailable()) {
document.getElementById("architectury-api-input").disabled = true
}
else {
document.getElementById("architectury-api-input").disabled = false
}
}

// Enables/disables the Fabric-like checkbox based on whether it can be selected for the current state.
function refreshFabricLikeCheckbox() {
const hasFabricLike = isFabricLikeAvailable();
Expand Down Expand Up @@ -198,4 +224,4 @@ modIdInput.value = state.mod_id;
refreshModIdPlaceholder();
refreshAvailablePlatforms();
document.getElementById("package-input").value = state.package_name;
document.getElementById("architectury-api-input").checked = state.dependencies.architectury_api;
document.getElementById("architectury-api-input").checked = state.dependencies.architectury_api;
13 changes: 12 additions & 1 deletion src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub async fn generate(state: JsValue) {
async fn generate_inner(state: JsValue) -> Result<(), JsValue> {
let app: crate::app::GeneratorApp = serde_wasm_bindgen::from_value(state)?;
crate::app::generator::generate(&app)
.await
.await
.map_err(|err| JsValue::from(format!("{}", err)))
}

Expand All @@ -96,3 +96,14 @@ pub fn supports_forge(game_version: JsValue) -> Result<bool, JsValue> {
let game_version: version_resolver::minecraft::MinecraftVersion = serde_wasm_bindgen::from_value(game_version)?;
Ok(game_version.forge_major_version().is_some())
}

#[wasm_bindgen]
pub fn arch_api_supports_forge(game_version: JsValue) -> Result<bool, JsValue> {
let game_version: version_resolver::minecraft::MinecraftVersion = serde_wasm_bindgen::from_value(game_version)?;
if game_version.forge_major_version().is_some() {
Ok(game_version.forge_major_version().expect("No forge version available!").parse::<i32>().unwrap() < 50)
}
else {
Ok(false)
}
}

0 comments on commit 6c4b274

Please sign in to comment.