mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-20 14:43:48 +01:00
Merge branch 'dev' of https://github.com/Undeemiss/bitburner into message-refactor
This commit is contained in:
commit
58bd2de8e5
@ -22,7 +22,8 @@ function error_process(err, error_callback) {
|
|||||||
if (err && error_callback) error_callback(err);
|
if (err && error_callback) error_callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type, success_callback, error_callback) {
|
if (greenworks) {
|
||||||
|
greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type, success_callback, error_callback) {
|
||||||
if (typeof options !== "object") {
|
if (typeof options !== "object") {
|
||||||
error_callback = success_callback;
|
error_callback = success_callback;
|
||||||
success_callback = ugc_query_type;
|
success_callback = ugc_query_type;
|
||||||
@ -34,16 +35,16 @@ greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type, s
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, success_callback, error_callback);
|
greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, success_callback, error_callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
greenworks.ugcGetUserItems = function (
|
greenworks.ugcGetUserItems = function (
|
||||||
options,
|
options,
|
||||||
ugc_matching_type,
|
ugc_matching_type,
|
||||||
ugc_list_sort_order,
|
ugc_list_sort_order,
|
||||||
ugc_list,
|
ugc_list,
|
||||||
success_callback,
|
success_callback,
|
||||||
error_callback,
|
error_callback,
|
||||||
) {
|
) {
|
||||||
if (typeof options !== "object") {
|
if (typeof options !== "object") {
|
||||||
error_callback = success_callback;
|
error_callback = success_callback;
|
||||||
success_callback = ugc_list;
|
success_callback = ugc_list;
|
||||||
@ -63,9 +64,9 @@ greenworks.ugcGetUserItems = function (
|
|||||||
success_callback,
|
success_callback,
|
||||||
error_callback,
|
error_callback,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, error_callback) {
|
greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, error_callback) {
|
||||||
if (typeof options !== "object") {
|
if (typeof options !== "object") {
|
||||||
error_callback = success_callback;
|
error_callback = success_callback;
|
||||||
success_callback = sync_dir;
|
success_callback = sync_dir;
|
||||||
@ -76,9 +77,9 @@ greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, error_callback);
|
greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, error_callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
greenworks.publishWorkshopFile = function (
|
greenworks.publishWorkshopFile = function (
|
||||||
options,
|
options,
|
||||||
file_path,
|
file_path,
|
||||||
image_path,
|
image_path,
|
||||||
@ -86,7 +87,7 @@ greenworks.publishWorkshopFile = function (
|
|||||||
description,
|
description,
|
||||||
success_callback,
|
success_callback,
|
||||||
error_callback,
|
error_callback,
|
||||||
) {
|
) {
|
||||||
if (typeof options !== "object") {
|
if (typeof options !== "object") {
|
||||||
error_callback = success_callback;
|
error_callback = success_callback;
|
||||||
success_callback = description;
|
success_callback = description;
|
||||||
@ -99,10 +100,18 @@ greenworks.publishWorkshopFile = function (
|
|||||||
tags: [],
|
tags: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
greenworks._publishWorkshopFile(options, file_path, image_path, title, description, success_callback, error_callback);
|
greenworks._publishWorkshopFile(
|
||||||
};
|
options,
|
||||||
|
file_path,
|
||||||
|
image_path,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
success_callback,
|
||||||
|
error_callback,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
greenworks.updatePublishedWorkshopFile = function (
|
greenworks.updatePublishedWorkshopFile = function (
|
||||||
options,
|
options,
|
||||||
published_file_handle,
|
published_file_handle,
|
||||||
file_path,
|
file_path,
|
||||||
@ -111,7 +120,7 @@ greenworks.updatePublishedWorkshopFile = function (
|
|||||||
description,
|
description,
|
||||||
success_callback,
|
success_callback,
|
||||||
error_callback,
|
error_callback,
|
||||||
) {
|
) {
|
||||||
if (typeof options !== "object") {
|
if (typeof options !== "object") {
|
||||||
error_callback = success_callback;
|
error_callback = success_callback;
|
||||||
success_callback = description;
|
success_callback = description;
|
||||||
@ -134,11 +143,11 @@ greenworks.updatePublishedWorkshopFile = function (
|
|||||||
success_callback,
|
success_callback,
|
||||||
error_callback,
|
error_callback,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// An utility function for publish related APIs.
|
// An utility function for publish related APIs.
|
||||||
// It processes remains steps after saving files to Steam Cloud.
|
// It processes remains steps after saving files to Steam Cloud.
|
||||||
function file_share_process(file_name, image_name, next_process_func, error_callback, progress_callback) {
|
function file_share_process(file_name, image_name, next_process_func, error_callback, progress_callback) {
|
||||||
if (progress_callback) progress_callback("Completed on saving files on Steam Cloud.");
|
if (progress_callback) progress_callback("Completed on saving files on Steam Cloud.");
|
||||||
greenworks.fileShare(
|
greenworks.fileShare(
|
||||||
file_name,
|
file_name,
|
||||||
@ -157,13 +166,13 @@ function file_share_process(file_name, image_name, next_process_func, error_call
|
|||||||
error_process(err, error_callback);
|
error_process(err, error_callback);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publishing user generated content(ugc) to Steam contains following steps:
|
// Publishing user generated content(ugc) to Steam contains following steps:
|
||||||
// 1. Save file and image to Steam Cloud.
|
// 1. Save file and image to Steam Cloud.
|
||||||
// 2. Share the file and image.
|
// 2. Share the file and image.
|
||||||
// 3. publish the file to workshop.
|
// 3. publish the file to workshop.
|
||||||
greenworks.ugcPublish = function (
|
greenworks.ugcPublish = function (
|
||||||
file_name,
|
file_name,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
@ -171,7 +180,7 @@ greenworks.ugcPublish = function (
|
|||||||
success_callback,
|
success_callback,
|
||||||
error_callback,
|
error_callback,
|
||||||
progress_callback,
|
progress_callback,
|
||||||
) {
|
) {
|
||||||
var publish_file_process = function () {
|
var publish_file_process = function () {
|
||||||
if (progress_callback) progress_callback("Completed on sharing files.");
|
if (progress_callback) progress_callback("Completed on sharing files.");
|
||||||
greenworks.publishWorkshopFile(
|
greenworks.publishWorkshopFile(
|
||||||
@ -196,13 +205,13 @@ greenworks.ugcPublish = function (
|
|||||||
error_process(err, error_callback);
|
error_process(err, error_callback);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update publish ugc steps:
|
// Update publish ugc steps:
|
||||||
// 1. Save new file and image to Steam Cloud.
|
// 1. Save new file and image to Steam Cloud.
|
||||||
// 2. Share file and images.
|
// 2. Share file and images.
|
||||||
// 3. Update published file.
|
// 3. Update published file.
|
||||||
greenworks.ugcPublishUpdate = function (
|
greenworks.ugcPublishUpdate = function (
|
||||||
published_file_id,
|
published_file_id,
|
||||||
file_name,
|
file_name,
|
||||||
title,
|
title,
|
||||||
@ -211,7 +220,7 @@ greenworks.ugcPublishUpdate = function (
|
|||||||
success_callback,
|
success_callback,
|
||||||
error_callback,
|
error_callback,
|
||||||
progress_callback,
|
progress_callback,
|
||||||
) {
|
) {
|
||||||
var update_published_file_process = function () {
|
var update_published_file_process = function () {
|
||||||
if (progress_callback) progress_callback("Completed on sharing files.");
|
if (progress_callback) progress_callback("Completed on sharing files.");
|
||||||
greenworks.updatePublishedWorkshopFile(
|
greenworks.updatePublishedWorkshopFile(
|
||||||
@ -238,10 +247,10 @@ greenworks.ugcPublishUpdate = function (
|
|||||||
error_process(err, error_callback);
|
error_process(err, error_callback);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Greenworks Utils APIs implmentation.
|
// Greenworks Utils APIs implmentation.
|
||||||
greenworks.Utils.move = function (source_dir, target_dir, success_callback, error_callback) {
|
greenworks.Utils.move = function (source_dir, target_dir, success_callback, error_callback) {
|
||||||
fs.rename(source_dir, target_dir, function (err) {
|
fs.rename(source_dir, target_dir, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (error_callback) error_callback(err);
|
if (error_callback) error_callback(err);
|
||||||
@ -249,9 +258,9 @@ greenworks.Utils.move = function (source_dir, target_dir, success_callback, erro
|
|||||||
}
|
}
|
||||||
if (success_callback) success_callback();
|
if (success_callback) success_callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
greenworks.init = function () {
|
greenworks.init = function () {
|
||||||
if (this.initAPI()) return true;
|
if (this.initAPI()) return true;
|
||||||
if (!this.isSteamRunning()) throw new Error("Steam initialization failed. Steam is not running.");
|
if (!this.isSteamRunning()) throw new Error("Steam initialization failed. Steam is not running.");
|
||||||
var appId;
|
var appId;
|
||||||
@ -278,16 +287,17 @@ greenworks.init = function () {
|
|||||||
"Maybe that's not really YOUR app ID? " +
|
"Maybe that's not really YOUR app ID? " +
|
||||||
appId.trim(),
|
appId.trim(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
var EventEmitter = require("events").EventEmitter;
|
var EventEmitter = require("events").EventEmitter;
|
||||||
greenworks.__proto__ = EventEmitter.prototype;
|
greenworks.__proto__ = EventEmitter.prototype;
|
||||||
EventEmitter.call(greenworks);
|
EventEmitter.call(greenworks);
|
||||||
|
|
||||||
greenworks._steam_events.on = function () {
|
greenworks._steam_events.on = function () {
|
||||||
greenworks.emit.apply(greenworks, arguments);
|
greenworks.emit.apply(greenworks, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
process.versions["greenworks"] = greenworks._version;
|
process.versions["greenworks"] = greenworks._version;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = greenworks;
|
module.exports = greenworks;
|
||||||
|
@ -25,7 +25,7 @@ process.on("uncaughtException", function () {
|
|||||||
|
|
||||||
// We want to fail gracefully if we cannot connect to Steam
|
// We want to fail gracefully if we cannot connect to Steam
|
||||||
try {
|
try {
|
||||||
if (greenworks.init()) {
|
if (greenworks && greenworks.init()) {
|
||||||
log.info("Steam API has been initialized.");
|
log.info("Steam API has been initialized.");
|
||||||
} else {
|
} else {
|
||||||
const error = "Steam API has failed to initialize.";
|
const error = "Steam API has failed to initialize.";
|
||||||
|
@ -8,6 +8,39 @@ const storage = require("./storage");
|
|||||||
const config = new Config();
|
const config = new Config();
|
||||||
|
|
||||||
function getMenu(window) {
|
function getMenu(window) {
|
||||||
|
const canZoomIn = utils.getZoomFactor() <= 2;
|
||||||
|
const zoomIn = () => {
|
||||||
|
const currentZoom = utils.getZoomFactor();
|
||||||
|
const newZoom = currentZoom + 0.1;
|
||||||
|
if (newZoom <= 2.0) {
|
||||||
|
utils.setZoomFactor(window, newZoom);
|
||||||
|
refreshMenu(window);
|
||||||
|
} else {
|
||||||
|
log.log("Max zoom out");
|
||||||
|
utils.writeToast(window, "Cannot zoom in anymore", "warning");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const canZoomOut = utils.getZoomFactor() >= 0.5;
|
||||||
|
const zoomOut = () => {
|
||||||
|
const currentZoom = utils.getZoomFactor();
|
||||||
|
const newZoom = currentZoom - 0.1;
|
||||||
|
if (newZoom >= 0.5) {
|
||||||
|
utils.setZoomFactor(window, newZoom);
|
||||||
|
refreshMenu(window);
|
||||||
|
} else {
|
||||||
|
log.log("Max zoom in");
|
||||||
|
utils.writeToast(window, "Cannot zoom out anymore", "warning");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const canResetZoom = utils.getZoomFactor() !== 1;
|
||||||
|
const resetZoom = () => {
|
||||||
|
utils.setZoomFactor(window, 1);
|
||||||
|
refreshMenu(window);
|
||||||
|
log.log("Reset zoom");
|
||||||
|
};
|
||||||
|
|
||||||
return Menu.buildFromTemplate([
|
return Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: "File",
|
label: "File",
|
||||||
@ -289,45 +322,45 @@ function getMenu(window) {
|
|||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: "Zoom In",
|
label: "Zoom In",
|
||||||
enabled: utils.getZoomFactor() <= 2,
|
enabled: canZoomIn,
|
||||||
accelerator: "CommandOrControl+numadd",
|
accelerator: "CommandOrControl+numadd",
|
||||||
click: () => {
|
click: zoomIn,
|
||||||
const currentZoom = utils.getZoomFactor();
|
|
||||||
const newZoom = currentZoom + 0.1;
|
|
||||||
if (newZoom <= 2.0) {
|
|
||||||
utils.setZoomFactor(window, newZoom);
|
|
||||||
refreshMenu(window);
|
|
||||||
} else {
|
|
||||||
log.log("Max zoom out");
|
|
||||||
utils.writeToast(window, "Cannot zoom in anymore", "warning");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Zoom In (non numpad)",
|
||||||
|
enabled: canZoomIn,
|
||||||
|
visible: false,
|
||||||
|
accelerator: "CommandOrControl+Plus",
|
||||||
|
acceleratorWorksWhenHidden: true,
|
||||||
|
click: zoomIn,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Zoom Out",
|
label: "Zoom Out",
|
||||||
enabled: utils.getZoomFactor() >= 0.5,
|
enabled: canZoomOut,
|
||||||
accelerator: "CommandOrControl+numsub",
|
accelerator: "CommandOrControl+numsub",
|
||||||
click: () => {
|
click: zoomOut,
|
||||||
const currentZoom = utils.getZoomFactor();
|
|
||||||
const newZoom = currentZoom - 0.1;
|
|
||||||
if (newZoom >= 0.5) {
|
|
||||||
utils.setZoomFactor(window, newZoom);
|
|
||||||
refreshMenu(window);
|
|
||||||
} else {
|
|
||||||
log.log("Max zoom in");
|
|
||||||
utils.writeToast(window, "Cannot zoom out anymore", "warning");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Zoom Out (non numpad)",
|
||||||
|
enabled: canZoomOut,
|
||||||
|
accelerator: "CommandOrControl+-",
|
||||||
|
visible: false,
|
||||||
|
acceleratorWorksWhenHidden: true,
|
||||||
|
click: zoomOut,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Reset Zoom",
|
label: "Reset Zoom",
|
||||||
enabled: utils.getZoomFactor() !== 1,
|
enabled: canResetZoom,
|
||||||
accelerator: "CommandOrControl+num0",
|
accelerator: "CommandOrControl+num0",
|
||||||
click: () => {
|
click: resetZoom,
|
||||||
utils.setZoomFactor(window, 1);
|
|
||||||
refreshMenu(window);
|
|
||||||
log.log("Reset zoom");
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Reset Zoom (non numpad)",
|
||||||
|
enabled: canResetZoom,
|
||||||
|
accelerator: "CommandOrControl+0",
|
||||||
|
visible: false,
|
||||||
|
acceleratorWorksWhenHidden: true,
|
||||||
|
click: resetZoom,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user