diff --git a/src/is-object-visible/index.ts b/src/is-object-visible/index.ts new file mode 100644 index 0000000..f813831 --- /dev/null +++ b/src/is-object-visible/index.ts @@ -0,0 +1,3 @@ +export function isObjectVisible(id: string): boolean { + return Game.getObjectById(id) !== null; +} diff --git a/src/is-object-visible/package.json b/src/is-object-visible/package.json new file mode 100644 index 0000000..eba0752 --- /dev/null +++ b/src/is-object-visible/package.json @@ -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" + } +} diff --git a/src/is-object-visible/readme.md b/src/is-object-visible/readme.md new file mode 100644 index 0000000..57caa3a --- /dev/null +++ b/src/is-object-visible/readme.md @@ -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('someid') +} +``` + +## Related +- [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible) + +## License +[MIT](../../license.md) diff --git a/src/is-object-visible/test.ts b/src/is-object-visible/test.ts new file mode 100644 index 0000000..071237b --- /dev/null +++ b/src/is-object-visible/test.ts @@ -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')); +}); diff --git a/src/is-object-visible/tsconfig.json b/src/is-object-visible/tsconfig.json new file mode 100644 index 0000000..9536a0f --- /dev/null +++ b/src/is-object-visible/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.base.json" +}