-
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
37c44e6
commit 962fd86
Showing
5 changed files
with
101 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 isObjectVisible(id: string): boolean { | ||
return Game.getObjectById(id) !== null; | ||
} |
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-object-visible", | ||
"version": "0.0.0-development", | ||
"description": "Is the game object visible", | ||
"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-object-visible#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,22 @@ | ||
# is-object-visible | ||
> Is the game object visible | ||
## Install | ||
```sh | ||
$ npm install @open-screeps/is-object-visible | ||
``` | ||
|
||
## Usage | ||
```typescript | ||
import { isObjectVisible } from '@open-screeps/is-object-visible'; | ||
|
||
if(isObjectVisible('someid')){ | ||
const source = Game.getObjectById<Source>('someid') | ||
} | ||
``` | ||
|
||
## 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,25 @@ | ||
import ava from 'ava'; | ||
|
||
import { isObjectVisible } from './index'; | ||
|
||
declare const global: any; | ||
|
||
function stubGame() { | ||
const objects: {[id: string]: {} | null} = { | ||
foo: {}, | ||
bar: null, | ||
}; | ||
|
||
global.Game = { | ||
getObjectById: (id: string) => { | ||
return objects[id]; | ||
}, | ||
}; | ||
} | ||
|
||
ava('Should return the right values', (t) => { | ||
stubGame(); | ||
|
||
t.true(isObjectVisible('foo')); | ||
t.false(isObjectVisible('bar')); | ||
}); |
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" | ||
} |