Update all modules, docker image
This commit is contained in:
parent
9dac06627f
commit
d69e0ffa9c
@ -1,4 +1,4 @@
|
||||
FROM node:10-alpine
|
||||
FROM node:14-alpine
|
||||
|
||||
RUN apk add --no-cache --virtual .gyp \
|
||||
python \
|
||||
|
6
Makefile
6
Makefile
@ -3,6 +3,9 @@ all: format build
|
||||
build-docker:
|
||||
docker build -t screeps-node .
|
||||
|
||||
install:
|
||||
tools/npm install
|
||||
|
||||
build:
|
||||
tools/npm run build
|
||||
|
||||
@ -17,3 +20,6 @@ coverage:
|
||||
|
||||
push:
|
||||
tools/npm run push-main
|
||||
|
||||
push-sim:
|
||||
tools/npm run push-sim
|
||||
|
37
package.json
37
package.json
@ -32,35 +32,34 @@
|
||||
"node": "10.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^11.1.0",
|
||||
"@rollup/plugin-multi-entry": "^3.0.0",
|
||||
"@rollup/plugin-node-resolve": "^7.1.3",
|
||||
"@rollup/plugin-buble": "^0.21.3",
|
||||
"@rollup/plugin-commonjs": "^20.0.0",
|
||||
"@rollup/plugin-multi-entry": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.0.4",
|
||||
"@types/chai": "^4.1.6",
|
||||
"@types/lodash": "3.10.2",
|
||||
"@types/mocha": "^5.2.5",
|
||||
"@types/node": "^13.13.14",
|
||||
"@types/lodash": "^4.14.172",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "^16.6.1",
|
||||
"@types/screeps": "^3.1.3",
|
||||
"@types/sinon": "^5.0.5",
|
||||
"@types/sinon": "^10.0.2",
|
||||
"@types/sinon-chai": "^3.2.0",
|
||||
"chai": "^4.2.0",
|
||||
"lodash": "^3.10.1",
|
||||
"mocha": "^5.2.0",
|
||||
"prettier": "^2.0.4",
|
||||
"rollup": "^2.22.1",
|
||||
"rollup-plugin-buble": "^0.19.8",
|
||||
"lodash": "^4.17.21",
|
||||
"mocha": "^9.0.3",
|
||||
"prettier": "^2.3.2",
|
||||
"rollup": "^2.56.2",
|
||||
"rollup-plugin-clear": "^2.0.7",
|
||||
"rollup-plugin-nodent": "^0.2.2",
|
||||
"rollup-plugin-screeps": "^1.0.1",
|
||||
"rollup-plugin-typescript2": "^0.27.0",
|
||||
"sinon": "^6.3.5",
|
||||
"rollup-plugin-typescript2": "^0.30.0",
|
||||
"sinon": "^11.1.2",
|
||||
"sinon-chai": "^3.2.0",
|
||||
"ts-node": "^8.8.2",
|
||||
"source-map": "^0.7.3",
|
||||
"ts-node": "^10.2.0",
|
||||
"tslint": "^6.1.1",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"tslint-plugin-prettier": "^2.3.0",
|
||||
"typescript": "^3.9.7"
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"source-map": "~0.6.1"
|
||||
}
|
||||
"dependencies": {}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import * as _ from 'lodash';
|
||||
import { harvestEnergyFromTombstone, selectSource } from './common';
|
||||
|
||||
interface BuilderMemory extends CreepMemory {
|
||||
|
21
src/main.ts
21
src/main.ts
@ -4,6 +4,7 @@ import { runAsBuilder } from './creep/builder';
|
||||
import { runAsUpgrader } from './creep/upgrader';
|
||||
import { uniqId } from './utils/Identity';
|
||||
import { runTower } from './tower';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
// When compiling TS to JS and bundling with rollup, the line numbers and file names in error messages change
|
||||
// This utility uses source maps to get the line numbers and file names of the original, TS source code
|
||||
@ -79,15 +80,17 @@ function makeCreep(role: CreepRole, count: number) {
|
||||
console.log(`Make creep "${role}"`, 'need', count, 'has', creeps.length);
|
||||
if (creeps.length < count) {
|
||||
const firstSpawn = _.first(Object.values(Game.spawns));
|
||||
const capacity = firstSpawn.room.energyCapacityAvailable;
|
||||
const body = selectBody(capacity);
|
||||
const name = makeName();
|
||||
const memory = { role: role, sourceId: '' } as CreepMemory;
|
||||
const err = firstSpawn.spawnCreep(body, name, {
|
||||
memory,
|
||||
directions: [BOTTOM, BOTTOM_RIGHT, RIGHT, BOTTOM_LEFT, LEFT]
|
||||
});
|
||||
console.log(`Make creep "${role}"`, 'body', calcBodyCost(body), 'err', err);
|
||||
if (firstSpawn !== undefined) {
|
||||
const capacity = firstSpawn.room.energyCapacityAvailable;
|
||||
const body = selectBody(capacity);
|
||||
const name = makeName();
|
||||
const memory = { role: role, sourceId: '' } as CreepMemory;
|
||||
const err = firstSpawn.spawnCreep(body, name, {
|
||||
memory,
|
||||
directions: [BOTTOM, BOTTOM_RIGHT, RIGHT, BOTTOM_LEFT, LEFT]
|
||||
});
|
||||
console.log(`Make creep "${role}"`, 'body', calcBodyCost(body), 'err', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
42
src/tower.ts
42
src/tower.ts
@ -1,23 +1,29 @@
|
||||
import * as _ from 'lodash';
|
||||
|
||||
const REPAIR_ENERGY_LIMIT = 500;
|
||||
|
||||
export function runTower(tower: StructureTower) {
|
||||
const room = tower.room;
|
||||
const hostiles = room.find(FIND_HOSTILE_CREEPS);
|
||||
if (hostiles.length > 0) {
|
||||
const hostile = _.min(hostiles, (h) => h.hits);
|
||||
const res = tower.attack(hostile);
|
||||
console.log('Attack', res);
|
||||
return;
|
||||
const hostile = _.minBy(hostiles, (h) => h.hits);
|
||||
if (hostile !== undefined) {
|
||||
const res = tower.attack(hostile);
|
||||
console.log('Attack', res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const creeps = room.find(FIND_MY_CREEPS, {
|
||||
filter: (c) => c.hits < c.hitsMax
|
||||
});
|
||||
if (creeps.length > 0) {
|
||||
const creep = _.min(creeps, (c) => c.hits);
|
||||
const res = tower.heal(creep);
|
||||
console.log('Heal', res);
|
||||
return;
|
||||
const creep = _.minBy(creeps, (c) => c.hits);
|
||||
if (creep !== undefined) {
|
||||
const res = tower.heal(creep);
|
||||
console.log('Heal', res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Energy only for attack and heal
|
||||
@ -29,19 +35,23 @@ export function runTower(tower: StructureTower) {
|
||||
filter: (s) => s.structureType === STRUCTURE_ROAD && s.hits < s.hitsMax
|
||||
});
|
||||
if (roads.length > 0) {
|
||||
const road = _.min(roads, (r) => r.hits);
|
||||
const res = tower.repair(road);
|
||||
console.log('Repair', res);
|
||||
return;
|
||||
const road = _.minBy(roads, (r) => r.hits);
|
||||
if (road !== undefined) {
|
||||
const res = tower.repair(road);
|
||||
console.log('Repair', res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const structures = room.find(FIND_STRUCTURES, {
|
||||
filter: (s) => s.hits < s.hitsMax
|
||||
});
|
||||
if (structures.length > 0) {
|
||||
const structure = _.min(structures, (s) => s.hits);
|
||||
const res = tower.repair(structure);
|
||||
console.log('Repair', res);
|
||||
return;
|
||||
const structure = _.minBy(structures, (s) => s.hits);
|
||||
if (structure !== undefined) {
|
||||
const res = tower.repair(structure);
|
||||
console.log('Repair', res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
// tslint:disable:no-conditional-assignment
|
||||
import { SourceMapConsumer } from 'source-map';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export class ErrorMapper {
|
||||
// Cache consumer
|
||||
private static _consumer?: SourceMapConsumer;
|
||||
|
||||
public static get consumer(): SourceMapConsumer {
|
||||
if (this._consumer == null) {
|
||||
this._consumer = new SourceMapConsumer(require('main.js.map'));
|
||||
public static async consumer(): Promise<SourceMapConsumer> {
|
||||
if (this._consumer === undefined) {
|
||||
this._consumer = await new SourceMapConsumer(require('main.js.map'));
|
||||
}
|
||||
|
||||
return this._consumer;
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ export class ErrorMapper {
|
||||
* @param {Error | string} error The error or original stack trace
|
||||
* @returns {string} The source-mapped stack trace
|
||||
*/
|
||||
public static sourceMappedStackTrace(error: Error | string): string {
|
||||
public static async sourceMappedStackTrace(error: Error | string): Promise<string> {
|
||||
const stack: string = error instanceof Error ? (error.stack as string) : error;
|
||||
if (this.cache.hasOwnProperty(stack)) {
|
||||
return this.cache[stack];
|
||||
@ -37,7 +37,8 @@ export class ErrorMapper {
|
||||
|
||||
while ((match = re.exec(stack))) {
|
||||
if (match[2] === 'main') {
|
||||
const pos = this.consumer.originalPositionFor({
|
||||
const consumer = await this.consumer();
|
||||
const pos = consumer.originalPositionFor({
|
||||
column: parseInt(match[4], 10),
|
||||
line: parseInt(match[3], 10)
|
||||
});
|
||||
@ -78,7 +79,9 @@ export class ErrorMapper {
|
||||
const message = `Source maps don't work in the simulator - displaying original error`;
|
||||
console.log(`<span style='color:red'>${message}<br>${_.escape(e.stack)}</span>`);
|
||||
} else {
|
||||
console.log(`<span style='color:red'>${_.escape(this.sourceMappedStackTrace(e))}</span>`);
|
||||
this.sourceMappedStackTrace(e).then((s) => {
|
||||
console.log(`<span style='color:red'>${_.escape(s)}</span>`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// can't handle it
|
||||
|
Loading…
Reference in New Issue
Block a user