Skip to content

Commit

Permalink
feat(is-creep-alive): add module is-creep-alive
Browse files Browse the repository at this point in the history
Works fairly similar too `is-room-visible` by checking whether a creep with the given name exists.
This will include creeps that are currently getting spawned as well, a separate module to check for this might get published later on.
  • Loading branch information
Arcath authored and RiftLurker committed Jan 15, 2018
1 parent 897db27 commit 8a57793
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/is-creep-alive/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isCreepAlive(creep: string): boolean {
return creep in Game.creeps;
}
48 changes: 48 additions & 0 deletions src/is-creep-alive/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@open-screeps/is-creep-alive",
"version": "0.0.0-development",
"description": "Returns true if the creep is alive",
"main": "index.js",
"scripts": {
"lint": "tslint -p ./tsconfig.json",
"test": "tsc && nyc ava",
"prepare": "npm test",
"release": "semantic-release -e semantic-release-monorepo"
},
"repository": {
"type": "git",
"url": "git+https://github.com/postcrafter/open-screeps.git"
},
"files": [
"index.{d.ts,js,js.map}"
],
"keywords": [
"screeps",
"open-screeps"
],
"author": "Adam Laycock <adam'arcath.net>",
"license": "MIT",
"bugs": {
"url": "https://github.com/postcrafter/open-screeps/issues"
},
"homepage": "https://github.com/postcrafter/open-screeps/src/is-creep-alive#readme",
"dependencies": {
"@types/screeps": "^0.0.0"
},
"devDependencies": {
"ava": "^0.24.0",
"condition-circle": "^2.0.1",
"nyc": "^11.3.0",
"semantic-release": "^11.0.2",
"semantic-release-monorepo": "^4.0.0",
"tslint": "^5.9.1",
"tslint-config-airbnb": "^5.4.2",
"typescript": "^2.6.2"
},
"publishConfig": {
"access": "public"
},
"release": {
"verifyConditions": "condition-circle"
}
}
20 changes: 20 additions & 0 deletions src/is-creep-alive/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# is-creep-alive
> Returns true if the creep is alive
## Install
```sh
$ npm install @open-screeps/is-creep-alive
```

## Usage
```typescript
import { isCreepAlive } from '@open-screeps/is-creep-alive';

const livingCreeps = _.filter(Memory.creepList, (creepName) => isCreepAlive(creepName))
```

## Related
- [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible)

## License
[MIT](../../license.md)
21 changes: 21 additions & 0 deletions src/is-creep-alive/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ava from 'ava';

import { isCreepAlive } from './index';

declare const global: any;

function stubGame() {
global.Game = {
creeps: {
dave: {},
bob: {},
},
};
}

ava('Should return the right values for is creep alive', (t) => {
stubGame();

t.true(isCreepAlive('dave'));
t.false(isCreepAlive('phil'));
});
3 changes: 3 additions & 0 deletions src/is-creep-alive/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.base.json"
}

0 comments on commit 8a57793

Please sign in to comment.