Skip to content

Commit 9876f24

Browse files
committed
Added develop page
1 parent c425ed2 commit 9876f24

2 files changed

Lines changed: 257 additions & 0 deletions

File tree

develop.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Develop | OrnitheMC</title>
6+
<meta charset="UTF-8">
7+
<link rel="stylesheet" href="style.css">
8+
<script src="develop.js" defer></script>
9+
</head>
10+
11+
<body>
12+
<h1>Develop</h1>
13+
14+
<h2>Getting started</h2>
15+
<p>
16+
If you are updating the Loom or Ploceus version in <code>build.gradle</code> file, make sure their version match
17+
(example, Ploceus of version <code>1.5-SNAPSHOT</code> needs Loom to be of version <code>1.5-SNAPSHOT</code> as
18+
well)</p>
19+
<p>TODO</p>
20+
21+
<h2>Latest versions</h2>
22+
23+
<input type="checkbox" id="allow-snapshots" />
24+
<label for="allow-snapshots">Include Snapshots</label>
25+
26+
<fieldset>
27+
<legend>Select a ModLoader</legend>
28+
<input type="radio" id="mod-loader-fabric" name="modLoader" checked />
29+
<label for="mod-loader-fabric">Fabric</label>
30+
31+
<input type="radio" id="mod-loader-quilt" name="modLoader" />
32+
<label for="mod-loader-quilt">Quilt</label>
33+
</fieldset>
34+
35+
<br />
36+
37+
<input type="text" id="mc-version" list="version-list" value="1.7.2" />
38+
<label for="mc-version-autocomplete">Game version</label>
39+
<datalist id="version-list">
40+
<option value="1.7.2" />
41+
<!-- DO NOT INSERT ANYTHING HERE -->
42+
<!-- Data here will be inserted by JavaScript -->
43+
</datalist>
44+
<br />
45+
46+
Paste these in gradle.properties in your project
47+
48+
<br />
49+
50+
<code id="ornithe-dependencies">
51+
# Dependencies
52+
</code>
53+
<p id="dependencies-extra-message"></p>
54+
55+
</body>
56+
57+
</html>

develop.js

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
(async () => {
2+
3+
const URL = "ornithemc.net";
4+
const META = "meta." + URL;
5+
const VERSION = "v3";
6+
7+
8+
function makeMetaUrl(...pathComponents) {
9+
let url = META + "/" + VERSION;
10+
for (const pathComponent of pathComponents) {
11+
url += "/";
12+
url += pathComponent;
13+
}
14+
return "https://" + url;
15+
}
16+
17+
async function getFromMeta(...pathComponents) {
18+
const response = await fetch(makeMetaUrl(...pathComponents));
19+
return response.json();
20+
}
21+
22+
async function getMinecraftVersionsMeta() {
23+
return await getFromMeta("versions", "game");
24+
}
25+
26+
async function getFeatherVersionMeta(mcVersion) {
27+
return await getFromMeta("versions", "feather", mcVersion);
28+
}
29+
30+
async function getNestsVersionMeta(mcVersion) {
31+
return await getFromMeta("versions", "nests", mcVersion);
32+
}
33+
34+
async function getLoaderVersionsMeta(loader) {
35+
return await getFromMeta("versions", loader + "-loader");
36+
}
37+
38+
async function getOslVersionsMeta() {
39+
return await getFromMeta("versions", "osl");
40+
}
41+
42+
function compareVersion(sv1, sv2) {
43+
function rec(v1, v2) {
44+
if (v1.length === 0 && v2.length === 0) return 0;
45+
if (v1.length === 0) return 1;
46+
if (v2.length === 0) return -1;
47+
const [head1, ...tail1] = v1;
48+
const [head2, ...tail2] = v2;
49+
const ih1 = parseInt(head1);
50+
const ih2 = parseInt(head2);
51+
if (ih1 < ih2) return 1;
52+
if (ih1 > ih2) return -1;
53+
return rec(tail1, tail2);
54+
}
55+
56+
return rec(sv1.split("."), sv2.split("."));
57+
}
58+
59+
async function getMinecraftVersions() {
60+
return await getMinecraftVersionsMeta()
61+
.then(l => l.map(v => v.version));
62+
}
63+
64+
async function getMinecraftStableVersions() {
65+
return await getMinecraftVersionsMeta()
66+
.then(l => l.filter(v => v.stable))
67+
.then(l => l.map(v => v.version));
68+
}
69+
70+
async function getLatestFeatherBuild(mcVersion) {
71+
return await getFeatherVersionMeta(mcVersion)
72+
.then(l => l.sort((e1, e2) => e2.build - e1.build))
73+
.then(s => { console.log(s); return s; })
74+
.then(([head, ..._]) => head)
75+
.then(e => e !== undefined ? e.build : null);
76+
}
77+
78+
async function getLatestNestsBuild(mcVersion) {
79+
return await getNestsVersionMeta(mcVersion)
80+
.then(l => l.sort((e1, e2) => e2.build - e1.build))
81+
.then(([head, ..._]) => head)
82+
.then(e => e !== undefined ? e.build : null);
83+
}
84+
85+
async function getLatestLoader(loader) {
86+
return await getLoaderVersionsMeta(loader)
87+
.then(l => l.filter(e => e.stable))
88+
.then(([head, ..._]) => head)
89+
.then(e => e.version);
90+
}
91+
92+
async function getLatestOsl() {
93+
return await getOslVersionsMeta()
94+
.then(l => l.sort((e1, e2) => compareVersion(e1.version, e2.version)))
95+
.then(([head, ..._]) => head)
96+
.then(e => e.version);
97+
}
98+
99+
const minecraftStableVersions = await getMinecraftStableVersions();
100+
const minecraftAllVersions = await getMinecraftVersions();
101+
102+
let possibleVersions;
103+
104+
const loaderSelectorRadios = { fabric: document.getElementById("mod-loader-fabric"), quilt: document.getElementById("mod-loader-quilt") }
105+
const versionSelectorInput = document.getElementById("mc-version");
106+
const versionListElement = document.getElementById("version-list");
107+
const allowSnapshotsCheck = document.getElementById("allow-snapshots");
108+
109+
async function getNestsFeatherBuilds(minecraftVersion) {
110+
const featherBuild = await getLatestFeatherBuild(minecraftVersion);
111+
if (featherBuild !== null) {
112+
const nestsBuild = await getLatestNestsBuild(minecraftVersion);
113+
addExtraMsg("Make sure to use the \"merged\" mod template for this Minecraft version!");
114+
if (nestsBuild === null)
115+
addExtraMsg("Nests are unavailable for this Minecraft version - make sure to edit your build.gradle appropriately!");
116+
return [
117+
`feather_build = ${featherBuild}`,
118+
nestsBuild ? `nests_build = ${nestsBuild}` : "# nests aren't used for this version"
119+
].join("\n");
120+
} else {
121+
addExtraMsg("Make sure to use the \"split\" mod template for this Minecraft version!");
122+
const featherBuildClient = await getLatestFeatherBuild(minecraftVersion + "-client");
123+
const featherBuildServer = await getLatestFeatherBuild(minecraftVersion + "-server");
124+
const nestsBuildClient = await getLatestNestsBuild(minecraftVersion + "-client");
125+
const nestsBuildServer = await getLatestNestsBuild(minecraftVersion + "-server");
126+
return [
127+
"",
128+
"### <project root>/client/gradle.properties",
129+
"environement = client",
130+
`feather_build = ${featherBuildClient}`,
131+
`nests_build = ${nestsBuildClient}`,
132+
"",
133+
"### <project root>/server/gradle.properties",
134+
"environment = server",
135+
`feather_build = ${featherBuildServer}`,
136+
`nests_build = ${nestsBuildServer}`
137+
].join("\n");
138+
}
139+
}
140+
141+
function setExtraMsg(message) {
142+
document.getElementById("dependencies-extra-message").innerText = message;
143+
}
144+
function getExtraMsg() {
145+
return document.getElementById("dependencies-extra-message").innerText;
146+
}
147+
148+
function addExtraMsg(message) {
149+
setExtraMsg(getExtraMsg() + (getExtraMsg() !== "" ? "\n" : "") + message)
150+
}
151+
152+
async function updateOrnitheDependencies() {
153+
setExtraMsg("");
154+
if (possibleVersions.some(version => versionSelectorInput.value === version)) {
155+
const loader = Object.entries(loaderSelectorRadios).find(([_, button]) => button.checked)[0];
156+
157+
const minecraftVersion = versionSelectorInput.value;
158+
const loaderVersion = await getLatestLoader(loader);
159+
const oslVersion = await getLatestOsl();
160+
const nestsFeatherBuildsStr = await getNestsFeatherBuilds(minecraftVersion);
161+
document.getElementById("ornithe-dependencies").innerText =
162+
[
163+
"### <project root>/gradle.properties",
164+
"# Dependencies",
165+
`minecraft_version = ${minecraftVersion}`,
166+
`loader_version = ${loaderVersion}`,
167+
`osl_version = ${oslVersion}`,
168+
nestsFeatherBuildsStr
169+
].join("\n");
170+
}
171+
}
172+
173+
Object.entries(loaderSelectorRadios).forEach(([_, button]) => button.addEventListener("change", async _ => await updateOrnitheDependencies()));
174+
175+
versionSelectorInput.addEventListener("input", async _ => await updateOrnitheDependencies())
176+
177+
allowSnapshotsCheck.addEventListener("change", _ => {
178+
if (allowSnapshotsCheck.checked) {
179+
possibleVersions = minecraftAllVersions;
180+
} else {
181+
possibleVersions = minecraftStableVersions;
182+
}
183+
updateVersionList();
184+
})
185+
186+
function updateVersionList() {
187+
const list = possibleVersions;
188+
while (versionListElement.firstChild) versionListElement.removeChild(versionListElement.lastChild);
189+
list.forEach(e => {
190+
const opt = new Option();
191+
opt.value = e;
192+
versionListElement.appendChild(opt);
193+
});
194+
}
195+
196+
possibleVersions = minecraftStableVersions;
197+
updateVersionList()
198+
updateOrnitheDependencies()
199+
200+
})()

0 commit comments

Comments
 (0)