Skip to content

Commit

Permalink
Parse advancements & store func call src
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Dec 6, 2023
1 parent 69da242 commit 05c67f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"no-unsafe-optional-chaining": 2,
"no-unmodified-loop-condition": 2,
"no-promise-executor-return": 2,
"no-warning-comments": 2,
"no-warning-comments": 1,
"no-var": 2,
"no-new-func": 2,
"no-new-wrappers": 2,
Expand Down
31 changes: 22 additions & 9 deletions assets/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ async function processEntries(entries) {
})
}
if (cmd == "function" || cmd.includes(" function ")) {
const func = /function ([-a-z0-9_]+):([-a-z0-9_/]+)/i.exec(line)
if (func && !dpExclusive.functionCalls.includes(func[1] + ":" + func[2])) dpExclusive.functionCalls.push(func[1] + ":" + func[2])
const func = /function (([-a-z0-9_]+):)?([-a-z0-9_/]+)/i.exec(line)
dpExclusive.functionCalls.push({
source: funcLocation[1] + ":" + funcLocation[2],
target: (func[2] || "minecraft") + ":" + func[3]
})
}

if (/scoreboard objectives add \w+ \w+( .+)?$/.test(line)) dpExclusive.scoreboards++
Expand Down Expand Up @@ -174,8 +177,16 @@ async function processEntries(entries) {
}
}
} else if (!rpMode && ext == "json") {
if (filePath.includes("/advancements/")) dpExclusive.folders.advancements++
else if (filePath.includes("/loot_tables/")) dpExclusive.folders.loot_tables++
// TODO: Refactor to avoid duplicate code

Check warning on line 180 in assets/analyzer.js

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected 'todo' comment: 'TODO: Refactor to avoid duplicate code'
if (filePath.includes("/advancements/")) {
dpExclusive.folders.advancements++

const parsed = JSON.parse(entry.content)
if (parsed.rewards && parsed.rewards.function) dpExclusive.functionCalls.push({
source: "(Advancement) " + entry.name,
target: parsed.rewards.function.includes(":") ? parsed.rewards.function : "minecraft:" + parsed.rewards.function
})
} 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++
Expand All @@ -191,9 +202,11 @@ async function processEntries(entries) {
dpExclusive.tags.functions++

const parsed = JSON.parse(entry.content)
console.log(parsed)
parsed.values.forEach(func => {
dpExclusive.functionCalls.push(func)
if (parsed.values) parsed.values.forEach(func => {
dpExclusive.functionCalls.push({
source: "(Tag) " + entry.name,
target: func.includes(":") ? func : "minecraft:" + func
})
})
} else if (filePath.includes("/tags/game_events/")) dpExclusive.tags.game_events++
else if (filePath.includes("/tags/items/")) dpExclusive.tags.items++
Expand Down Expand Up @@ -294,8 +307,8 @@ async function mainScan(hasData = false) {
if (error == 0) document.getElementById("progress").innerText = ""
if (Object.values(filetypes).reduce((a, b) => a + b) == 0) document.getElementById("progress").innerHTML = "No " + (rpMode ? "resource" : "data") + "pack files found!"

const uncalledFunctions = dpExclusive.functions.filter(func => !dpExclusive.functionCalls.includes(func))
const missingFunctions = dpExclusive.functionCalls.filter(func => !dpExclusive.functions.includes(func))
const uncalledFunctions = dpExclusive.functions.filter(funcName => !dpExclusive.functionCalls.some(func => func.target == funcName))
const missingFunctions = dpExclusive.functionCalls.filter(func => !dpExclusive.functions.includes(func.target))

let html =
(packImages.length > 0 ? "<div style='display: flex;'>" + packImages.map(img => "<img src='" + img + "' width='64' height='64'>") + "</div>" : "") +
Expand Down
2 changes: 1 addition & 1 deletion assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function createImage() {
ctx.fillStyle = "white"
ctx.fillRect(0, 0, canvas.width, canvas.height)

drawing = new Image()
const drawing = new Image()
drawing.src = "./assets/images/generated_background.png"
drawing.onload = () => {
ctx.globalAlpha = 0.3
Expand Down

0 comments on commit 05c67f7

Please sign in to comment.