-
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.
- Loading branch information
1 parent
f01578b
commit 37c44e6
Showing
6 changed files
with
117 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
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,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; | ||
} |
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,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" | ||
} | ||
} |
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-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) |
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,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'])); | ||
}); |
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" | ||
} |