-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(is-creep-alive): add module is-creep-alive
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
1 parent
897db27
commit 8a57793
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json" | ||
} |