mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 04:05:46 +01:00
fix editor not loading files
This commit is contained in:
parent
41593e0dce
commit
b2b682fa04
24
dist/vendor.bundle.js
vendored
24
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
@ -10,8 +10,26 @@ if (greenworks.init()) {
|
||||
|
||||
const debug = false;
|
||||
|
||||
let win = null;
|
||||
|
||||
require("http")
|
||||
.createServer(async function (req, res) {
|
||||
let body = "";
|
||||
req.on("data", (chunk) => {
|
||||
body += chunk.toString(); // convert Buffer to string
|
||||
});
|
||||
req.on("end", () => {
|
||||
const data = JSON.parse(body);
|
||||
win.webContents.executeJavaScript(`document.saveFile("${data.filename}", "${data.code}")`).then((result) => {
|
||||
res.write(result);
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
})
|
||||
.listen(9990);
|
||||
|
||||
function createWindow(killall) {
|
||||
const win = new BrowserWindow({
|
||||
win = new BrowserWindow({
|
||||
show: false,
|
||||
backgroundThrottling: false,
|
||||
backgroundColor: "#000000",
|
||||
@ -41,7 +59,6 @@ function createWindow(killall) {
|
||||
const achievements = greenworks.getAchievementNames();
|
||||
const intervalID = setInterval(async () => {
|
||||
const achs = await win.webContents.executeJavaScript("document.achievements");
|
||||
console.log(achs);
|
||||
for (const ach of achs) {
|
||||
if (!achievements.includes(ach)) continue;
|
||||
greenworks.activateAchievement(ach, () => undefined);
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -14,6 +14,8 @@ import { HacknetServer } from "./Hacknet/HacknetServer";
|
||||
import { CityName } from "./Locations/data/CityNames";
|
||||
import { Player } from "./Player";
|
||||
import { Programs } from "./Programs/Programs";
|
||||
import { isScriptFilename } from "./Script/isScriptFilename";
|
||||
import { Script } from "./Script/Script";
|
||||
import { GetAllServers, GetServer } from "./Server/AllServers";
|
||||
import { SpecialServers } from "./Server/data/SpecialServers";
|
||||
import { Server } from "./Server/Server";
|
||||
@ -412,5 +414,30 @@ function calculateAchievements(): void {
|
||||
|
||||
export function initElectron(): void {
|
||||
setAchievements([]);
|
||||
initWebserver();
|
||||
setInterval(calculateAchievements, 5000);
|
||||
}
|
||||
|
||||
function initWebserver(): void {
|
||||
(document as any).saveFile = function (filename: string, code: string): string {
|
||||
const home = GetServer("home");
|
||||
if (home === null) return "'home' server not found.";
|
||||
if (home === null) return "Server should not be null but it is.";
|
||||
if (isScriptFilename(filename)) {
|
||||
//If the current script already exists on the server, overwrite it
|
||||
for (let i = 0; i < home.scripts.length; i++) {
|
||||
if (filename == home.scripts[i].filename) {
|
||||
home.scripts[i].saveScript(filename, code, "home", home.scripts);
|
||||
}
|
||||
}
|
||||
|
||||
//If the current script does NOT exist, create a new one
|
||||
const script = new Script();
|
||||
script.saveScript(filename, code, "home", home.scripts);
|
||||
home.scripts.push(script);
|
||||
return "written";
|
||||
}
|
||||
|
||||
return "not a script file";
|
||||
};
|
||||
}
|
||||
|
@ -333,10 +333,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
|
||||
if (editorRef.current === null || monacoRef.current === null) return;
|
||||
|
||||
if (props.files) {
|
||||
const files = Object.entries(props.files);
|
||||
|
||||
if (!files.length && currentScript !== null) {
|
||||
if (!props.files && currentScript !== null) {
|
||||
// Open currentscript
|
||||
regenerateModel(currentScript);
|
||||
editorRef.current.setModel(currentScript.model);
|
||||
@ -346,6 +343,8 @@ export function Root(props: IProps): React.ReactElement {
|
||||
editorRef.current.focus();
|
||||
return;
|
||||
}
|
||||
if (props.files) {
|
||||
const files = Object.entries(props.files);
|
||||
|
||||
if (!files.length) {
|
||||
editorRef.current.focus();
|
||||
@ -383,6 +382,8 @@ export function Root(props: IProps): React.ReactElement {
|
||||
updateRAM(newScript.code);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("here we need to load something if we can");
|
||||
}
|
||||
|
||||
editorRef.current.focus();
|
||||
|
Loading…
Reference in New Issue
Block a user