Unify error handling

This commit is contained in:
Snarling
2022-08-29 02:41:17 -04:00
parent 5798c4c7d3
commit 572c68738f
23 changed files with 156 additions and 255 deletions
+7 -8
View File
@@ -9,7 +9,6 @@ import { ScriptUrl } from "./ScriptUrl";
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver";
import { roundToTwo } from "../utils/helpers/roundToTwo";
import { IPlayer } from "../PersonObjects/IPlayer";
import { ScriptModule } from "./ScriptModule";
let globalModuleSequenceNumber = 0;
@@ -52,13 +51,13 @@ export class Script {
// hostname of server that this script is on.
server = "";
constructor(player: IPlayer | null = null, fn = "", code = "", server = "", otherScripts: Script[] = []) {
constructor(fn = "", code = "", server = "", otherScripts: Script[] = []) {
this.filename = fn;
this.code = code;
this.server = server; // hostname of server this script is on
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
if (this.code !== "" && player !== null) {
this.updateRamUsage(player, otherScripts);
if (this.code !== "") {
this.updateRamUsage(otherScripts);
}
}
@@ -94,13 +93,13 @@ export class Script {
* @param {string} code - The new contents of the script
* @param {Script[]} otherScripts - Other scripts on the server. Used to process imports
*/
saveScript(player: IPlayer, filename: string, code: string, hostname: string, otherScripts: Script[]): void {
saveScript(filename: string, code: string, hostname: string, otherScripts: Script[]): void {
// Update code and filename
this.code = Script.formatCode(code);
this.filename = filename;
this.server = hostname;
this.updateRamUsage(player, otherScripts);
this.updateRamUsage(otherScripts);
this.markUpdated();
for (const dependent of this.dependents) {
const [dependentScript] = otherScripts.filter(
@@ -114,8 +113,8 @@ export class Script {
* Calculates and updates the script's RAM usage based on its code
* @param {Script[]} otherScripts - Other scripts on the server. Used to process imports
*/
updateRamUsage(player: IPlayer, otherScripts: Script[]): void {
const res = calculateRamUsage(player, this.code, otherScripts);
updateRamUsage(otherScripts: Script[]): void {
const res = calculateRamUsage(this.code, otherScripts);
if (res.cost > 0) {
this.ramUsage = roundToTwo(res.cost);
this.ramUsageEntries = res.entries;