Skip to content

Commit

Permalink
Reworked showvanilla files (#459)
Browse files Browse the repository at this point in the history
* Reworked showvanilla files

* Removed unnesscary trigger
  • Loading branch information
DaanV2 authored Mar 9, 2023
1 parent e0f6f4a commit 2e95a7b
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 176 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ name: PR

on:
push: {}
pull_request: {}
workflow_dispatch: {}

jobs:
Expand Down
3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
},
"dependencies": {
"@blockception/shared": "^0.0.1",
"@types/node-fetch": "^2.6.2",
"bc-minecraft-bedrock-project": "^1.19.50-1",
"bc-minecraft-bedrock-vanilla-data": "^1.19.60-0",
"node": "^19.0.0",
"node-fetch": "^2.6.9",
"vscode-languageclient": "^8.0.2"
},
"devDependencies": {
Expand Down
63 changes: 33 additions & 30 deletions client/src/Commands/Vanilla/ShowVanillaFile.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import path from "path";
import { commands, ExtensionContext, Uri, window } from "vscode";
import { Commands, GetBedrockInstallationFolder } from "@blockception/shared";
import { Glob } from "../../Glob";
import { commands, ExtensionContext, Uri, window, workspace } from "vscode";
import { Commands } from "@blockception/shared";
import { GithubFiles } from "bc-minecraft-bedrock-vanilla-data/lib/src/Lib/Vanilla/sources";
import fetch, { RequestInit } from "node-fetch";

export function Activate(context: ExtensionContext): void {
context.subscriptions.push(commands.registerCommand(Commands.ShowVanillaFile, ShowVanillaFile));
}
async function ShowVanillaFile(args: any) {
const source = GithubFiles.source;
const files = GithubFiles.files;

function ShowVanillaFile(args: any) {
const dir = path.join(GetBedrockInstallationFolder(), "data");
const files = Glob.GetFiles(["{behavior_packs,resource_packs}/vanilla**/**/*.json"], ["behavior_trees", "contents.json"], dir);
if (files.length === 0) {
return;
}

if (files.length === 0) {
window.showErrorMessage("No vanilla files found");
return;
}
window.showQuickPick(files).then((filepath) => {
if (!filepath) {
return;
}

const options: Record<string, string> = {};

files.forEach((file) => {
const key = path.basename(file);
options[key] = file;
});
const uri = Uri.parse(source + filepath);
const options: RequestInit = {
method: "GET",
redirect: "error",
};

const keys = Object.keys(options);
keys.sort();
console.log("Downloading vanilla file", filepath)
return fetch(uri.toString(), options)
.then(data => data.text())
.then(text => {
workspace.openTextDocument({ language: "json", content: text }).then(doc => window.showTextDocument(doc))
})
.catch(err => {
window.showErrorMessage("Failed to download vanilla file", filepath as string, JSON.stringify(err));
}).finally(() => {
console.log("Downloaded vanilla file", filepath)
});

window.showQuickPick(keys).then((key) => {
if (key) {
let file = options[key];
if (file) {
const uri = Uri.file(file);
});
}

window.showTextDocument(uri, { preview: false });
}
}
});
context.subscriptions.push(commands.registerCommand(Commands.ShowVanillaFile, ShowVanillaFile));
}
4 changes: 2 additions & 2 deletions client/src/Console/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class Console {
}

/**Sends a error to the console log of the server*/
static Log(message: string): void {
console.log(message);
static Log(message: string, ...optionalParams: any): void {
console.log(message, ...optionalParams);
}

/**Sends a error to the console log of the server*/
Expand Down
23 changes: 0 additions & 23 deletions client/src/Glob/Glob.test.ts

This file was deleted.

82 changes: 0 additions & 82 deletions client/src/Glob/Glob.ts

This file was deleted.

3 changes: 0 additions & 3 deletions client/src/Glob/index.ts

This file was deleted.

Loading

0 comments on commit 2e95a7b

Please sign in to comment.