Skip to content

Commit

Permalink
feat: add is-object-visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath authored and RiftLurker committed Jan 17, 2018
1 parent 37c44e6 commit 962fd86
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/is-object-visible/index.ts
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;
}
48 changes: 48 additions & 0 deletions src/is-object-visible/package.json
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"
}
}
22 changes: 22 additions & 0 deletions src/is-object-visible/readme.md
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)
25 changes: 25 additions & 0 deletions src/is-object-visible/test.ts
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'));
});
3 changes: 3 additions & 0 deletions src/is-object-visible/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.base.json"
}

0 comments on commit 962fd86

Please sign in to comment.