frogmc.dev/template.md

279 lines
9.6 KiB
Markdown
Raw Normal View History

2024-06-05 16:42:57 -04:00
---
title: Mod Template Generator
sidebar: false
prev: false
next: false
editLink: false
lastUpdated: false
outline: false
2024-06-05 16:42:57 -04:00
---
<!-- This is a mess! Someone improve this please. -->
<script setup>
2024-06-08 11:27:05 -04:00
import JSZip from 'jszip'
import { ref, onMounted } from 'vue'
import { saveAs } from 'file-saver'
const assetBaseUrl = "/resources/template"
2024-06-08 11:27:05 -04:00
const showSnapshots = ref()
2024-06-05 16:42:57 -04:00
const versionSelector = ref()
2024-06-08 11:27:05 -04:00
const modIdRef = ref()
const modNameRef = ref()
const mavenGroupRef = ref()
const licenseRef = ref()
const useSnapshots = ref()
2024-06-08 11:27:05 -04:00
let releases = []
let snapshots = []
let versions = []
let latestLoader
let latestPhytotelma
let latestLoaderSnapshot
let latestPhytotelmaSnapshot
2024-06-05 16:42:57 -04:00
async function getGameVersions() {
const response = await fetch("https://piston-meta.mojang.com/mc/game/version_manifest_v2.json")
return await response.json()
}
2024-06-08 11:27:05 -04:00
function getVersions() {
versionSelector.value.innerHTML = ""
for (let version of releases) {
versionSelector.value.innerHTML += "<option value=\""+version.id+"\">"+version.id+"</option>"
2024-06-08 11:27:05 -04:00
}
if (showSnapshots.value) {
for (let version of snapshots) {
versionSelector.value.innerHTML += "<option value=\""+version.id+"\">"+version.id+"</option>"
}
}
}
2024-06-05 16:42:57 -04:00
2024-06-08 11:27:05 -04:00
onMounted(() => {
getGameVersions().then((v) => {
versions = v.versions
for (let version of versions){
if (version.type === "snapshot"){
snapshots.push(version)
} else {
releases.push(version)
}
}
getVersions()
})
getLatestProjectVersions()
2024-06-05 16:42:57 -04:00
})
2024-06-08 11:27:05 -04:00
function getLatestProjectVersions() {
fetchVersionFromMaven("releases", "frogloader").then((v) => {
2024-06-08 11:27:05 -04:00
latestLoader = v
document.getElementById("frogLoaderVersionReleaseBadge").innerHTML = v
}).catch((err) => {
document.getElementById("frogLoaderVersionReleaseBadge").innerHTML = "No version found!"
2024-06-08 11:27:05 -04:00
})
fetchVersionFromMaven("releases", "phytotelma").then((v) => {
2024-06-08 11:27:05 -04:00
latestPhytotelma = v
document.getElementById("phytotelmaVersionReleaseBadge").innerHTML = v
}).catch((err) => {
document.getElementById("phytotelmaVersionReleaseBadge").innerHTML = "No version found!"
})
fetchVersionFromMaven("snapshots", "frogloader").then((v) => {
latestLoaderSnapshot = v
document.getElementById("frogLoaderVersionSnapshotBadge").innerHTML = v
})
fetchVersionFromMaven("snapshots", "phytotelma").then((v) => {
latestPhytotelmaSnapshot = v
document.getElementById("phytotelmaVersionSnapshotBadge").innerHTML = v
2024-06-08 11:27:05 -04:00
})
}
async function fetchVersionFromMaven(repository, name) {
const response = await fetch("https://maven.frogmc.dev/"+repository+"/dev/frogmc/"+name+"/maven-metadata.xml")
const text = await response.text()
const parser = new DOMParser()
const doc = parser.parseFromString(text, "text/xml")
return doc.getElementsByTagName("latest")[0].textContent
}
function generate() {
let missing = []
if (modIdRef.value === undefined) {
missing.push("Mod ID")
}
if (modNameRef.value === undefined) {
missing.push("Mod Name")
}
if (mavenGroupRef.value === undefined) {
missing.push("Maven Group")
}
if (licenseRef.value === undefined) {
missing.push("License")
}
if (missing.length > 0) {
let html = "<div class=\"danger custom-block\"><p class=\"custom-block-title\">Missing Inputs</p><p>"
html += missing.join("</p><p>")
html += "</p></div>"
document.getElementById("missingBox").innerHTML = html
return
}
2024-06-08 11:27:05 -04:00
let zip = JSZip()
let gradle = zip.folder("gradle")
let wrapper = gradle.folder("wrapper")
let promises = []
promises.push(
readAsset("/gradle/libs.versions.toml").then((data) => {
2024-06-08 11:27:05 -04:00
gradle.file("libs.versions.toml", data)
})
)
promises.push(
readAssetBinary("/gradle/wrapper/gradle-wrapper.properties").then((data) => {
2024-06-08 11:27:05 -04:00
wrapper.file("gradle-wrapper.properties", data)
})
)
promises.push(
readAssetBinary("/gradle/wrapper/gradle-wrapper.jar").then((data) => {
2024-06-08 11:27:05 -04:00
wrapper.file("gradle-wrapper.jar", data)
})
)
promises.push(
readAsset("/.gitignore").then((data) => {
2024-06-08 11:27:05 -04:00
zip.file(".gitignore", data)
})
)
promises.push(
readAsset("/build.gradle.kts").then((data) => {
2024-06-08 11:27:05 -04:00
zip.file("build.gradle.kts", data)
})
)
promises.push(
readAssetBinary("/gradlew.sh").then((data) => {
2024-06-08 11:27:05 -04:00
zip.file("gradlew", data)
})
)
promises.push(
readAssetBinary("/gradlew.bat").then((data) => {
2024-06-08 11:27:05 -04:00
zip.file("gradlew.bat", data)
})
)
promises.push(
readAsset("/build.gradle.kts").then((data) => {
2024-06-08 11:27:05 -04:00
zip.file("build.gradle.kts", data)
})
)
promises.push(
readAsset("/settings.gradle.kts").then((data) => {
2024-06-08 11:27:05 -04:00
zip.file("settings.gradle.kts", data)
})
)
let src = zip.folder("src")
let main = src.folder("main")
let java = main.folder("java")
let resources = main.folder("resources")
let classes = java
for (let part of mavenGroupRef.value.split(/\\./g)) {
classes = classes.folder(part)
}
const classFileName = modNameRef.value.replaceAll(" ", "")
promises.push(
readAsset("/src/main/java/Main.java").then((data) => {
classes.file(classFileName+"Main", data)
})
)
2024-06-08 11:27:05 -04:00
promises.push(
readAsset("/src/main/resources/frog.mod.toml").then((data) => {
2024-06-08 11:27:05 -04:00
resources.file("frog.mod.toml", data)
})
)
promises.push(
readAsset("/src/main/resources/example_mod.mixins.json").then((data) => {
2024-06-08 11:27:05 -04:00
resources.file(modIdRef.value+".mixins.json", data)
})
)
Promise.all(promises).then((values) => {
zip.generateAsync({type:"blob"}).then(function (blob) {
saveAs(blob, modIdRef.value+"_template.zip")
}, function (err) {
alert("Failed to download generated zip file, please report this!")
})
})
}
async function readAssetBinary(path) {
const response = await fetch(assetBaseUrl+path)
2024-06-08 11:27:05 -04:00
return await response.blob()
}
async function readAsset(path){
const response = await fetch(assetBaseUrl+path)
2024-06-08 11:27:05 -04:00
return await response.text().then((data) => {
data = data.replaceAll("$mod_id", modIdRef.value)
2024-06-09 07:09:19 -04:00
data = data.replaceAll("$mod_name_pascal", modNameRef.value.replaceAll(" ", ""))
data = data.replaceAll("$mod_name", modNameRef.value)
data = data.replaceAll("$maven_group", mavenGroupRef.value)
data = data.replaceAll("$license", licenseRef.value)
data = data.replaceAll("$loader_version", useSnapshots.value ? latestLoaderSnapshot : latestLoader)
data = data.replaceAll("$phytotelma_version", useSnapshots.value ? latestPhytotelmaSnapshot : latestPhytotelma)
data = data.replaceAll("$game_version", versionSelector.value.value)
2024-06-08 11:27:05 -04:00
return data
})
}
function inputsChanged() {
document.getElementById("missingBox").innerHTML = ""
2024-06-08 11:27:05 -04:00
}
</script>
2024-06-05 16:42:57 -04:00
# {{ $frontmatter.title }}
2024-06-08 11:27:05 -04:00
## Inputs
2024-06-05 16:42:57 -04:00
2024-06-08 11:27:05 -04:00
<div id="inputs">
<table>
<tbody>
<tr>
<td>Mod ID</td>
<td><input v-model="modIdRef" @input="inputsChanged" /></td>
2024-06-08 11:27:05 -04:00
</tr>
<tr>
<td>Mod Name</td>
<td><input v-model="modNameRef" @input="inputsChanged" /></td>
2024-06-08 11:27:05 -04:00
</tr>
<tr>
<td>Maven Group</td>
<td><input v-model="mavenGroupRef" @input="inputsChanged" /></td>
2024-06-08 11:27:05 -04:00
</tr>
<tr>
<td>License (SPDX)</td>
<td><input v-model="licenseRef" @input="inputsChanged" /></td>
2024-06-08 11:27:05 -04:00
</tr>
<tr>
<td>Minecraft Version</td>
2024-06-08 11:27:05 -04:00
<td>
<select ref="versionSelector">
2024-06-08 11:27:05 -04:00
<option value="loading">Loading Versions...</option>
</select>
<input type="checkbox" v-model="showSnapshots" @change="getVersions">Show Snapshots</input>
</td>
</tr>
<tr>
<td>Library Versions</td>
<td>
<input type="checkbox" v-model="useSnapshots">Use Snapshots (Beta Versions)</input>
2024-06-08 11:27:05 -04:00
</td>
</tr>
</tbody>
</table>
<div id="missingBox"></div>
<button @click="generate">Download</button>
2024-06-08 11:27:05 -04:00
</div>
2024-06-05 16:42:57 -04:00
2024-06-08 11:27:05 -04:00
## Latest Versions
2024-06-05 16:42:57 -04:00
[FrogLoader](/contributing/tools.md#frogloader) <Badge type="tip" id="frogLoaderVersionReleaseBadge">Loading Release...</Badge> <Badge type="warning" id="frogLoaderVersionSnapshotBadge">Loading Snapshot...</Badge>
2024-06-05 16:42:57 -04:00
[Phytotelma](/contributing/tools.md#phytotelma) <Badge type="tip" id="phytotelmaVersionReleaseBadge">Loading Release...</Badge> <Badge type="warning" id="phytotelmaVersionSnapshotBadge">Loading Snapshot...</Badge>
2024-06-05 16:42:57 -04:00