Minor improvements and fixes
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/screepers/screeps-typescript-starter#readme",
|
"homepage": "https://github.com/screepers/screeps-typescript-starter#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash": "^4.14.85",
|
"@types/lodash": "^3.10.1",
|
||||||
"@types/source-map": "^0.5.2",
|
"@types/source-map": "^0.5.2",
|
||||||
"rollup": "^0.51.8",
|
"rollup": "^0.51.8",
|
||||||
"rollup-plugin-clean": "^1.0.0",
|
"rollup-plugin-clean": "^1.0.0",
|
||||||
|
|||||||
22
src/main.ts
22
src/main.ts
@@ -1,16 +1,14 @@
|
|||||||
import { ErrorMapper } from "utils/ErrorMapper";
|
import { ErrorMapper } from "utils/ErrorMapper";
|
||||||
|
|
||||||
export function loop() {
|
// When compiling TS to JS and bundling with rollup, the line numbers and file names in error messages change
|
||||||
try {
|
// This utility uses source maps to get the line numbers and file names of the original, TS source code
|
||||||
// Clear non-existing creep memory.
|
export const loop = ErrorMapper.wrapLoop(function() {
|
||||||
for (const name in Memory.creeps) {
|
console.log(`Current game tick is ${Game.time}`);
|
||||||
if (!Game.creeps[name]) {
|
|
||||||
delete Memory[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Current tick is ${Game.time}`);
|
// Automatically delete memory of missing creeps
|
||||||
} catch (e) {
|
for (let name in Memory.creeps) {
|
||||||
console.log(ErrorMapper.sourceMappedStackTrace(e));
|
if (!(name in Game.creeps)) {
|
||||||
|
delete Memory.creeps[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -67,4 +67,23 @@ export class ErrorMapper {
|
|||||||
this.cache[stack] = outStack;
|
this.cache[stack] = outStack;
|
||||||
return outStack;
|
return outStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static wrapLoop(loop: () => void): () => void {
|
||||||
|
return () => {
|
||||||
|
try {
|
||||||
|
loop();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("sim" in Game.rooms) {
|
||||||
|
console.log(`<span style='color:red'>Source maps don't work in the simulator - displaying original error<br>${_.escape(e.stack)}</span>`)
|
||||||
|
} else {
|
||||||
|
console.log(`<span style='color:red'>${_.escape(this.sourceMappedStackTrace(e))}</span>`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// can't handle it
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user