Skip to content

Commit

Permalink
Merge pull request #16 from PostCrafter/is-simulation
Browse files Browse the repository at this point in the history
feat(is-simulation): add module is-simulation
  • Loading branch information
RiftLurker authored Dec 27, 2017
2 parents 78ecb72 + 02ee25f commit 4ad0085
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/is-room-visible/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ import { isRoomVisible } from '@open-screeps/is-room-visible';
const observerTargets = Object.keys(Memory.rooms).filter(r => isRoomVisible(r));
```

## Related
- [is-simulation](https://github.com/PostCrafter/open-screeps/tree/master/src/is-simulation)

## License
[MIT](../../license.md)
7 changes: 7 additions & 0 deletions src/is-simulation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { isRoomVisible } from '@open-screeps/is-room-visible';

export const ROOM_SIMULATION = 'sim';

export function isSimulation() {
return isRoomVisible(ROOM_SIMULATION);
}
56 changes: 56 additions & 0 deletions src/is-simulation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@open-screeps/is-simulation",
"version": "0.0.0",
"description": "Check whether the code is running in simulation",
"main": "index.js",
"scripts": {
"test": "tsc && nyc ava",
"prepare": "npm test",
"release": "semantic-release"
},
"repository": {
"type": "git",
"url": "git+https://github.com/postcrafter/open-screeps.git"
},
"files": [
"index.{d.ts,js,js.map}"
],
"keywords": [
"screeps",
"open-screeps"
],
"author": "Leo "PostCrafter" Friedrichs <dev@postcrafter.de>",
"license": "MIT",
"bugs": {
"url": "https://github.com/postcrafter/open-screeps/issues"
},
"homepage": "https://github.com/postcrafter/open-screeps/src/is-simulation#readme",
"dependencies": {
"@open-screeps/is-room-visible": "*",
"@types/screeps": "^0.0.0"
},
"devDependencies": {
"@semantic-release/git": "^2.0.1",
"ava": "^0.24.0",
"condition-circle": "^2.0.1",
"coveralls": "^3.0.0",
"nyc": "^11.3.0",
"semantic-release": "^11.0.2",
"semantic-release-monorepo": "^3.1.0",
"typescript": "^2.6.2"
},
"publishConfig": {
"access": "public"
},
"release": {
"verifyConditions": "condition-circle",
"analyzeCommits": "semantic-release-monorepo",
"generateNotes": "semantic-release-monorepo",
"getLastRelease": "semantic-release-monorepo",
"publish": [
"@semantic-release/npm",
"@semantic-reelase/git",
"semantic-release-monorepo/github"
]
}
}
22 changes: 22 additions & 0 deletions src/is-simulation/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# is-simulation
> Check whether the code is running in simulation
## Install
```sh
$ npm install @open-screeps/is-simulation
```

## Usage
```typescript
import { isSimulation } from '@open-screeps/is-simulation';

if (isSimulation()) {
console.log('Code loaded in simulation.');
}
```

## Related
- [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible)

## License
[MIT](../../license.md)
28 changes: 28 additions & 0 deletions src/is-simulation/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import test from 'ava';

import { isSimulation, ROOM_SIMULATION } from './index';

declare const global: any;

function stubGame(...rooms: string[]) {
type RoomsStub = {
[roomName: string]: boolean;
};

global.Game = rooms.reduce((game, roomName) => {
game.rooms[roomName] = true;
return game;
}, {
rooms: {} as RoomsStub
});
}

test('Should return true when the room `ROOM_SIMULATION` is visible.', t => {
stubGame(ROOM_SIMULATION);
t.true(isSimulation());
});

test('Should return false when the room `ROOM_SIMULATION` is not visible.', t => {
stubGame('tutorial');
t.false(isSimulation());
});
3 changes: 3 additions & 0 deletions src/is-simulation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.base.json"
}

0 comments on commit 4ad0085

Please sign in to comment.