Skip to content

Commit

Permalink
Add Datapack Icons & much more content
Browse files Browse the repository at this point in the history
Displays the uncalled & missing functions and changes a few item descriptions
  • Loading branch information
DEVTomatoCake committed Apr 13, 2024
1 parent 1854498 commit 0a63baa
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 68 deletions.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ module.exports = [
}
},
files: ["vscExtension/**/*.js", "eslint.config.js", "minify.js"],
ignores: ["vscExtension/out/*.js"],
plugins: {
unicorn,
sonarjs,
Expand Down
2 changes: 2 additions & 0 deletions vscExtension/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build.js
src/**
8 changes: 7 additions & 1 deletion vscExtension/build.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const fs = require("node:fs").promises
const path = require("node:path")

const main = async () => {
const extension = await fs.readFile("./src/extension.js", "utf8")
let extension = await fs.readFile("./src/extension.js", "utf8")
//const packAnalyzer = await fs.readFile("./src/script.js", "utf8")

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())
}
main()
5 changes: 5 additions & 0 deletions vscExtension/dpIcons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
All icons in this folder are from the [**Datapack Icons** extension](https://marketplace.visualstudio.com/items?itemName=SuperAnt.mc-dp-icons) created by SuperAnt_, bth123 and amandin.

They have given permission to use these icons in this extension.

Please see their [GitHub repository](https://github.com/SuperAnt220/mc-dp-icons) and [license](https://github.com/SuperAnt220/mc-dp-icons/blob/main/LICENSE.txt) for more information.
Binary file added vscExtension/dpIcons/assets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/atlases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/blockstates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/functions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/lang.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/mcfunction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/mcfunction_load.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/md.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/misc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/namespace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/particles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/shaders.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/sounds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/src_folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/tags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/texts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscExtension/dpIcons/textures.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions vscExtension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
"commands": [
{
"command": "packAnalyzer.refresh",
"title": "Refresh",
"icon": {
"light": "resources/light/refresh.svg",
"dark": "resources/dark/refresh.svg"
}
"title": "Refresh"
}
],
"menus": {
Expand Down
157 changes: 95 additions & 62 deletions vscExtension/src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,6 @@ async function processEntries(entries) {
}

async function mainScan() {
const uncalledFunctions = dpExclusive.functions.filter(funcName => !dpExclusive.functionCalls.some(func => func.target == funcName))
const missingFunctions = [...new Set(dpExclusive.functionCalls.filter(func => !dpExclusive.functions.includes(func.target)).map(func => func.target))]

let html =
(packImages.length > 0 ? "<div style='display: flex;'>" + packImages.map(img => "<img src='" + img + "' width='64' height='64'>") + "</div>" : "") +
(packFiles.length > 0 ? "<strong>" + (rpMode ? "Resource" : "Data") + "pack" + (packFiles.length == 1 ? "" : "s") + " found:</strong><br>" +
Expand Down Expand Up @@ -330,12 +327,6 @@ async function mainScan() {
: "") +
(packFiles.length == 0 && (filetypes.fsh || filetypes.vsh || filetypes.xcf || filetypes.glsl) ? "<strong>Shader found</strong><br>" : "") +

(Object.keys(commands).length > 0 ?
"<strong>Total amount of commands: " + localize(Object.keys(commands).reduce((a, b) => a + commands[b], 0)) + "</strong><br>" +
"<span class='indented'>Unique command names: " + localize(Object.keys(commands).length) + "</span><br>"
: "") +
(comments > 0 ? "<span class='indented'>Comments: " + localize(comments) + "</span><br>" : "") +
(empty > 0 ? "<span class='indented'>Empty lines: " + localize(empty) + "</span><br>" : "") +
"<strong>Pack file types found:</strong><br>" +
Object.keys(filetypes).sort((a, b) => filetypes[b] - filetypes[a]).map(type => "<span class='indented'>." + type + ": " + localize(filetypes[type]) + "</span><br>").join("") +
(Object.keys(filetypesOther).length > 0 ?
Expand All @@ -344,16 +335,6 @@ async function mainScan() {
Object.keys(filetypesOther).sort((a, b) => filetypesOther[b] - filetypesOther[a]).map(type => "<span class='indented'>" + type + ": " + localize(filetypesOther[type]) + "</span><br>").join("") +
"</details><br>"
: "") +
(uncalledFunctions.length > 0 ?
"<strong>Uncalled functions:</strong><br>" +
uncalledFunctions.map(func => "<span class='indented'>" + func + "</span><br>").join("") +
"<br>"
: "") +
(missingFunctions.length > 0 ?
"<strong>Missing functions:</strong><br>" +
missingFunctions.map(func => "<span class='indented'>" + func + "</span><br>").join("") +
"<br>"
: "") +
(emptyFiles.length > 0 ?
"<strong>Empty files:</strong><br>" +
emptyFiles.map(func => "<span class='indented'>" + func + "</span><br>").join("") +
Expand Down Expand Up @@ -396,11 +377,19 @@ const collapsible = new Set([
"cmdsBehindMacros",
"cmdsBehindReturn",

"folders",
"tags",
"selectors"
"selectors",

"uncalledFunctions",
"missingFunctions"
])

const iconUrl = (icon = "") =>
vscode.Uri.from({
scheme: "data",
path: "image/png;base64," + icon + ""
})

class PackAnalyzer {
constructor() {
this._onDidChangeTreeData = new vscode.EventEmitter()
Expand Down Expand Up @@ -489,42 +478,85 @@ class PackAnalyzer {
getTreeItem(element) {
log("getTreeItem: " + JSON.stringify(element))

let label = element.item
const treeItem = new vscode.TreeItem(label)

if (element.item == "files") label = "Scanned files: " + files
else if (element.item == "error") label = "Scanning errors: " + error
else if (element.item == "rpMode") label = "Resource pack mode: " + (rpMode ? "enabled" : "disabled")

else if (element.item == "dpExclusive") label = "Data pack"
else if (element.parent == "folders") label = element.item + ": " + dpExclusive.folders[element.item]
else if (element.parent == "tags") label = element.item + ": " + dpExclusive.tags[element.item]
else if (element.item == "scoreboards") label = "Scoreboards: " + dpExclusive.scoreboards
else if (element.item == "selectors") label = "Selectors: " + Object.keys(dpExclusive.selectors).length
else if (element.parent == "selectors") label = "@" + element.item + ": " + dpExclusive.selectors[element.item]

else if (element.item == "rpExclusive") label = "Resource pack"
else if (element.parent == "rpExclusive") label = element.item + ": " + rpExclusive[element.item]

else if (element.item == "filetypes") label = "File types: " + Object.keys(filetypes).length
else if (element.parent == "filetypes") label = "." + element.item + ": " + filetypes[element.item]
else if (element.item == "filetypesOther") label = "Non-pack file types: " + Object.keys(filetypesOther).length
else if (element.parent == "filetypesOther") label = element.item + ": " + filetypesOther[element.item]

else if (element.item == "commands") label = "Commands: " + Object.keys(commands).length
else if (element.parent == "commands") {
label = element.item + ": " + commands[element.item]
if (cmdsBehindExecute[element.item]) treeItem.description = "(" + cmdsBehindExecute[element.item] + " behind execute)"
} else if (element.item == "cmdsBehindMacros") label = "Commands behind macros: " + Object.keys(cmdsBehindMacros).length
else if (element.item == "cmdsBehindReturn") label = "Commands behind return: " + Object.keys(cmdsBehindReturn).length

else if (element.item == "comments") label = "Comments: " + comments
else if (element.item == "empty") label = "Empty lines: " + empty
else if (element.item == "emptyFiles") label = "Empty files: " + emptyFiles.length

treeItem.label = label
const treeItem = new vscode.TreeItem(element.item)
treeItem.iconPath = iconUrl("{DPICON|namespace}")
if (collapsible.has(element.item)) treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed

if (element.item == "files") treeItem.label = "Scanned files: " + localize(files)
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") {
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.iconPath = iconUrl("{DPICON|tags}")
} else if (element.parent == "tags") {
treeItem.label = element.item + ": " + localize(dpExclusive.tags[element.item])
treeItem.iconPath = iconUrl("{DPICON|tags}")
} else if (element.item == "scoreboards") treeItem.label = "Scoreboards: " + localize(dpExclusive.scoreboards)
else if (element.item == "selectors") {
treeItem.label = "Selectors"
treeItem.iconPath = iconUrl("{DPICON|mcfunction}")
} else if (element.parent == "selectors") {
treeItem.label = "@" + element.item + ": " + localize(dpExclusive.selectors[element.item])
treeItem.iconPath = iconUrl("{DPICON|mcfunction}")
} else if (element.item == "rpExclusive") {
treeItem.label = "Resource pack"
treeItem.iconPath = iconUrl("{DPICON|assets}")
} else if (element.parent == "rpExclusive") {
treeItem.label = element.item + ": " + localize(rpExclusive[element.item])

// Must be hardcoded due to static replacement in vscExtension/build.js
if (element.item == "atlases") treeItem.iconPath = iconUrl("{DPICON|atlases}")
else if (element.item == "blockstates") treeItem.iconPath = iconUrl("{DPICON|blockstates}")
else if (element.item == "font") treeItem.iconPath = iconUrl("{DPICON|font}")
else if (element.item == "lang") treeItem.iconPath = iconUrl("{DPICON|lang}")
else if (element.item == "models") treeItem.iconPath = iconUrl("{DPICON|models}")
else if (element.item == "particles") treeItem.iconPath = iconUrl("{DPICON|particles}")
else if (element.item == "shaders") treeItem.iconPath = iconUrl("{DPICON|shaders}")
else if (element.item == "sounds") treeItem.iconPath = iconUrl("{DPICON|sounds}")
else if (element.item == "texts") treeItem.iconPath = iconUrl("{DPICON|texts}")
else if (element.item == "textures") treeItem.iconPath = iconUrl("{DPICON|textures}")
} else if (element.item == "filetypes") {
treeItem.label = "Files"
treeItem.description = "(parsed only; " + localize(Object.values(filetypes).reduce((a, b) => a + b)) + " total, " + localize(Object.keys(filetypes).length) + " unique)"
treeItem.iconPath = iconUrl("{DPICON|folder}")
} else if (element.parent == "filetypes") treeItem.label = "." + element.item + ": " + localize(filetypes[element.item])

else if (element.item == "commands") {
treeItem.label = "Commands"
treeItem.description = "(" + localize(Object.values(commands).reduce((a, b) => a + b)) + " total, " + localize(Object.keys(commands).length) + " unique)"
} else if (element.parent == "commands") {
treeItem.label = element.item + ": " + localize(commands[element.item])
if (cmdsBehindExecute[element.item]) {
treeItem.description = (element.item == "execute" ? "⚠️ " : "") + "(" + localize(cmdsBehindExecute[element.item]) + " behind execute)"
if (element.item == "execute") treeItem.tooltip = "⚠️ (\"... run execute ...\" equals \"... ...\")"
}
} else if (element.item == "cmdsBehindMacros") treeItem.label = "Commands behind macros: " + localize(Object.keys(cmdsBehindMacros).length)
else if (element.parent == "cmdsBehindMacros") treeItem.label = element.item + ": " + localize(cmdsBehindMacros[element.item])
else if (element.item == "cmdsBehindReturn") treeItem.label = "Commands behind return: " + localize(Object.keys(cmdsBehindReturn).length)
else if (element.parent == "cmdsBehindReturn") treeItem.label = element.item + ": " + localize(cmdsBehindReturn[element.item])

else if (element.item == "comments") {
treeItem.label = "Comments: " + localize(comments)
treeItem.iconPath = iconUrl("{DPICON|md}")
} else if (element.item == "empty") {
treeItem.label = "Empty lines: " + localize(empty)
treeItem.iconPath = iconUrl("{DPICON|misc}")
} else if (element.item == "emptyFiles") {
treeItem.label = "Empty files: " + localize(emptyFiles.length)
treeItem.iconPath = iconUrl("{DPICON|misc}")
} else if (element.item == "uncalledFunctions") {
treeItem.label = "Uncalled functions: " + localize(dpExclusive.uncalledFunctions.length)
treeItem.iconPath = iconUrl("{DPICON|mcfunction}")
} else if (element.item == "missingFunctions") {
treeItem.label = "Missing functions: " + localize(dpExclusive.missingFunctions.length)
treeItem.iconPath = iconUrl("{DPICON|mcfunction}")
}

return treeItem
}

Expand All @@ -534,26 +566,26 @@ class PackAnalyzer {
if (element) {
const item = element.item
if (item == "dpExclusive") return [
Object.keys(dpExclusive.folders).reduce((a, b) => a + dpExclusive.folders[b], 0) > 0 ? "folders" : void 0,
Object.keys(dpExclusive.tags).reduce((a, b) => a + dpExclusive.tags[b], 0) > 0 ? "tags" : void 0,
dpExclusive.scoreboards > 0 ? "scoreboards" : void 0,
Object.keys(dpExclusive.selectors).reduce((a, b) => a + dpExclusive.selectors[b], 0) > 0 ? "selectors" : void 0,
"uncalledFunctions",
"missingFunctions"
dpExclusive.uncalledFunctions.length > 0 ? "uncalledFunctions" : void 0,
dpExclusive.missingFunctions.length > 0 ? "missingFunctions" : void 0
].filter(Boolean).map(child => ({item: child, parent: item}))

if (item == "folders") return Object.keys(dpExclusive.folders).filter(key => dpExclusive.folders[key] > 0).map(child => ({item: child, parent: item}))
if (item == "tags") return Object.keys(dpExclusive.tags).filter(key => dpExclusive.tags[key] > 0).map(child => ({item: child, parent: item}))
if (item == "selectors") return Object.keys(dpExclusive.selectors).filter(key => dpExclusive.selectors[key] > 0).map(child => ({item: child, parent: item}))

if (item == "rpExclusive") return Object.keys(rpExclusive).filter(key => rpExclusive[key] > 0).map(child => ({item: child, parent: item}))

if (item == "filetypes") return Object.keys(filetypes).map(child => ({item: child, parent: item}))
if (item == "filetypesOther") return Object.keys(filetypesOther).map(child => ({item: child, parent: item}))

if (item == "commands") return Object.keys(commands).map(child => ({item: child, parent: item}))
if (item == "cmdsBehindMacros") return Object.keys(cmdsBehindMacros).map(child => ({item: child, parent: item}))
if (item == "cmdsBehindReturn") return Object.keys(cmdsBehindReturn).map(child => ({item: child, parent: item}))

if (item == "missingFunctions") return dpExclusive.missingFunctions.map(child => ({item: child, parent: item}))
if (item == "uncalledFunctions") return dpExclusive.uncalledFunctions.map(child => ({item: child, parent: item}))
}

const fileList = await vscode.workspace.findFiles("**/*")
Expand All @@ -569,16 +601,17 @@ class PackAnalyzer {
return []
}

dpExclusive.uncalledFunctions = dpExclusive.functions.filter(funcName => !dpExclusive.functionCalls.some(func => func.target == funcName))
dpExclusive.missingFunctions = [...new Set(dpExclusive.functionCalls.filter(func => !dpExclusive.functions.includes(func.target)).map(func => func.target))]

return [
"files",
error > 0 ? "error" : void 0,
"rpMode",

rpMode ? void 0 : "dpExclusive",
rpMode ? "rpExclusive" : void 0,

Object.keys(filetypes).length > 0 ? "filetypes" : void 0,
Object.keys(filetypesOther).length > 0 ? "filetypesOther" : void 0,

Object.keys(commands).length > 0 ? "commands" : void 0,
Object.keys(cmdsBehindMacros).length > 0 ? "cmdsBehindMacros" : void 0,
Expand Down

0 comments on commit 0a63baa

Please sign in to comment.