-
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.
Merge pull request #16 from PostCrafter/is-simulation
feat(is-simulation): add module is-simulation
- Loading branch information
Showing
6 changed files
with
119 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,7 @@ | ||
import { isRoomVisible } from '@open-screeps/is-room-visible'; | ||
|
||
export const ROOM_SIMULATION = 'sim'; | ||
|
||
export function isSimulation() { | ||
return isRoomVisible(ROOM_SIMULATION); | ||
} |
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,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" | ||
] | ||
} | ||
} |
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-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) |
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,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()); | ||
}); |
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" | ||
} |