Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Architectury API where a Forge port does not exist #25

Open
wants to merge 6 commits into
base: feature/forge-1.20.6-1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 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,19 @@ 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 +182,14 @@ function refreshForgeLikePlatform(available, id) {
}
}

function refreshArchitecturySupport() {
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 +221,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;
10 changes: 10 additions & 0 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ 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().unwrap().parse::<i32>().unwrap() < 50)
} else {
Ok(false)
}
}
Loading