本文整理匯總了TypeScript中utils/ErrorMapper.ErrorMapper類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ErrorMapper類的具體用法?TypeScript ErrorMapper怎麽用?TypeScript ErrorMapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ErrorMapper類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: RoomManager
import { ErrorMapper } from "utils/ErrorMapper";
import {HarvesterRole} from "roles/harvester"
import {RoomManager} from "roomManager"
import { UpgraderRole } from "roles/upgrader";
import {BuilderRole} from "roles/builder";
var firstRoomName = Object.keys(Game.rooms)[0];
var roomManager = new RoomManager(firstRoomName, new HarvesterRole(), new BuilderRole(), new UpgraderRole());
// 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
export const loop = ErrorMapper.wrapLoop(() => {
roomManager.run();
});
示例2:
import { ErrorMapper } from "utils/ErrorMapper";
// 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
export const loop = ErrorMapper.wrapLoop(() => {
console.log(`Current game tick is ${Game.time}`);
// Automatically delete memory of missing creeps
for (const name in Memory.creeps) {
if (!(name in Game.creeps)) {
delete Memory.creeps[name];
}
}
});
示例3: setupMem
import {RoomState, RoomType} from "shared";
import "source";
import "structures/structure";
import "tombstone";
// 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
export const loop = ErrorMapper.wrapLoop(() => {
setupMem();
clearMem();
const pct = Game.gcl.progress / Game.gcl.progressTotal * 100;
const pctStr = pct.toFixed(1);
if (Memory.vars.lastPct != pctStr) {
console.log(`GCL Progress: ${pctStr}%`);
Memory.vars.lastPct = pctStr;
}
const rooms = Memory.config.rooms.map((name) => Game.rooms[name]).filter((r) => r != null);
rooms.sort((r) => r.energyAvailable).reverse();
for (const room of rooms) {
room.run();
}
_.forOwn(Game.creeps, (creep) => {
creep.run();
});
});
export const setupMem = () => {
if (Memory.testing == null) {
Memory.testing = false;
}
if (Memory.vars == null) {
Memory.vars = {};
示例4: programClearMemory
import { ErrorMapper } from "utils/ErrorMapper";
import { programClearMemory } from "programs/program.ClearMemory";
import { programSpawnCreep } from "programs/program.SpawnCreep";
import { programMapActions } from "programs/program.MapActions";
import { programInitializeRoomMemory } from "programs/program.InitializeRoomMemory";
import { programTowerDefense } from "programs/program.TowerDefense";
// 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
export const loop = ErrorMapper.wrapLoop(() => {
//console.log(`Current game tick is ${Game.time}`);
let clearMemory: programClearMemory = new programClearMemory();
let spawnCreep: programSpawnCreep = new programSpawnCreep();
let mapActions: programMapActions = new programMapActions();
let towerDefense: programTowerDefense = new programTowerDefense();
let initializeRoomMemory: programInitializeRoomMemory = new programInitializeRoomMemory();
initializeRoomMemory.Run();
clearMemory.Run();
spawnCreep.Run();
mapActions.Run();
towerDefense.Run();
});
示例5: Neuralyzer
import { ErrorMapper } from "utils/ErrorMapper";
import { Neuralyzer } from "utils/Neuralyzer";
import Runtime from "Runtime";
// 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
export const loop = ErrorMapper.wrapLoop(() => {
console.log(`Current game tick is ${Game.time}`);
Neuralyzer();
Runtime.loop();
});
示例6: if
export const loop = ErrorMapper.wrapLoop(() => {
profiler.wrap(() => {
utilityFunctions.respawn();
utilityFunctions.clearDeadCreepMemory();
utilityFunctions.clearMissingFlagMemory();
// cleanup dead claimer
if (Memory.claimerName && !Game.creeps[Memory.claimerName]) {
Memory.claimerName = undefined;
}
// cleanup dead colonists
for (const name in Memory.colonistNames) {
if (!Game.creeps[name]) {
delete Memory.colonistNames[name];
}
}
// count my rooms (used for determining if I can expand)
const myRooms = _.filter(Game.rooms, { controller: { my: true}});
const myRoomCount = _.size(myRooms);
towerFunctions.runTowerLogic();
// Number of creeps that should exist for a given role. May vary by RCL.
const creepRoleCountsByRcl = {
rcl1: {
builder: 2,
courier: 3,
upgrader: 3
},
rcl4: {
builder: 1,
courier: 2,
upgrader: 1
}
};
for (const roomName in Game.rooms) {
const room = Game.rooms[roomName];
roomFunctions.checkForSources(room);
// if there is a newClaim in one of my rooms, delete it and replace
// it with a newColony if there is not already a newColony.
const claimFlag = Game.flags[roleClaimer.newClaimFlagName];
if (claimFlag &&
!Game.flags[roleColonist.newColonyFlagName] &&
Game.rooms[claimFlag.pos.roomName] &&
Game.rooms[claimFlag.pos.roomName].controller &&
Game.rooms[claimFlag.pos.roomName].controller!.my) {
// replace newClaim with newColony in the same position
claimFlag.pos.createFlag(roleColonist.newColonyFlagName, COLOR_PURPLE);
claimFlag.remove();
}
// handle a new colony. Decides to build a spawn in,
// abandon, or finish a colony.
const colonyFlag = Game.flags[roleColonist.newColonyFlagName];
if (colonyFlag) {
if (!colonyFlag.room!.controller!.my) {
// If the colony is in a room that is not mine, abandon it.
console.log("Colony room not owned by me. Abandoning colony: " + colonyFlag.room!.name);
Memory.colonySpawnSiteID = undefined;
colonyFlag.remove();
} else if (!Memory.colonySpawnSiteID) {
// If the spawn constructionSite is not in memory, get it.
colonyFlag.pos.createConstructionSite(STRUCTURE_SPAWN);
const colonySpawnSites = colonyFlag.room!.find(FIND_MY_CONSTRUCTION_SITES, {
filter: (constructionSite) => constructionSite.structureType === STRUCTURE_SPAWN
});
if (colonySpawnSites.length && colonySpawnSites[0].id) {
Memory.colonySpawnSiteID = colonySpawnSites[0].id;
}
} else if (Memory.colonySpawnSiteID && !Game.getObjectById(Memory.colonySpawnSiteID)) {
// If we can't find the spawn constructionSite, it either finished
// or was destroyed. Either way, delete the colony flag.
console.log("Colony spawn finished/destroyed. removing colony flag in: " + colonyFlag.room!.name);
Memory.colonySpawnSiteID = undefined;
colonyFlag.remove();
}
}
const creepsOfRole: any = {};
for (const roleName in roles) {
creepsOfRole[roleName] = {};
}
const roomCreeps = room.find(FIND_MY_CREEPS);
for (const creepIndex in roomCreeps) {
const creep = roomCreeps[creepIndex];
if (roles[creep.memory.role]) {
creepsOfRole[creep.memory.role][creep.name] = creep.id;
roles[creep.memory.role].run(creep);
}
}
if (room.controller && room.controller.my) {
//.........這裏部分代碼省略.........