added logic to add cmd/ctrl and +, cmd/ctrl and - cmd/ctrl and 0

* added logic to atleast allow arm64 to launch due to steam incopatibility
This commit is contained in:
phyzical 2022-04-02 23:04:48 +08:00
parent acfd164927
commit 6f09720393
3 changed files with 231 additions and 195 deletions

@ -29,7 +29,8 @@ function error_process(err, error_callback) {
error_callback(err); error_callback(err);
} }
greenworks.ugcGetItems = function(options, ugc_matching_type, ugc_query_type, if (greenworks) {
greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type,
success_callback, error_callback) { success_callback, error_callback) {
if (typeof options !== 'object') { if (typeof options !== 'object') {
error_callback = success_callback; error_callback = success_callback;
@ -43,9 +44,9 @@ greenworks.ugcGetItems = function(options, ugc_matching_type, ugc_query_type,
} }
greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type,
success_callback, error_callback); success_callback, error_callback);
} }
greenworks.ugcGetUserItems = function(options, ugc_matching_type, greenworks.ugcGetUserItems = function (options, ugc_matching_type,
ugc_list_sort_order, ugc_list, success_callback, error_callback) { ugc_list_sort_order, ugc_list, success_callback, error_callback) {
if (typeof options !== 'object') { if (typeof options !== 'object') {
error_callback = success_callback; error_callback = success_callback;
@ -60,9 +61,9 @@ greenworks.ugcGetUserItems = function(options, ugc_matching_type,
} }
greenworks._ugcGetUserItems(options, ugc_matching_type, ugc_list_sort_order, greenworks._ugcGetUserItems(options, ugc_matching_type, ugc_list_sort_order,
ugc_list, success_callback, error_callback); ugc_list, success_callback, error_callback);
} }
greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback,
error_callback) { error_callback) {
if (typeof options !== 'object') { if (typeof options !== 'object') {
error_callback = success_callback; error_callback = success_callback;
@ -75,9 +76,9 @@ greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback,
} }
greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, greenworks._ugcSynchronizeItems(options, sync_dir, success_callback,
error_callback); error_callback);
} }
greenworks.publishWorkshopFile = function(options, file_path, image_path, title, greenworks.publishWorkshopFile = function (options, file_path, image_path, title,
description, success_callback, error_callback) { description, success_callback, error_callback) {
if (typeof options !== 'object') { if (typeof options !== 'object') {
error_callback = success_callback; error_callback = success_callback;
@ -93,9 +94,9 @@ greenworks.publishWorkshopFile = function(options, file_path, image_path, title,
} }
greenworks._publishWorkshopFile(options, file_path, image_path, title, greenworks._publishWorkshopFile(options, file_path, image_path, title,
description, success_callback, error_callback); description, success_callback, error_callback);
} }
greenworks.updatePublishedWorkshopFile = function(options, greenworks.updatePublishedWorkshopFile = function (options,
published_file_handle, file_path, image_path, title, description, published_file_handle, file_path, image_path, title, description,
success_callback, error_callback) { success_callback, error_callback) {
if (typeof options !== 'object') { if (typeof options !== 'object') {
@ -113,66 +114,66 @@ greenworks.updatePublishedWorkshopFile = function(options,
greenworks._updatePublishedWorkshopFile(options, published_file_handle, greenworks._updatePublishedWorkshopFile(options, published_file_handle,
file_path, image_path, title, description, success_callback, file_path, image_path, title, description, 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, function file_share_process(file_name, image_name, next_process_func,
error_callback, progress_callback) { error_callback, progress_callback) {
if (progress_callback) if (progress_callback)
progress_callback("Completed on saving files on Steam Cloud."); progress_callback("Completed on saving files on Steam Cloud.");
greenworks.fileShare(file_name, function() { greenworks.fileShare(file_name, function () {
greenworks.fileShare(image_name, function() { greenworks.fileShare(image_name, function () {
next_process_func(); next_process_func();
}, function(err) { error_process(err, error_callback); }); }, function (err) { error_process(err, error_callback); });
}, function(err) { error_process(err, error_callback); }); }, function (err) { 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(file_name, title, description, image_name, greenworks.ugcPublish = function (file_name, title, description, image_name,
success_callback, error_callback, progress_callback) { success_callback, error_callback, progress_callback) {
var publish_file_process = function() { var publish_file_process = function () {
if (progress_callback) if (progress_callback)
progress_callback("Completed on sharing files."); progress_callback("Completed on sharing files.");
greenworks.publishWorkshopFile(file_name, image_name, title, description, greenworks.publishWorkshopFile(file_name, image_name, title, description,
function(publish_file_id) { success_callback(publish_file_id); }, function (publish_file_id) { success_callback(publish_file_id); },
function(err) { error_process(err, error_callback); }); function (err) { error_process(err, error_callback); });
}; };
greenworks.saveFilesToCloud([file_name, image_name], function() { greenworks.saveFilesToCloud([file_name, image_name], function () {
file_share_process(file_name, image_name, publish_file_process, file_share_process(file_name, image_name, publish_file_process,
error_callback, progress_callback); error_callback, progress_callback);
}, function(err) { error_process(err, error_callback); }); }, function (err) { 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(published_file_id, file_name, title, greenworks.ugcPublishUpdate = function (published_file_id, file_name, title,
description, image_name, success_callback, error_callback, description, image_name, success_callback, error_callback,
progress_callback) { progress_callback) {
var update_published_file_process = function() { var update_published_file_process = function () {
if (progress_callback) if (progress_callback)
progress_callback("Completed on sharing files."); progress_callback("Completed on sharing files.");
greenworks.updatePublishedWorkshopFile(published_file_id, greenworks.updatePublishedWorkshopFile(published_file_id,
file_name, image_name, title, description, file_name, image_name, title, description,
function() { success_callback(); }, function () { success_callback(); },
function(err) { error_process(err, error_callback); }); function (err) { error_process(err, error_callback); });
}; };
greenworks.saveFilesToCloud([file_name, image_name], function() { greenworks.saveFilesToCloud([file_name, image_name], function () {
file_share_process(file_name, image_name, update_published_file_process, file_share_process(file_name, image_name, update_published_file_process,
error_callback, progress_callback); error_callback, progress_callback);
}, function(err) { error_process(err, error_callback); }); }, function (err) { error_process(err, error_callback); });
} }
// Greenworks Utils APIs implmentation. // Greenworks Utils APIs implmentation.
greenworks.Utils.move = function(source_dir, target_dir, success_callback, greenworks.Utils.move = function (source_dir, target_dir, success_callback,
error_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);
return; return;
@ -180,9 +181,9 @@ greenworks.Utils.move = function(source_dir, target_dir, success_callback,
if (success_callback) if (success_callback)
success_callback(); success_callback();
}); });
} }
greenworks.init = function() { greenworks.init = function () {
if (this.initAPI()) return true; if (this.initAPI()) return true;
if (!this.isSteamRunning()) if (!this.isSteamRunning())
throw new Error("Steam initialization failed. Steam is not running."); throw new Error("Steam initialization failed. Steam is not running.");
@ -202,16 +203,17 @@ greenworks.init = function() {
throw new Error("Steam initialization failed, but Steam is running, " + throw new Error("Steam initialization failed, but Steam is running, " +
"and steam_appid.txt is present and valid." + "and steam_appid.txt is present and valid." +
"Maybe that's not really YOUR app ID? " + appId.trim()); "Maybe that's not really YOUR app ID? " + appId.trim());
}
var EventEmitter = require('events').EventEmitter;
greenworks.__proto__ = EventEmitter.prototype;
EventEmitter.call(greenworks);
greenworks._steam_events.on = function () {
greenworks.emit.apply(greenworks, arguments);
};
process.versions['greenworks'] = greenworks._version;
} }
var EventEmitter = require('events').EventEmitter;
greenworks.__proto__ = EventEmitter.prototype;
EventEmitter.call(greenworks);
greenworks._steam_events.on = function () {
greenworks.emit.apply(greenworks, arguments);
};
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.";
@ -149,7 +149,7 @@ function setStopProcessHandler(app, window, enabled) {
} }
const { save, ...other } = arg; const { save, ...other } = arg;
log.silly("Received game saved info", {...other, save: `${save.length} bytes`}); log.silly("Received game saved info", { ...other, save: `${save.length} bytes` });
if (storage.isAutosaveEnabled()) { if (storage.isAutosaveEnabled()) {
saveToDisk(save, arg.fileName); saveToDisk(save, arg.fileName);

@ -8,6 +8,40 @@ 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",
@ -268,7 +302,7 @@ function getMenu(window) {
defaultId: 0, defaultId: 0,
cancelId: 0, cancelId: 0,
noLink: true, noLink: true,
}).then(({response}) => { }).then(({ response }) => {
if (response === 1) { if (response === 1) {
utils.openExternal('https://github.com/bitburner-official/bitburner-vscode'); utils.openExternal('https://github.com/bitburner-official/bitburner-vscode');
} }
@ -282,45 +316,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,
}, },
], ],
}, },