From 703b597ad8200da73b344e13fac30f3fd2b3b9b1 Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Sat, 20 Apr 2024 07:08:53 +0200 Subject: [PATCH] Share frontend & backend code --- assets/script.js | 323 +++++++++++++++++----------------- eslint.config.js | 5 +- vscExtension/build.js | 8 +- vscExtension/src/extension.js | 210 ++++------------------ 4 files changed, 205 insertions(+), 341 deletions(-) diff --git a/assets/script.js b/assets/script.js index 2c941de..8d8dea5 100644 --- a/assets/script.js +++ b/assets/script.js @@ -376,192 +376,198 @@ function createImage() { } } -async function processEntries(entries) { - for await (const entry of entries) { - const filePath = entry.webkitRelativePath || entry.name - if (filePath.includes("/.git/") || filePath.includes("/.svn/")) continue - if (entry.kind == "directory") { - processEntries(entry) - continue - } - if (entry.name.endsWith("/") && entry.content == "") continue +const processFile = async (filePath = "", name = "", loadContentCallback = () => {}) => { + const ext = name.split(".").pop() + if ( + ext == "mcmeta" || ext == "json" || + (!rpMode && (ext == "mcfunction" || ext == "nbt")) || + (rpMode && (ext == "png" || ext == "icns" || ext == "txt" || ext == "ogg" || ext == "fsh" || ext == "vsh" || ext == "glsl" || ext == "lang" || ext == "properties" || ext == "inc" || ext == "xcf")) + ) { + if (filetypes[ext]) filetypes[ext]++ + else filetypes[ext] = 1 + } else { + if (filetypesOther[(name.includes(".") ? "." : "") + ext]) filetypesOther[(name.includes(".") ? "." : "") + ext]++ + else filetypesOther[(name.includes(".") ? "." : "") + ext] = 1 + } - const ext = entry.name.split(".").pop() - if ( - ext == "mcmeta" || ext == "json" || - (!rpMode && (ext == "mcfunction" || ext == "nbt")) || - (rpMode && (ext == "png" || ext == "icns" || ext == "txt" || ext == "ogg" || ext == "fsh" || ext == "vsh" || ext == "glsl" || ext == "lang" || ext == "properties" || ext == "inc" || ext == "xcf")) - ) { - if (filetypes[ext]) filetypes[ext]++ - else filetypes[ext] = 1 - } else { - if (filetypesOther[(entry.name.includes(".") ? "." : "") + ext]) filetypesOther[(entry.name.includes(".") ? "." : "") + ext]++ - else filetypesOther[(entry.name.includes(".") ? "." : "") + ext] = 1 - } + if ( + ext == "mcfunction" || ext == "mcmeta" || (!rpMode && ext == "json" && (filePath.includes("/advancements/") || filePath.includes("/tags/functions/"))) || + ext == "fsh" || ext == "vsh" || ext == "glsl" || name.endsWith("pack.png") + ) { + files++ + + const processContent = result => { + done++ + if (result.trim() == "") return emptyFiles.push(filePath) + + if (!rpMode && ext == "mcfunction") { + const fileLocation = /data\/([-a-z0-9_.]+)\/functions\/([-a-z0-9_./]+)\.mcfunction/i.exec(filePath) + if (fileLocation && !dpExclusive.functions.includes(fileLocation[1] + ":" + fileLocation[2])) dpExclusive.functions.push(fileLocation[1] + ":" + fileLocation[2]) + + for (let line of result.split("\n")) { + line = line.trim() + if (line.startsWith("#")) comments++ + if (line == "") empty++ + if (line.startsWith("#") || line == "") continue + const splitted = line.split(" ") + + let cmd = splitted[0] + if (cmd.startsWith("$")) { + cmd = cmd.slice(1) + if (cmdsBehindMacros[cmd]) cmdsBehindMacros[cmd]++ + else cmdsBehindMacros[cmd] = 1 + } - if ( - ext == "mcfunction" || ext == "mcmeta" || (!rpMode && ext == "json" && (filePath.includes("/advancements/") || filePath.includes("/tags/functions/"))) || - ext == "fsh" || ext == "vsh" || ext == "glsl" || entry.name.endsWith("pack.png") - ) { - files++ - - const processFile = result => { - done++ - if (result.trim() == "") return emptyFiles.push(filePath) - - if (!rpMode && ext == "mcfunction") { - const fileLocation = /data\/([-a-z0-9_.]+)\/functions\/([-a-z0-9_./]+)\.mcfunction/i.exec(filePath) - if (fileLocation && !dpExclusive.functions.includes(fileLocation[1] + ":" + fileLocation[2])) dpExclusive.functions.push(fileLocation[1] + ":" + fileLocation[2]) - - for (let line of result.split("\n")) { - line = line.trim() - if (line.startsWith("#")) comments++ - if (line == "") empty++ - if (line.startsWith("#") || line == "") continue - const splitted = line.split(" ") - - let cmd = splitted[0] - if (cmd.startsWith("$")) { - cmd = cmd.slice(1) - if (cmdsBehindMacros[cmd]) cmdsBehindMacros[cmd]++ - else cmdsBehindMacros[cmd] = 1 - } + if (commands[cmd]) commands[cmd]++ + else commands[cmd] = 1 - if (commands[cmd]) commands[cmd]++ - else commands[cmd] = 1 + if (cmd == "execute") { + const matches = / run ([a-z_:]{2,})/g.exec(line) + if (matches) matches.forEach(match => { + const cmdBehind = match.replace("run ", "").trim() + + if (cmdsBehindExecute[cmdBehind]) cmdsBehindExecute[cmdBehind]++ + else cmdsBehindExecute[cmdBehind] = 1 + if (commands[cmdBehind]) commands[cmdBehind]++ + else commands[cmdBehind] = 1 - if (cmd == "execute") { - const matches = / run ([a-z_:]{2,})/g.exec(line) - if (matches) matches.forEach(match => { - const cmdBehind = match.replace("run ", "").trim() - - if (cmdsBehindExecute[cmdBehind]) cmdsBehindExecute[cmdBehind]++ - else cmdsBehindExecute[cmdBehind] = 1 - if (commands[cmdBehind]) commands[cmdBehind]++ - else commands[cmdBehind] = 1 - - if (cmdBehind == "return") { - const returnCmd = / run return run ([a-z_:]{2,})/g.exec(line) - if (returnCmd && returnCmd[1]) { - if (cmdsBehindReturn[returnCmd[1]]) cmdsBehindReturn[returnCmd[1]]++ - else cmdsBehindReturn[returnCmd[1]] = 1 - } + if (cmdBehind == "return") { + const returnCmd = / run return run ([a-z_:]{2,})/g.exec(line) + if (returnCmd && returnCmd[1]) { + if (cmdsBehindReturn[returnCmd[1]]) cmdsBehindReturn[returnCmd[1]]++ + else cmdsBehindReturn[returnCmd[1]] = 1 } - }) - } else if (cmd == "return") { - const returnCmd = / run return run ([a-z_:]{2,})/g.exec(line) - if (returnCmd && returnCmd[1]) { - if (cmdsBehindReturn[returnCmd[1]]) cmdsBehindReturn[returnCmd[1]]++ - else cmdsBehindReturn[returnCmd[1]] = 1 } + }) + } else if (cmd == "return") { + const returnCmd = / run return run ([a-z_:]{2,})/g.exec(line) + if (returnCmd && returnCmd[1]) { + if (cmdsBehindReturn[returnCmd[1]]) cmdsBehindReturn[returnCmd[1]]++ + else cmdsBehindReturn[returnCmd[1]] = 1 } - if (fileLocation && (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: fileLocation[1] + ":" + fileLocation[2], - target: (func[2] || "minecraft") + ":" + func[3] - }) - } - - if (/scoreboard objectives add \w+ \w+( .+)?$/.test(line)) dpExclusive.scoreboards++ - - splitted.forEach(arg => { - if (arg.startsWith("@")) { - arg = arg.slice(1) - if (arg.startsWith("a")) dpExclusive.selectors.a++ - else if (arg.startsWith("e")) dpExclusive.selectors.e++ - else if (arg.startsWith("p")) dpExclusive.selectors.p++ - else if (arg.startsWith("r")) dpExclusive.selectors.r++ - else if (arg.startsWith("s")) dpExclusive.selectors.s++ - } + } + if (fileLocation && (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: fileLocation[1] + ":" + fileLocation[2], + target: (func[2] || "minecraft") + ":" + func[3] }) } - } else if (ext == "mcmeta") { - if (entry.name == "pack.mcmeta") { - try { - packFiles.push(JSON.parse(result)) - } catch (e) { - console.warn("Could not parse pack.mcmeta: " + filePath, e) - error++ + + if (/scoreboard objectives add \w+ \w+( .+)?$/.test(line)) dpExclusive.scoreboards++ + + splitted.forEach(arg => { + if (arg.startsWith("@")) { + arg = arg.slice(1) + if (arg.startsWith("a")) dpExclusive.selectors.a++ + else if (arg.startsWith("e")) dpExclusive.selectors.e++ + else if (arg.startsWith("p")) dpExclusive.selectors.p++ + else if (arg.startsWith("r")) dpExclusive.selectors.r++ + else if (arg.startsWith("s")) dpExclusive.selectors.s++ } + }) + } + } else if (ext == "mcmeta") { + if (name == "pack.mcmeta") { + try { + packFiles.push(JSON.parse(result)) + } catch (e) { + console.warn("Could not parse pack.mcmeta: " + filePath, e) + error++ } - } else if (entry.name.endsWith("pack.png") && !result.includes(">")) packImages.push(result) - else if (rpMode && (ext == "fsh" || ext == "vsh" || ext == "glsl")) { - for (let line of result.split("\n")) { - line = line.trim() - if (line.startsWith("//") || line.startsWith("/*")) comments++ - if (line == "") empty++ - if (line.startsWith("//") || line.startsWith("/*") || line == "") continue - - const cmd = line.match(/^[a-z_#0-9]+/i)?.[0] - if (cmd && cmd != "{" && cmd != "}") { - if (commands[cmd]) commands[cmd]++ - else commands[cmd] = 1 - } + } + } else if (name.endsWith("pack.png") && !result.includes(">")) packImages.push(result) + else if (rpMode && (ext == "fsh" || ext == "vsh" || ext == "glsl")) { + for (let line of result.split("\n")) { + line = line.trim() + if (line.startsWith("//") || line.startsWith("/*")) comments++ + if (line == "") empty++ + if (line.startsWith("//") || line.startsWith("/*") || line == "") continue + + const cmd = line.match(/^[a-z_#0-9]+/i)?.[0] + if (cmd && cmd != "{" && cmd != "}") { + if (commands[cmd]) commands[cmd]++ + else commands[cmd] = 1 } - } else if (!rpMode && ext == "json") { - if (filePath.includes("/advancements/")) { - const fileLocation = /data\/([-a-z0-9_.]+)\/advancements\/([-a-z0-9_./]+)\.json/i.exec(filePath) - - try { - const parsed = JSON.parse(result) - if (parsed.rewards && parsed.rewards.function) dpExclusive.functionCalls.push({ - source: "(Advancement) " + fileLocation[1] + ":" + fileLocation[2], - target: parsed.rewards.function.includes(":") ? parsed.rewards.function : "minecraft:" + parsed.rewards.function - }) - } catch (e) { - console.warn("Unable to analyze advancement: " + filePath, e) - } - } else if (filePath.includes("/tags/functions/")) { - const fileLocation = /data\/([-a-z0-9_.]+)\/tags\/functions\/([-a-z0-9_./]+)\.json/i.exec(filePath) - if (fileLocation && !dpExclusive.functions.includes("#" + fileLocation[1] + ":" + fileLocation[2])) dpExclusive.functions.push("#" + fileLocation[1] + ":" + fileLocation[2]) - - try { - const parsed = JSON.parse(result) - if (parsed.values) parsed.values.forEach(func => { - if (typeof func == "object") { - if (func.required === false) return - func = func.id - } + } + } else if (!rpMode && ext == "json") { + if (filePath.includes("/advancements/")) { + const fileLocation = /data\/([-a-z0-9_.]+)\/advancements\/([-a-z0-9_./]+)\.json/i.exec(filePath) + + try { + const parsed = JSON.parse(result) + if (parsed.rewards && parsed.rewards.function) dpExclusive.functionCalls.push({ + source: "(Advancement) " + fileLocation[1] + ":" + fileLocation[2], + target: parsed.rewards.function.includes(":") ? parsed.rewards.function : "minecraft:" + parsed.rewards.function + }) + } catch (e) { + console.warn("Unable to analyze advancement: " + filePath, e) + } + } else if (filePath.includes("/tags/functions/")) { + const fileLocation = /data\/([-a-z0-9_.]+)\/tags\/functions\/([-a-z0-9_./]+)\.json/i.exec(filePath) + if (fileLocation && !dpExclusive.functions.includes("#" + fileLocation[1] + ":" + fileLocation[2])) dpExclusive.functions.push("#" + fileLocation[1] + ":" + fileLocation[2]) + + try { + const parsed = JSON.parse(result) + if (parsed.values) parsed.values.forEach(func => { + if (typeof func == "object") { + if (func.required === false) return + func = func.id + } - dpExclusive.functionCalls.push({ - source: "#" + fileLocation[1] + ":" + fileLocation[2], - target: func.includes(":") ? func : "minecraft:" + func - }) + dpExclusive.functionCalls.push({ + source: "#" + fileLocation[1] + ":" + fileLocation[2], + target: func.includes(":") ? func : "minecraft:" + func }) - } catch (e) { - console.warn("Unable to analyze function tag: " + filePath, e) - } + }) + } catch (e) { + console.warn("Unable to analyze function tag: " + filePath, e) } } } + } + + await loadContentCallback(processContent, ext) + } + if (!rpMode && ext == "json") { + 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) + Object.keys(rpExclusive).forEach(type => { + if (filePath.includes("/" + type + "/")) rpExclusive[type]++ + }) +} + +async function processEntries(entries) { + for await (const entry of entries) { + const filePath = entry.webkitRelativePath || entry.name + if (filePath.includes("/.git/") || filePath.includes("/.svn/")) continue + if (entry.kind == "directory") { + processEntries(entry) + continue + } + if (entry.name.endsWith("/") && entry.content == "") continue - if ("content" in entry) processFile(entry.content) + processFile(filePath, entry.name, async (processContent, ext) => { + if ("content" in entry) processContent(entry.content) else { const reader = new FileReader() if (ext == "png") reader.readAsDataURL(entry) - else entry.text().then(processFile) + else entry.text().then(processContent) reader.onload = () => { - processFile(reader.result) + processContent(reader.result) } reader.onerror = e => { console.warn("Could not read file: " + filePath, e) error++ } } - } - if (!rpMode && ext == "json") { - 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) - Object.keys(rpExclusive).forEach(type => { - if (filePath.includes("/" + type + "/")) rpExclusive[type]++ - }) + }) } } @@ -722,7 +728,8 @@ async function mainScan(hasData = false) { (Object.keys(filetypesOther).length > 0 ? "
" + "Non-pack file types found:" + - Object.keys(filetypesOther).sort((a, b) => filetypesOther[b] - filetypesOther[a]).map(type => "" + type + ": " + localize(filetypesOther[type]) + "
").join("") + + Object.keys(filetypesOther).sort((a, b) => filetypesOther[b] - filetypesOther[a]) + .map(type => "" + type + ": " + localize(filetypesOther[type]) + "
").join("") + "

" : "") + (uncalledFunctions.length > 0 ? diff --git a/eslint.config.js b/eslint.config.js index 868d954..9b19a90 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -131,7 +131,7 @@ const rules = { "@stylistic/js/no-trailing-spaces": 2, "@stylistic/js/max-statements-per-line": 2, "@stylistic/js/max-len": [2, { - code: 220 + code: 210 }], "@stylistic/js/quote-props": [2, "as-needed"], "@stylistic/js/quotes": [2, "double", { @@ -240,7 +240,8 @@ module.exports = [ languageOptions: { globals: { ...global, - ...globals.node + ...globals.node, + processFile: "readonly" } }, files: ["vscExtension/**/*.js", "eslint.config.js", "minify.js"], diff --git a/vscExtension/build.js b/vscExtension/build.js index 1cc870b..1d6d122 100644 --- a/vscExtension/build.js +++ b/vscExtension/build.js @@ -3,13 +3,17 @@ const path = require("node:path") const main = async () => { let extension = await fs.readFile("./src/extension.js", "utf8") - //const packAnalyzer = await fs.readFile("./src/script.js", "utf8") + + const packAnalyzer = await fs.readFile("../assets/script.js", "utf8") + const funcStart = packAnalyzer.indexOf("const processFile = ") + const funcEnd = packAnalyzer.includes("\r\n}", funcStart) ? (packAnalyzer.indexOf("\r\n}", funcStart) + 3) : (packAnalyzer.indexOf("\n}", funcStart) + 2) + extension = extension.replace("/* processFile */", packAnalyzer.substring(funcStart, funcEnd) + "\n") for await (const match of extension.match(/{DPICON\|\w+?}/g)) { const icon = await fs.readFile(path.join(__dirname, "dpIcons", match.replace("{DPICON|", "").replace("}", "") + ".png")) extension = extension.replace(match, Buffer.from(icon).toString("base64")) } - await fs.writeFile("./out/extension.js", /*packAnalyzer.toString() + "\n".repeat(3) +*/ extension.toString()) + await fs.writeFile("./out/extension.js", extension.toString()) } main() diff --git a/vscExtension/src/extension.js b/vscExtension/src/extension.js index 0c3b768..968c73e 100644 --- a/vscExtension/src/extension.js +++ b/vscExtension/src/extension.js @@ -24,7 +24,6 @@ const requestVersions = async () => { } requestVersions() -let interval let files = 0 let done = 0 let error = 0 @@ -33,6 +32,7 @@ let rpMode = false let filetypes = {} let filetypesOther = {} let packFiles = [] +// eslint-disable-next-line sonarjs/no-unused-collection let packImages = [] let commands = {} let cmdsBehindExecute = {} @@ -102,175 +102,16 @@ let rpExclusive = { const localize = str => str.toLocaleString() +/* processFile */ async function processEntries(entries) { for await (const filePath of entries) { const name = filePath.split("/").pop() - const ext = name.split(".").pop() - if ( - ext == "mcmeta" || ext == "json" || - (!rpMode && (ext == "mcfunction" || ext == "nbt")) || - (rpMode && (ext == "png" || ext == "icns" || ext == "txt" || ext == "ogg" || ext == "fsh" || ext == "vsh" || ext == "glsl" || ext == "lang" || ext == "properties" || ext == "inc" || ext == "xcf")) - ) { - if (filetypes[ext]) filetypes[ext]++ - else filetypes[ext] = 1 - } else { - if (filetypesOther[(name.includes(".") ? "." : "") + ext]) filetypesOther[(name.includes(".") ? "." : "") + ext]++ - else filetypesOther[(name.includes(".") ? "." : "") + ext] = 1 - } - - if ( - ext == "mcfunction" || ext == "mcmeta" || (!rpMode && ext == "json" && (filePath.includes("/advancements/") || filePath.includes("/tags/functions/"))) || - ext == "fsh" || ext == "vsh" || ext == "glsl" || name.endsWith("pack.png") - ) { - files++ - - const processFile = result => { - done++ - if (result.trim() == "") return emptyFiles.push(filePath) - - if (!rpMode && ext == "mcfunction") { - const fileLocation = /data\/([-a-z0-9_.]+)\/functions\/([-a-z0-9_./]+)\.mcfunction/i.exec(filePath) - if (fileLocation && !dpExclusive.functions.includes(fileLocation[1] + ":" + fileLocation[2])) dpExclusive.functions.push(fileLocation[1] + ":" + fileLocation[2]) - - for (let line of result.split("\n")) { - line = line.trim() - if (line.startsWith("#")) comments++ - if (line == "") empty++ - if (line.startsWith("#") || line == "") continue - const splitted = line.split(" ") - - let cmd = splitted[0] - if (cmd.startsWith("$")) { - cmd = cmd.slice(1) - if (cmdsBehindMacros[cmd]) cmdsBehindMacros[cmd]++ - else cmdsBehindMacros[cmd] = 1 - } - - if (commands[cmd]) commands[cmd]++ - else commands[cmd] = 1 - - if (cmd == "execute") { - const matches = / run ([a-z_:]{2,})/g.exec(line) - if (matches) matches.forEach(match => { - const cmdBehind = match.replace("run ", "").trim() - - if (cmdsBehindExecute[cmdBehind]) cmdsBehindExecute[cmdBehind]++ - else cmdsBehindExecute[cmdBehind] = 1 - if (commands[cmdBehind]) commands[cmdBehind]++ - else commands[cmdBehind] = 1 - - if (cmdBehind == "return") { - const returnCmd = / run return run ([a-z_:]{2,})/g.exec(line) - if (returnCmd && returnCmd[1]) { - if (cmdsBehindReturn[returnCmd[1]]) cmdsBehindReturn[returnCmd[1]]++ - else cmdsBehindReturn[returnCmd[1]] = 1 - } - } - }) - } else if (cmd == "return") { - const returnCmd = / run return run ([a-z_:]{2,})/g.exec(line) - if (returnCmd && returnCmd[1]) { - if (cmdsBehindReturn[returnCmd[1]]) cmdsBehindReturn[returnCmd[1]]++ - else cmdsBehindReturn[returnCmd[1]] = 1 - } - } - if (fileLocation && (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: fileLocation[1] + ":" + fileLocation[2], - target: (func[2] || "minecraft") + ":" + func[3] - }) - } - - if (/scoreboard objectives add \w+ \w+( .+)?$/.test(line)) dpExclusive.scoreboards++ - - splitted.forEach(arg => { - if (arg.startsWith("@")) { - arg = arg.slice(1) - if (arg.startsWith("a")) dpExclusive.selectors.a++ - else if (arg.startsWith("e")) dpExclusive.selectors.e++ - else if (arg.startsWith("p")) dpExclusive.selectors.p++ - else if (arg.startsWith("r")) dpExclusive.selectors.r++ - else if (arg.startsWith("s")) dpExclusive.selectors.s++ - } - }) - } - } else if (ext == "mcmeta") { - if (name == "pack.mcmeta") { - try { - packFiles.push(JSON.parse(result)) - } catch (e) { - console.warn("Could not parse pack.mcmeta: " + filePath, e) - error++ - } - } - } else if (name.endsWith("pack.png") && !result.includes(">")) packImages.push(result) - else if (rpMode && (ext == "fsh" || ext == "vsh" || ext == "glsl")) { - for (let line of result.split("\n")) { - line = line.trim() - if (line.startsWith("//") || line.startsWith("/*")) comments++ - if (line == "") empty++ - if (line.startsWith("//") || line.startsWith("/*") || line == "") continue - - const cmd = line.match(/^[a-z_#0-9]+/i)?.[0] - if (cmd && cmd != "{" && cmd != "}") { - if (commands[cmd]) commands[cmd]++ - else commands[cmd] = 1 - } - } - } else if (!rpMode && ext == "json") { - if (filePath.includes("/advancements/")) { - const fileLocation = /data\/([-a-z0-9_.]+)\/advancements\/([-a-z0-9_./]+)\.json/i.exec(filePath) - - try { - const parsed = JSON.parse(result) - if (parsed.rewards && parsed.rewards.function) dpExclusive.functionCalls.push({ - source: "(Advancement) " + fileLocation[1] + ":" + fileLocation[2], - target: parsed.rewards.function.includes(":") ? parsed.rewards.function : "minecraft:" + parsed.rewards.function - }) - } catch (e) { - console.warn("Unable to analyze advancement: " + filePath, e) - } - } else if (filePath.includes("/tags/functions/")) { - const fileLocation = /data\/([-a-z0-9_.]+)\/tags\/functions\/([-a-z0-9_./]+)\.json/i.exec(filePath) - if (fileLocation && !dpExclusive.functions.includes("#" + fileLocation[1] + ":" + fileLocation[2])) dpExclusive.functions.push("#" + fileLocation[1] + ":" + fileLocation[2]) - - try { - const parsed = JSON.parse(result) - if (parsed.values) parsed.values.forEach(func => { - if (typeof func == "object") { - if (func.required === false) return - func = func.id - } - - dpExclusive.functionCalls.push({ - source: "#" + fileLocation[1] + ":" + fileLocation[2], - target: func.includes(":") ? func : "minecraft:" + func - }) - }) - } catch (e) { - console.warn("Unable to analyze function tag: " + filePath, e) - } - } - } - } - + await processFile(filePath, name, async processContent => { const content = await vscode.workspace.fs.readFile(vscode.Uri.file(filePath)) const decoder = new TextDecoder() - processFile(decoder.decode(content)) - } - if (!rpMode && ext == "json") { - 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) - Object.keys(rpExclusive).forEach(type => { - if (filePath.includes("/" + type + "/")) rpExclusive[type]++ - }) + processContent(decoder.decode(content)) + }) } log("Successfully processed " + done + " files with " + error + " errors") @@ -278,7 +119,6 @@ async function processEntries(entries) { async function mainScan() { let html = - (packImages.length > 0 ? "
" + packImages.map(img => "") + "
" : "") + (packFiles.length > 0 ? "" + (rpMode ? "Resource" : "Data") + "pack" + (packFiles.length == 1 ? "" : "s") + " found:
" + packFiles.map(pack => { let oldestFormat = pack.pack.pack_format @@ -293,18 +133,7 @@ async function mainScan() { } } - let description = "" - if (pack.pack && pack.pack.description) { - if (typeof pack.pack.description == "object") { - const desc = Array.isArray(pack.pack.description) ? pack.pack.description : [pack.pack.description] - desc.forEach(d => { - if (d.text || d.translation) description += d.text || d.translation - }) - } else description = pack.pack.description - } else description = "No description" - - return "" + description.replace(/§[0-9a-flmnor]/gi, "") + - (versions.some(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == pack.pack.pack_format) ? + return (versions.some(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == pack.pack.pack_format) ? "
Supported versions: " + (versions.findLast(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == oldestFormat)?.name || "?") + " - " + @@ -367,6 +196,8 @@ async function mainScan() { } const collapsible = new Set([ + "packs", + "dpExclusive", "rpExclusive", @@ -486,12 +317,30 @@ class PackAnalyzer { else if (element.item == "error") treeItem.label = "Scanning errors: " + localize(error) else if (element.item == "rpMode") treeItem.label = "Resource pack mode: " + (rpMode ? "enabled" : "disabled") - else if (element.item == "dpExclusive") { + else if (element.item == "packs") { + log(JSON.stringify(packFiles)) + treeItem.label = "Packs: " + localize(packFiles.length) + } else if (element.parent == "packs") { + log(JSON.stringify(packFiles)) + const pack = packFiles[element.item] + let description = "" + if (pack.pack && pack.pack.description) { + if (typeof pack.pack.description == "object") { + const desc = Array.isArray(pack.pack.description) ? pack.pack.description : [pack.pack.description] + desc.forEach(d => { + if (d.text || d.translation) description += d.text || d.translation + }) + } else description = pack.pack.description + } else description = "Pack #" + (element.item + 1) + + treeItem.label = description.replace(/§[0-9a-flmnor]/gi, "") + } else if (element.item == "dpExclusive") { treeItem.label = "Data pack" treeItem.iconPath = iconUrl("{DPICON|mcfunction}") } else if (element.item == "tags") { treeItem.label = "Tags" - treeItem.description = "(" + localize(Object.values(dpExclusive.tags).reduce((a, b) => a + b)) + " total, " + localize(Object.keys(dpExclusive.tags).length) + " unique)" + treeItem.description = "(" + localize(Object.values(dpExclusive.tags).reduce((a, b) => a + b)) + " total, " + + localize(Object.keys(dpExclusive.tags).filter(key => dpExclusive.tags[key] > 0).length) + " unique)" treeItem.iconPath = iconUrl("{DPICON|tags}") } else if (element.parent == "tags") { treeItem.label = element.item + ": " + localize(dpExclusive.tags[element.item]) @@ -565,6 +414,8 @@ class PackAnalyzer { if (element) { const item = element.item + if (item == "packs") return packFiles.map((pack, i) => ({item: i, parent: item})) + if (item == "dpExclusive") return [ Object.keys(dpExclusive.tags).reduce((a, b) => a + dpExclusive.tags[b], 0) > 0 ? "tags" : void 0, dpExclusive.scoreboards > 0 ? "scoreboards" : void 0, @@ -608,6 +459,7 @@ class PackAnalyzer { "files", error > 0 ? "error" : void 0, "rpMode", + "packs", rpMode ? void 0 : "dpExclusive", rpMode ? "rpExclusive" : void 0,