The District of Joban Difference between revisions of "JCM:MTR Version Check"

Difference between revisions of "JCM:MTR Version Check"

From The District of Joban
(Created page with "For a more friendly experience, Joban Client Mod grabs the MTR Mod version from the corresponding Mod Loader (Fabric or Forge), then compare it to the minimum MTR version. (Which is manually bumped by the developers whenever there's an incompatibilties) The code written in javascript is as follows:")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
For a more friendly experience, Joban Client Mod grabs the MTR Mod version from the corresponding Mod Loader (Fabric or Forge), then compare it to the minimum MTR version. (Which is manually bumped by the developers whenever there's an incompatibilties)
For a more friendly experience, Joban Client Mod grabs the MTR Mod version from the corresponding Mod Loader (Fabric or Forge), then compare it to the minimum MTR version. (Which is manually bumped by the developers whenever there's an incompatibilties)


== Issues ==
On JCM v1.1.5, the code for comparing versions is flawed. After MTR releases 3.1.0-prerelease-1, all JCM users using that version gets a pop up saying their version is incompatible every time the game launches. (When in fact, it is compatible) 


The code written in javascript is as follows:
The code is later rewritten, and is displayed below (Presented in javascript):
<nowiki>
let minVer = "3.1.0-unofficial-3"
let curVer = "3.1.0-prerelease-1"
console.log(lowerThanMin(minVer, curVer))
 
function lowerThanMin(ogMinVersion, ogCurVersion) {
    let minVersion = ogMinVersion.split("-hotfix-")[0];
    let curVersion = ogCurVersion.split("-hotfix-")[0];
 
    if (curVersion == null) {
        return false;
    }
 
    if (curVersion.includes("beta")) {
        return true;
    }
 
    if (minVersion == curVersion) {
        return false;
    }
 
    let minimumMainVersion = minVersion.split("-")[0];
    let currentMainVersion = curVersion.split("-")[0];
 
    if (minimumMainVersion != currentMainVersion) {
        let splittedA = minimumMainVersion.split(".");
        let splittedB = currentMainVersion.split(".");
 
        if (splittedA.length != splittedB.length) {
            return false;
        }
 
        for (let i = 0; i < splittedA.length; i++) {
            let min = parseInt(splittedA[i]);
            let cur = parseInt(splittedB[i]);
            if (min > cur) {
                return true;
            }
        }
        return false;
    } else {
        if (minVersion.includes("-unofficial-") && curVersion.includes("-unofficial-")) {
            let minUnofficialVer = parseInt(minVersion.split("-unofficial-")[1]);
            let curUnofficialVer = parseInt(curVersion.split("-unofficial-")[1]);
 
            if (minUnofficialVer > curUnofficialVer) {
                return true;
            }
        }
 
        if (minVersion.includes("-prerelease-") && curVersion.includes("-prerelease-")) {
            let minUnofficialVer = parseInt(minVersion.split("-prerelease-")[1]);
            let curUnofficialVer = parseInt(curVersion.split("-prerelease-")[1]);
            if (minUnofficialVer > curUnofficialVer) {
                return true;
            }
        }
 
        if (minVersion.includes("-unofficial-") && curVersion.includes("-prerelease-")) {
            return false;
        }
 
        if (minVersion.includes("-prerelease-") && curVersion.includes("-unofficial-")) {
            return true;
        }
 
        let minVerIsOfficial = !minVersion.includes("-unofficial-") && !minVersion.includes("-prerelease-");
        let curVerIsOfficial = !curVersion.includes("-unofficial-") && !curVersion.includes("-prerelease-");
 
        if (minVerIsOfficial && !curVerIsOfficial) {
            return true;
        }
 
        if (curVerIsOfficial && !minVerIsOfficial) {
            return false;
        }
        return false;
    }
}
</nowiki>

Latest revision as of 20:38, 31 August 2022

For a more friendly experience, Joban Client Mod grabs the MTR Mod version from the corresponding Mod Loader (Fabric or Forge), then compare it to the minimum MTR version. (Which is manually bumped by the developers whenever there's an incompatibilties)

Issues

On JCM v1.1.5, the code for comparing versions is flawed. After MTR releases 3.1.0-prerelease-1, all JCM users using that version gets a pop up saying their version is incompatible every time the game launches. (When in fact, it is compatible)

The code is later rewritten, and is displayed below (Presented in javascript):

let minVer = "3.1.0-unofficial-3"
let curVer = "3.1.0-prerelease-1"
console.log(lowerThanMin(minVer, curVer))

function lowerThanMin(ogMinVersion, ogCurVersion) {
    let minVersion = ogMinVersion.split("-hotfix-")[0];
    let curVersion = ogCurVersion.split("-hotfix-")[0];

    if (curVersion == null) {
        return false;
    }

    if (curVersion.includes("beta")) {
        return true;
    }

    if (minVersion == curVersion) {
        return false;
    }

    let minimumMainVersion = minVersion.split("-")[0];
    let currentMainVersion = curVersion.split("-")[0];

    if (minimumMainVersion != currentMainVersion) {
        let splittedA = minimumMainVersion.split(".");
        let splittedB = currentMainVersion.split(".");

        if (splittedA.length != splittedB.length) {
            return false;
        }

        for (let i = 0; i < splittedA.length; i++) {
            let min = parseInt(splittedA[i]);
            let cur = parseInt(splittedB[i]);
            if (min > cur) {
                return true;
            }
        }
        return false;
    } else {
        if (minVersion.includes("-unofficial-") && curVersion.includes("-unofficial-")) {
            let minUnofficialVer = parseInt(minVersion.split("-unofficial-")[1]);
            let curUnofficialVer = parseInt(curVersion.split("-unofficial-")[1]);

            if (minUnofficialVer > curUnofficialVer) {
                return true;
            }
        }

        if (minVersion.includes("-prerelease-") && curVersion.includes("-prerelease-")) {
            let minUnofficialVer = parseInt(minVersion.split("-prerelease-")[1]);
            let curUnofficialVer = parseInt(curVersion.split("-prerelease-")[1]);
            if (minUnofficialVer > curUnofficialVer) {
                return true;
            }
        }

        if (minVersion.includes("-unofficial-") && curVersion.includes("-prerelease-")) {
            return false;
        }

        if (minVersion.includes("-prerelease-") && curVersion.includes("-unofficial-")) {
            return true;
        }

        let minVerIsOfficial = !minVersion.includes("-unofficial-") && !minVersion.includes("-prerelease-");
        let curVerIsOfficial = !curVersion.includes("-unofficial-") && !curVersion.includes("-prerelease-");

        if (minVerIsOfficial && !curVerIsOfficial) {
            return true;
        }

        if (curVerIsOfficial && !minVerIsOfficial) {
            return false;
        }
        return false;
    }
}