diff --git a/src/is-creep-alive/readme.md b/src/is-creep-alive/readme.md index 482f043..644b85f 100644 --- a/src/is-creep-alive/readme.md +++ b/src/is-creep-alive/readme.md @@ -14,6 +14,7 @@ const livingCreeps = _.filter(Memory.creepList, (creepName) => isCreepAlive(cree ``` ## Related +- [is-creep-spawning](https://github.com/PostCrafter/open-screeps/tree/master/src/is-creep-spawning) - [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible) ## License diff --git a/src/is-creep-spawning/index.ts b/src/is-creep-spawning/index.ts new file mode 100644 index 0000000..af7615f --- /dev/null +++ b/src/is-creep-spawning/index.ts @@ -0,0 +1,17 @@ +import { isCreepAlive } from '@open-screeps/is-creep-alive'; + +export function isCreepSpawning(creepName: string | Creep): boolean { + let creep: Creep; + + if (typeof creepName === 'string') { + if (!isCreepAlive(creepName)) { + return false; + } + + creep = Game.creeps[creepName]; + } else { + creep = creepName; + } + + return creep.spawning; +} diff --git a/src/is-creep-spawning/package.json b/src/is-creep-spawning/package.json new file mode 100644 index 0000000..5543070 --- /dev/null +++ b/src/is-creep-spawning/package.json @@ -0,0 +1,49 @@ +{ + "name": "@open-screeps/is-creep-spawning", + "version": "0.0.0-development", + "description": "Is the named/supplied creep spawning?", + "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-spawning#readme", + "dependencies": { + "@open-screeps/is-creep-alive": "*", + "@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" + } +} diff --git a/src/is-creep-spawning/readme.md b/src/is-creep-spawning/readme.md new file mode 100644 index 0000000..0802f34 --- /dev/null +++ b/src/is-creep-spawning/readme.md @@ -0,0 +1,20 @@ +# is-creep-spawning +> Is the named/supplied creep spawning? + +## Install +```sh +$ npm install @open-screeps/is-creep-spawning +``` + +## Usage +```typescript +import { isCreepSpawning } from '@open-screeps/is-creep-spawning'; + +const spawningCreeps = _.filter(Game.creeps, (creep) => isCreepSpawning(creep)) +``` + +## Related +- [is-creep-alive](https://github.com/PostCrafter/open-screeps/tree/master/src/is-creep-alive) + +## License +[MIT](../../license.md) diff --git a/src/is-creep-spawning/test.ts b/src/is-creep-spawning/test.ts new file mode 100644 index 0000000..4320fb6 --- /dev/null +++ b/src/is-creep-spawning/test.ts @@ -0,0 +1,27 @@ +import ava from 'ava'; + +import { isCreepSpawning } from './index'; + +declare const global: any; + +function stubGame() { + global.Game = { + creeps: { + dave: { + spawning: true, + }, + phil: { + spawning: false, + }, + }, + }; +} + +ava('Should return the right values for the given creeps', (t) => { + stubGame(); + + t.true(isCreepSpawning('dave')); + t.false(isCreepSpawning('phil')); + t.false(isCreepSpawning('jeff')); + t.true(isCreepSpawning(Game.creeps['dave'])); +}); diff --git a/src/is-creep-spawning/tsconfig.json b/src/is-creep-spawning/tsconfig.json new file mode 100644 index 0000000..9536a0f --- /dev/null +++ b/src/is-creep-spawning/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.base.json" +}