Skip to content

Commit

Permalink
feat: add is-creep-spawning module
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath authored and RiftLurker committed Jan 17, 2018
1 parent f01578b commit 37c44e6
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/is-creep-alive/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/is-creep-spawning/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
49 changes: 49 additions & 0 deletions src/is-creep-spawning/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"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"
}
}
20 changes: 20 additions & 0 deletions src/is-creep-spawning/readme.md
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions src/is-creep-spawning/test.ts
Original file line number Diff line number Diff line change
@@ -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']));
});
3 changes: 3 additions & 0 deletions src/is-creep-spawning/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.base.json"
}

0 comments on commit 37c44e6

Please sign in to comment.