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