Fixed bug and added compatibility for converting RunningScript offline dataMap to version v0.43.1

This commit is contained in:
danielyxie 2019-02-12 01:14:38 -08:00
parent 1d0515a957
commit 08417f250e
7 changed files with 26 additions and 10 deletions

File diff suppressed because one or more lines are too long

@ -22,6 +22,7 @@ import {gameOptionsBoxClose} from "../utils/GameOptions";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {createStatusText} from "./ui/createStatusText";
@ -509,9 +510,11 @@ function loadImportedGame(saveObj, saveString) {
Player.lastUpdate = Engine._lastUpdate;
Engine.start(); //Run main game loop and Scripts loop
dialogBoxCreate("While you were offline, your scripts generated <span class='money-gold'>$" +
numeralWrapper.format(offlineProductionFromScripts, '0,0.00') + "</span> and your Hacknet Nodes generated <span class='money-gold'>$" +
numeralWrapper.format(offlineProductionFromHacknetNodes, '0,0.00') + "</span>");
const timeOfflineString = convertTimeMsToTimeElapsedString(time);
dialogBoxCreate(`Offline for ${timeOfflineString}. While you were offline, your scripts ` +
"generated <span class='money-gold'>" +
numeralWrapper.formatMoney(offlineProductionFromScripts) + "</span> and your Hacknet Nodes generated <span class='money-gold'>" +
numeralWrapper.formatMoney(offlineProductionFromHacknetNodes) + "</span>");
return true;
}

@ -812,6 +812,9 @@ function loadAllRunningScripts() {
}
function scriptCalculateOfflineProduction(runningScriptObj) {
console.log("Calculating offline production for: ");
console.log(runningScriptObj);
//The Player object stores the last update time from when we were online
var thisUpdate = new Date().getTime();
var lastUpdate = Player.lastUpdate;

@ -1905,7 +1905,7 @@ let Terminal = {
}
const scriptname = commandArray[1];
if (!scriptname.endsWith(".lit") && !isScriptFilename(scriptname) && !scriptname.endsWith(".txt")) {
postError("scp only works for .script, .txt, and .lit files");
postError("scp only works for scripts, text files (.txt), and literature files (.lit)");
return;
}
const destServer = getServer(commandArray[2]);

@ -1365,9 +1365,11 @@ const Engine = {
Player.lastUpdate = Engine._lastUpdate;
Engine.start(); //Run main game loop and Scripts loop
removeLoadingScreen();
dialogBoxCreate("While you were offline, your scripts generated <span class='money-gold'>$" +
formatNumber(offlineProductionFromScripts, 2) + "</span> and your Hacknet Nodes generated <span class='money-gold'>$" +
formatNumber(offlineProductionFromHacknetNodes, 2) + "</span>");
const timeOfflineString = convertTimeMsToTimeElapsedString(time);
dialogBoxCreate(`Offline for ${timeOfflineString}. While you were offline, your scripts ` +
"generated <span class='money-gold'>" +
numeralWrapper.formatMoney(offlineProductionFromScripts) + "</span> and your Hacknet Nodes generated <span class='money-gold'>" +
numeralWrapper.formatMoney(offlineProductionFromHacknetNodes) + "</span>");
//Close main menu accordions for loaded game
var visibleMenuTabs = [terminal, createScript, activeScripts, stats,
hacknetnodes, city, tutorial, options, dev];

@ -15,7 +15,15 @@ function Reviver(key, value) {
if (typeof value === "object" &&
typeof value.ctor === "string" &&
typeof value.data !== "undefined") {
// Compatibility for version v0.43.1
// TODO Remove this eventually
if (value.ctor === "AllServersMap") {
console.log('Converting AllServersMap for v0.43.1');
return value.data;
}
ctor = Reviver.constructors[value.ctor] || window[value.ctor];
if (typeof ctor === "function" &&
typeof ctor.fromJSON === "function") {
@ -45,7 +53,7 @@ function Generic_toJSON(ctorName, obj, keys) {
}
data = {};
for (index = 0; index < keys.length; ++index) {
for (let index = 0; index < keys.length; ++index) {
key = keys[index];
data[key] = obj[key];
}