Skip to content

Commit

Permalink
remove lang & simplify theme toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Dec 26, 2023
1 parent 47868c9 commit 16bdbdf
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 117 deletions.
1 change: 1 addition & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "CodeQL"

on:
pull_request:
workflow_dispatch:

jobs:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Minecraft Datapack Analyzer
Allows you to analyze and generate stats for [Minecraft](https://minecraft.net) Java Edition data- and resourcepacks.

![](https://raw.githubusercontent.com/DEVTomatoCake/Datapack-Analyzer/main/assets/images/showcase.png)
![](https://raw.githubusercontent.com/DEVTomatoCake/Pack-Analyzer/main/assets/images/showcase.png)

## Credits

Expand All @@ -14,7 +14,7 @@ Developed mostly by [TomatoCake](https://github.com/DEVTomatoCake).
## Note on v1
v1 used Tauri to make this app installable on Windows - this is annoying and scary, especially for one-time use.

As such, v2+ instead uses [a website](https://datapack-analyzer.pages.dev/), with almost the same code. You're now able to install it as a [Progressive Web App](https://en.wikipedia.org/wiki/Progressive_web_app).
As such, v2+ instead uses [a website](https://pack-analyzer.pages.dev/), with almost the same code. You're now able to install it as a [Progressive Web App](https://en.wikipedia.org/wiki/Progressive_web_app).

## Like this project?
Feel free to leave a star, create a feature request or bug report issue, or even contribute to the code!
Expand Down
21 changes: 8 additions & 13 deletions assets/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ async function processEntries(entries) {
else commands[cmd] = 1

if (cmd == "execute") {
line.match(/ run [a-z_:]{2,}/g)?.forEach(match => {
line.match(/run ([a-z_:]{2,})/g)?.forEach(match => {
if (match[1] == "return") return

const cmdBehind = match.replace(" run ", "")
if (cmdsBehindExecute[cmdBehind]) cmdsBehindExecute[cmdBehind]++
else cmdsBehindExecute[cmdBehind] = 1
if (commands[cmdBehind]) commands[cmdBehind]++
else commands[cmdBehind] = 1
})
}
if (cmd == "function" || line.includes(" function ")) {
if (cmd == "function" || line.includes(" function ") || line.includes("/function ")) {
const func = /function (([-a-z0-9_]+):)?([-a-z0-9_/]+)/i.exec(line)
if (func && func[3]) dpExclusive.functionCalls.push({
source: funcLocation[1] + ":" + funcLocation[2],
Expand Down Expand Up @@ -209,23 +211,16 @@ async function processEntries(entries) {
}
}
if (!rpMode && ext == "json") {
// TODO: Refactor to avoid duplicate code
if (filePath.includes("/advancements/")) dpExclusive.folders.advancements++
else if (filePath.includes("/loot_tables/")) dpExclusive.folders.loot_tables++
else if (filePath.includes("/recipes/")) dpExclusive.folders.recipes++
else if (filePath.includes("/predicates/")) dpExclusive.folders.predicates++
else if (filePath.includes("/dimension/")) dpExclusive.folders.dimension++
else if (filePath.includes("/dimension_type/")) dpExclusive.folders.dimension_type++
else if (filePath.includes("/worldgen/")) dpExclusive.folders.worldgen++

Object.keys(dpExclusive.folders).forEach(type => {
if (filePath.includes("/" + type + "/")) dpExclusive.folders[type]++
})
Object.keys(dpExclusive.tags).forEach(type => {
if (filePath.includes("/tags/" + type + "/")) dpExclusive.tags[type]++
})
} else if (rpMode) {
} else if (rpMode)
Object.keys(rpExclusive).forEach(type => {
if (filePath.includes("/" + type + "/")) rpExclusive[type]++
})
}
}
}

Expand Down
Binary file added assets/images/favicon.ico
Binary file not shown.
37 changes: 9 additions & 28 deletions assets/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Cookie/"load"/getLanguage() code modified from https://github.com/DEVTomatoCake/dashboard/blob/0ad2ba278373244f05025dc6554e4ebb86868e8a/assets/js/script.js#L1-L26 and language.js
// Cookie/"load" code modified from https://github.com/DEVTomatoCake/dashboard/blob/0ad2ba278373244f05025dc6554e4ebb86868e8a/assets/js/script.js#L1-L26

function setCookie(name, value, days) {
let cookie = name + "=" + (value || "") + ";path=/;"
Expand All @@ -20,13 +20,6 @@ function getCookie(name) {
return void 0
}

const getLanguage = () => {
if (getCookie("lang")) return getCookie("lang")

const userLang = navigator.language || navigator.userLanguage
return userLang ? (userLang.split("-")[0] == "de" ? "de" : "en") : "en"
}

const requestVersions = async () => {
const res = await fetch("https://raw.githubusercontent.com/misode/mcmeta/summary/versions/data.json")
const json = await res.json()
Expand All @@ -41,12 +34,11 @@ const requestVersions = async () => {
requestVersions()

window.addEventListener("load", () => {
if (getCookie("theme") == "light") document.body.classList = "light-theme"
if (getCookie("theme") == "light") document.body.classList.add("light-theme")
else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
document.body.classList = "light-theme"
document.body.classList.add("light-theme")
setCookie("theme", "light", 365)
}
if (!getCookie("lang")) setCookie("lang", getLanguage(), 365)

const params = new URLSearchParams(location.search)
if (params.has("data")) {
Expand Down Expand Up @@ -114,7 +106,7 @@ window.addEventListener("paste", async e => {
}
})

const localize = string => string.toLocaleString(getCookie("lang") || "en-US")
const localize = string => string.toLocaleString()

function openDialog(dialog) {
dialog.style.display = "block"
Expand All @@ -126,22 +118,11 @@ function openDialog(dialog) {
}
}

async function openSettingsDialog() {
const dialog = document.getElementById("settingsDialog")
openDialog(dialog)

if (getCookie("theme") == "light") dialog.querySelector("option[value='light']").selected = true
else dialog.querySelector("option[value='dark']").selected = true

if (getCookie("lang") == "de-DE") dialog.querySelector("option[value='de-DE']").selected = true
else dialog.querySelector("option[value='en-US']").selected = true

for (let select of dialog.getElementsByTagName("select")) {
select.onchange = () => {
setCookie(select.name, select.value, 365)
if (select.name == "theme") document.body.classList = select.value + "-theme"
}
}
const toggleTheme = () => {
const newTheme = getCookie("theme") == "light" ? "dark" : "light"
setCookie("theme", newTheme, 365)
if (newTheme == "light") document.body.classList.add("light-theme")
else document.body.classList.remove("light-theme")
}

function clearResults() {
Expand Down
10 changes: 8 additions & 2 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
--heading-color: #008900;
--number-color: #00a100;
}
.dark-theme {
:root {
--background: #222;
--header-bg: #216E4A;
--dialog-bg: #222;
Expand All @@ -37,7 +37,9 @@ button {
padding: 5px 8px;
font-size: 16px;
border: none;
border-radius: 5px;
border-radius: 7px;
cursor: pointer;
box-shadow: inset 0px -1px 2px rgba(17,24,39,.15), 0 0 0 0 transparent;
}
p {
font-size: 19px;
Expand Down Expand Up @@ -67,6 +69,10 @@ code {
margin-left: 75px;
}

main {
margin: 0 25px;
}

header {
background-color: var(--header-bg);
padding: 20px;
Expand Down
103 changes: 41 additions & 62 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
<meta name="theme-color" content="#216E4A">

<link rel="manifest" href="./manifest.json">
<link href="./assets/images/icon_192.png" rel="shortcut icon" type="image/x-icon">
<link href="./assets/images/icon_192.png" rel="apple-touch-icon" sizes="192x192">
<link href="./assets/images/favicon.ico" rel="shortcut icon" type="image/x-icon">
<link href="./assets/images/favicon.ico" rel="apple-touch-icon" sizes="192x192">

<link rel="stylesheet" href="./assets/style.css">
<script src="./assets/analyzer.js"></script>
<script src="./assets/script.js"></script>
<script src="./assets/jszip.min.js"></script>
</head>
<body class="dark-theme">
<body>
<header>
<h1>Minecraft Datapack and Resourcepack analyzer</h1>
<h2>Drop/paste a .zip file or select a folder below to start analyzing!</h2>
<div>
<button type="button" onclick="selectFolder()">Select folder</button>
<button type="button" onclick="selectZip()">Select .zip</button>
<button type="button" onclick="openSettingsDialog()">Settings</button>
<button type="button" onclick="toggleTheme()">Toggle theme</button>
<button type="button" onclick="openDialog(document.getElementById('aboutDialog'))">About</button>
</div>
<div id="resultButtons" hidden>
Expand All @@ -44,70 +44,49 @@ <h2>Drop/paste a .zip file or select a folder below to start analyzing!</h2>
<br>
</header>

<h1 id="progress"></h1>
<canvas id="shareImage" width="955" height="500" style="display: none;"></canvas>
<p id="result"></p>
<main>
<h1 id="progress"></h1>
<canvas id="shareImage" width="955" height="500" style="display: none;"></canvas>
<p id="result"></p>

<div id="settingsDialog" class="dialog">
<div class="dialog-content">
<span class="close">&times;</span>
<h1>Settings</h1>
<div id="aboutDialog" class="dialog">
<div class="dialog-content">
<span class="close">&times;</span>
<h1>About</h1>

<label for="setTheme">Theme</label>
<br>
<select id="setTheme" name="theme">
<option value="dark" selected>Dark</option>
<option value="light">Light</option>
</select>
<p>
Made in HTML, plain JavaScript and CSS, this site allows you to get usage stats from your Minecraft data and resource packs.
It also allows analyzing of whole worlds and shaders.
</p>

<br>
<br>
<label for="setLang">Language (changes how numbers are displayed)</label>
<br>
<select id="setLang" name="lang">
<option value="en-US" selected>English</option>
<option value="de-DE">German</option>
</select>
<p>
Developed by: <a href="https://discord.com/users/581146486646243339" target="_blank" rel="noopener">TomatoCake</a>
</p>
<p>
Inspired by: <a href="https://github.com/ErrorCraft/FunctionAnalyser" target="_blank" rel="noopener">ErrorCraft's FunctionAnalyser</a>
</p>
<p>
GitHub: <a href="https://github.com/DEVTomatoCake/Pack-Analyzer" target="_blank" rel="noopener">https://github.com/DEVTomatoCake/Pack-Analyzer</a>
</p>
<p>
Support/Feedback:
<a href="https://discord.gg/JXVDQFf" target="_blank" rel="noopener">Vanilla Minigames Discord</a> or
<a href="https://github.com/DEVTomatoCake/Pack-Analyzer/issues" target="_blank" rel="noopener">GitHub</a>
</p>
</div>
</div>
</div>

<div id="aboutDialog" class="dialog">
<div class="dialog-content">
<span class="close">&times;</span>
<h1>About</h1>
<div id="shareDialog" class="dialog">
<div class="dialog-content">
<span class="close">&times;</span>
<h1>Share as link</h1>

<p>
Made in raw HTML, JavaScript and CSS (yes, it's pain. Don't ask.), this site allows you to get stats from your Minecraft datapacks and resourcepacks.
It also allows analyzing of whole worlds and OptiFine shaders.
</p>

<p>
Developed by: <a href="https://discord.com/users/581146486646243339" target="_blank" rel="noopener">TomatoCake</a>
</p>
<p>
Inspired by: <a href="https://github.com/ErrorCraft/FunctionAnalyser" target="_blank" rel="noopener">ErrorCraft's FunctionAnalyser</a>
</p>
<p>
GitHub: <a href="https://github.com/DEVTomatoCake/Datapack-Analyzer" target="_blank" rel="noopener">https://github.com/DEVTomatoCake/Datapack-Analyzer</a>
</p>
<p>
Support/Feedback:
<a href="https://discord.gg/JXVDQFf" target="_blank" rel="noopener">Vanilla Minigames Discord</a> or
<a href="https://github.com/DEVTomatoCake/Datapack-Analyzer/issues" target="_blank" rel="noopener">GitHub</a>
</p>
</div>
</div>

<div id="shareDialog" class="dialog">
<div class="dialog-content">
<span class="close">&times;</span>
<h1>Share as link</h1>

<a id="share-link" href="https://shorter.cf"></a>
<br>
<br>
<img id="share-img" width="150" height="150" alt="QR-Code">
<a id="share-link" href="https://shorter.cf"></a>
<br>
<br>
<img id="share-img" width="150" height="150" alt="QR-Code">
</div>
</div>
</div>
</main>
</body>
</html>
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "datapack-analyzer",
"name": "pack-analyzer",
"version": "2.0.0",
"private": true,
"description": "Allows you to analyze and generate stats for [Minecraft](https://minecraft.net) Java Edition data- and resourcepacks.",
"description": "Allows you to analyze and generate stats for [Minecraft](https://minecraft.net) Java Edition data and resource packs.",
"main": "index.html",
"author": "TomatoCake",
"license": "CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0",
Expand Down

0 comments on commit 16bdbdf

Please sign in to comment.