diff --git a/assets/analyzer.js b/assets/analyzer.js index 703af07..c755e22 100644 --- a/assets/analyzer.js +++ b/assets/analyzer.js @@ -12,6 +12,7 @@ let packImages = [] let commands = {} let cmdsBehindExecute = {} let cmdsBehindMacros = {} +let cmdsBehindReturn = {} let comments = 0 let empty = 0 let emptyFiles = [] @@ -117,17 +118,28 @@ async function processEntries(entries) { if (commands[cmd]) commands[cmd]++ else commands[cmd] = 1 - // TODO: Count "return run ..." commands if (cmd == "execute") { - line.match(/run ([a-z_:]{2,})/g)?.forEach(match => { - if (match[1] == "return") return - - const cmdBehind = match.replace("run ", "").trim() - if (cmdsBehindExecute[cmdBehind]) cmdsBehindExecute[cmdBehind]++ - else cmdsBehindExecute[cmdBehind] = 1 - if (commands[cmdBehind]) commands[cmdBehind]++ - else commands[cmdBehind] = 1 + const matches = / run ([a-z_:]{2,})/g.exec(line) + if (matches) matches.forEach(match => { + if (cmdsBehindExecute[match[1]]) cmdsBehindExecute[match[1]]++ + else cmdsBehindExecute[match[1]] = 1 + if (commands[match[1]]) commands[match[1]]++ + else commands[match[1]] = 1 + + if (match[1] == "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 (cmd == "function" || line.includes(" function ") || line.includes("/function ")) { const func = /function ((#?[-a-z0-9_.]+):)?([-a-z0-9_./]+)/i.exec(line) @@ -257,6 +269,7 @@ async function mainScan(hasData = false) { commands = {} cmdsBehindExecute = {} cmdsBehindMacros = {} + cmdsBehindReturn = {} comments = 0 empty = 0 emptyFiles = [] @@ -339,7 +352,9 @@ async function mainScan(hasData = false) { } } - return "" + (pack.pack?.description?.replace(/§[0-9a-flmnor]/gi, "") || "No description") + + const description = pack.pack && pack.pack.description ? + (typeof pack.pack.description == "object" ? (pack.pack.description.text || pack.pack.description.translation) : pack.pack.description) : "No description" + return "" + description.replace(/§[0-9a-flmnor]/gi, "") + (window.versions.some(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == pack.pack.pack_format) ? "
Supported versions: " + (window.versions.findLast(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == oldestFormat)?.name || "?") + @@ -415,6 +430,7 @@ async function mainScan(hasData = false) { if (cmdsBehindExecute[cmd]) html += "Behind execute: " + localize(cmdsBehindExecute[cmd]) + (cmd == "execute" ? "⚠️ (... run execute ... equals ... ...)" : "") + "
" if (cmdsBehindMacros[cmd]) html += "Behind macro: " + localize(cmdsBehindMacros[cmd]) + "
" + if (cmdsBehindReturn[cmd]) html += "Behind return: " + localize(cmdsBehindReturn[cmd]) + "
" }) document.getElementById("result").innerHTML = html } diff --git a/assets/script.js b/assets/script.js index ec3808a..0b7eab7 100644 --- a/assets/script.js +++ b/assets/script.js @@ -53,8 +53,11 @@ window.addEventListener("load", () => { packFiles = parsed.packFiles commands = parsed.commands cmdsBehindExecute = parsed.cmdsBehindExecute + cmdsBehindMacros = parsed.cmdsBehindMacros + cmdsBehindReturn = parsed.cmdsBehindReturn comments = parsed.comments empty = parsed.empty + emptyFiles = parsed.emptyFiles dpExclusive = parsed.dpExclusive rpExclusive = parsed.rpExclusive @@ -148,6 +151,7 @@ async function share(type) { commands, cmdsBehindExecute, cmdsBehindMacros, + cmdsBehindReturn, comments, empty, emptyFiles,