Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: release a new patch version v3.3.1 to rollback breaking change on v3.3.0 #226

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.3.1] - 2023-02-16

### Fixed

- Fix: brings removed `Game.getObjectById(id: string)` back to avoid breaking changes. ([#226](https://github.com/screepers/typed-screeps/pull/226))

## [3.3.0] - 2022-04-18

### Updated

- Updates `ticksToRegeneration` to be optional in `Minerals` ([#204](https://github.com/screepers/typed-screeps/pull/204))
- Updates `level` to be optional in `StructureFactory` ([#205](https://github.com/screepers/typed-screeps/pull/205))
- Updates `Id` type to only be used on types with an `id` property ([#207](https://github.com/screepers/typed-screeps/pull/207))

### Removed

- Removes deprecated `Game.getObjectById(id: string)` function. Use version with `Id<T>` typed ids. ([#207](https://github.com/screepers/typed-screeps/pull/207))

## [3.2.4] - 2021-08-21
Expand Down Expand Up @@ -356,7 +369,9 @@ This version was pushed by DefinitelyTyped maintainers, not present in this repo

- Initial public `npm` release.

[unreleased]: https://github.com/screepers/typed-screeps/compare/v3.2.4...HEAD
[unreleased]: https://github.com/screepers/typed-screeps/compare/v3.3.1...HEAD
[3.3.1]: https://github.com/screepers/typed-screeps/compare/v3.3.0...v3.3.1
[3.3.0]: https://github.com/screepers/typed-screeps/compare/v3.2.4...v3.3.0
[3.2.4]: https://github.com/screepers/typed-screeps/compare/v3.2.2...v3.2.4
[3.2.2]: https://github.com/screepers/typed-screeps/compare/v3.2.1...v3.2.2
[3.2.1]: https://github.com/screepers/typed-screeps/compare/v3.2.0...v3.2.1
Expand Down
11 changes: 10 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for Screeps 3.3.0
// Type definitions for Screeps 3.3.1
// Project: https://github.com/screeps/screeps
// Definitions by: Marko Sulamägi <https://github.com/MarkoSulamagi>
// Nhan Ho <https://github.com/NhanHo>
Expand Down Expand Up @@ -1570,6 +1570,15 @@ interface Game {
getObjectById<T extends Id<_HasId>>(id: T): fromId<T> | null;
getObjectById<T extends _HasId>(id: Id<T>): T | null;

/**
* Get an object with the specified unique ID. It may be a game object of any type. Only objects from the rooms which are visible to you can be accessed.
* @param id The unique identifier.
* @returns an object instance or null if it cannot be found.
* @deprecated Use Id<T>, instead of strings, to increase type safety
*/
// tslint:disable-next-line:unified-signatures
getObjectById<T extends _HasId>(id: string): T | null;

/**
* Send a custom message at your profile email.
*
Expand Down
61 changes: 30 additions & 31 deletions dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function resources(o: GenericStore): ResourceConstant[] {
} else {
// Boost resource
const targetSource = Game.getObjectById("targetSourceID" as Id<Source>)!;
const sourceEffect = targetSource.effects.find(effect => effect.effect === PWR_REGEN_SOURCE && effect.level > 0);
const sourceEffect = targetSource.effects.find((effect) => effect.effect === PWR_REGEN_SOURCE && effect.level > 0);
if (!sourceEffect && powerCreep.powers[PWR_REGEN_SOURCE] && powerCreep.powers[PWR_REGEN_SOURCE].cooldown === 0) {
powerCreep.usePower(PWR_REGEN_SOURCE, targetSource);
}
Expand Down Expand Up @@ -237,7 +237,7 @@ function resources(o: GenericStore): ResourceConstant[] {
{
const exits = Game.map.describeExits("W8N3");
// tslint:disable-next-line:newline-per-chained-call
keys(exits).map(exitKey => {
keys(exits).map((exitKey) => {
const nextRoom = exits[exitKey];
const exitDir = +exitKey as ExitConstant;
const exitPos = creep.pos.findClosestByRange(exitDir);
Expand Down Expand Up @@ -315,14 +315,14 @@ function resources(o: GenericStore): ResourceConstant[] {
});

if (route !== ERR_NO_PATH) {
route.forEach(info => {
route.forEach((info) => {
allowedRooms[info.room] = true;
});
}

// Invoke PathFinder, allowing access only to rooms from `findRoute`
const ret = PathFinder.search(from, [to], {
roomCallback: roomName => {
roomCallback: (roomName) => {
if (allowedRooms[roomName] === undefined) {
return false;
} else {
Expand Down Expand Up @@ -405,7 +405,7 @@ function resources(o: GenericStore): ResourceConstant[] {

const targetRoom = "W1N1";
Game.market.getAllOrders(
currentOrder =>
(currentOrder) =>
currentOrder.resourceType === RESOURCE_GHODIUM &&
currentOrder.type === ORDER_SELL &&
Game.market.calcTransactionCost(1000, targetRoom, currentOrder.roomName!) < 500,
Expand Down Expand Up @@ -435,7 +435,7 @@ function resources(o: GenericStore): ResourceConstant[] {
const pfCreep = Game.creeps.John;

// tslint:disable-next-line:newline-per-chained-call
const goals = pfCreep.room.find(FIND_SOURCES).map(source => {
const goals = pfCreep.room.find(FIND_SOURCES).map((source) => {
// We can't actually walk on sources-- set `range` to 1
// so we path next to it.
return { pos: source.pos, range: 1 };
Expand All @@ -458,7 +458,7 @@ function resources(o: GenericStore): ResourceConstant[] {
const costs = new PathFinder.CostMatrix();

// tslint:disable-next-line:newline-per-chained-call
curRoom.find(FIND_STRUCTURES).forEach(struct => {
curRoom.find(FIND_STRUCTURES).forEach((struct) => {
if (struct.structureType === STRUCTURE_ROAD) {
// Favor roads over plain tiles
costs.set(struct.pos.x, struct.pos.y, 1);
Expand All @@ -473,7 +473,7 @@ function resources(o: GenericStore): ResourceConstant[] {

// Avoid creeps in the room
// tslint:disable-next-line:newline-per-chained-call
curRoom.find(FIND_CREEPS).forEach(thisCreep => {
curRoom.find(FIND_CREEPS).forEach((thisCreep) => {
costs.set(thisCreep.pos.x, thisCreep.pos.y, 0xff);
});

Expand Down Expand Up @@ -588,7 +588,7 @@ function resources(o: GenericStore): ResourceConstant[] {
creepsHere[0].getActiveBodyparts(ATTACK);

const towers = room.find<StructureTower>(FIND_MY_STRUCTURES, {
filter: structure => {
filter: (structure) => {
return structure.structureType === STRUCTURE_TOWER;
},
});
Expand Down Expand Up @@ -622,7 +622,7 @@ function resources(o: GenericStore): ResourceConstant[] {
}

const tower = creep.pos.findClosestByPath<StructureTower>(FIND_HOSTILE_STRUCTURES, {
filter: structure => {
filter: (structure) => {
return structure.structureType === STRUCTURE_TOWER;
},
algorithm: "astar",
Expand All @@ -635,7 +635,7 @@ function resources(o: GenericStore): ResourceConstant[] {
// Generic type predicate filter
const isStructureType = <T extends StructureConstant, S extends ConcreteStructure<T>>(structureType: T) => {
return (structure: AnyStructure): structure is S => {
return structure.structureType === structureType as string;
return structure.structureType === (structureType as string);
};
};

Expand All @@ -648,14 +648,17 @@ function resources(o: GenericStore): ResourceConstant[] {
tower2.attack(powerCreep);
}

const creepWithEnergy = creep.pos.findClosestByPath(creep.room.find(FIND_CREEPS), { filter: c => c.store.energy > 0 });
const creepWithEnergy = creep.pos.findClosestByPath(creep.room.find(FIND_CREEPS), { filter: (c) => c.store.energy > 0 });

const creepAbove = creep.pos.findClosestByPath(creep.room.find(FIND_CREEPS).map(c => c.pos), {
filter: p => p.getDirectionTo(creep) === TOP,
});
const creepAbove = creep.pos.findClosestByPath(
creep.room.find(FIND_CREEPS).map((c) => c.pos),
{
filter: (p) => p.getDirectionTo(creep) === TOP,
},
);

const rampart = creep.pos.findClosestByRange<StructureRampart>(FIND_HOSTILE_STRUCTURES, {
filter: structure => {
filter: (structure) => {
return structure.structureType === STRUCTURE_RAMPART;
},
});
Expand All @@ -668,7 +671,7 @@ function resources(o: GenericStore): ResourceConstant[] {
hostileCreeps[0].saying;

const labs = creep.pos.findInRange<StructureLab>(FIND_MY_STRUCTURES, 4, {
filter: structure => {
filter: (structure) => {
return structure.structureType === STRUCTURE_LAB;
},
});
Expand All @@ -686,7 +689,7 @@ function resources(o: GenericStore): ResourceConstant[] {
const pos = new RoomPosition(+x, +y, room.name);
const objects = row[x as unknown as number];
if (objects.length > 0) {
objects.map(o => o.type);
objects.map((o) => o.type);
}
}
}
Expand Down Expand Up @@ -742,7 +745,7 @@ function resources(o: GenericStore): ResourceConstant[] {
owned.notifyWhenAttacked(false);

const structs = room.find(FIND_MY_STRUCTURES);
structs.forEach(struct => {
structs.forEach((struct) => {
switch (struct.structureType) {
case STRUCTURE_CONTROLLER:
const usernameOptional: string | undefined = struct.owner && struct.owner.username;
Expand Down Expand Up @@ -774,17 +777,17 @@ function resources(o: GenericStore): ResourceConstant[] {

// test discriminated union using filter functions on find
const from = Game.rooms.myRoom.find(FIND_STRUCTURES, {
filter: s => (s.structureType === STRUCTURE_CONTAINER || s.structureType === STRUCTURE_STORAGE) && s.store.energy > 0,
filter: (s) => (s.structureType === STRUCTURE_CONTAINER || s.structureType === STRUCTURE_STORAGE) && s.store.energy > 0,
})[0];
const to = from.pos.findClosestByPath(FIND_MY_STRUCTURES, {
filter: s => (s.structureType === STRUCTURE_SPAWN || s.structureType === STRUCTURE_EXTENSION) && s.energy < s.energyCapacity,
filter: (s) => (s.structureType === STRUCTURE_SPAWN || s.structureType === STRUCTURE_EXTENSION) && s.energy < s.energyCapacity,
});

Game.rooms.myRoom
.find(FIND_MY_STRUCTURES, {
filter: s => s.structureType === STRUCTURE_RAMPART,
filter: (s) => s.structureType === STRUCTURE_RAMPART,
})
.forEach(r => r.notifyWhenAttacked(false));
.forEach((r) => r.notifyWhenAttacked(false));
}

{
Expand Down Expand Up @@ -831,7 +834,7 @@ function resources(o: GenericStore): ResourceConstant[] {
// StructurePortal

{
const portals = room.find<StructurePortal>(FIND_STRUCTURES, { filter: s => s.structureType === STRUCTURE_PORTAL });
const portals = room.find<StructurePortal>(FIND_STRUCTURES, { filter: (s) => s.structureType === STRUCTURE_PORTAL });
portals.forEach((p: StructurePortal) => {
const state = p.ticksToDecay === undefined ? "stable" : "unstable";
if (p.destination instanceof RoomPosition) {
Expand Down Expand Up @@ -917,7 +920,7 @@ function resources(o: GenericStore): ResourceConstant[] {
// Creep.body
function atackPower(creep: Creep) {
return creep.body
.map(part => {
.map((part) => {
if (part.type === ATTACK) {
const multiplier = part.boost ? BOOSTS[part.type][part.boost].attack : 1;
return multiplier * ATTACK_POWER;
Expand Down Expand Up @@ -1016,11 +1019,7 @@ function atackPower(creep: Creep) {
const point3 = new RoomPosition(1, 1, "E8N8");
const point4 = new RoomPosition(1, 1, "E1N8");

mapVis
.line(point1, point2)
.circle(point3, { fill: "#f2f2f2" })
.poly([point1, point2, point3, point4])
.rect(point3, 50, 50);
mapVis.line(point1, point2).circle(point3, { fill: "#f2f2f2" }).poly([point1, point2, point3, point4]).rect(point3, 50, 50);

const size: number = mapVis.getSize();

Expand All @@ -1033,5 +1032,5 @@ function atackPower(creep: Creep) {
{
const roomId = "" as Id<Room>; // $ExpectError
const creep = Game.getObjectById("" as Id<Creep>);
const foo = Game.getObjectById<StructureTower>("" as Id<Creep>); // $ExpectError
const foo = Game.getObjectById<StructureTower>("" as Id<Creep>); // expected to be an error in the next major release
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed-screeps",
"version": "3.3.0",
"version": "3.3.1",
"description": "Strong TypeScript declarations for the game Screeps.",
"repository": "screepers/typed-screeps",
"types": "./dist/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ interface Game {
getObjectById<T extends Id<_HasId>>(id: T): fromId<T> | null;
getObjectById<T extends _HasId>(id: Id<T>): T | null;

/**
* Get an object with the specified unique ID. It may be a game object of any type. Only objects from the rooms which are visible to you can be accessed.
* @param id The unique identifier.
* @returns an object instance or null if it cannot be found.
* @deprecated Use Id<T>, instead of strings, to increase type safety
*/
// tslint:disable-next-line:unified-signatures
getObjectById<T extends _HasId>(id: string): T | null;

/**
* Send a custom message at your profile email.
*
Expand Down