Skip to content

Fix Memory interface so that's it's extensible #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4c38745
Added optional visualizePathStyle to MoveToOpts interface in order to…
jyarbro May 2, 2017
30fb291
Added visual studio files to .gitignore.
jyarbro May 2, 2017
7793239
Added dependency on ntypescript for compilation.
jyarbro May 2, 2017
b88dfdc
Added class declaration for RoomVisual.
jyarbro May 2, 2017
2ebc7f2
Completed declaration of RoomVisual.
jyarbro May 2, 2017
11fa545
Added visual property to Room class declaration.
jyarbro May 2, 2017
42d1971
Updated dist file to include all changes.
jyarbro May 2, 2017
db62d9d
Replaced my tabs with their spaces.
jyarbro May 2, 2017
6466db0
Adjusted a comment.
jyarbro May 2, 2017
db8ba79
removed unnecessary change to .gitignore.
jyarbro May 2, 2017
398bd28
removed addition of ntypescript dependency as it's outside the scope …
jyarbro May 2, 2017
44ab926
Fix Memory interface so that's it's extensible
bryanbecker May 14, 2017
82298b4
Change Creep, Spawn, Flag, and Room memory to match Memory object
bryanbecker May 16, 2017
dc9983f
Compile changes to memory
bryanbecker May 19, 2017
4b865f0
Merge pull request #1 from bryanbecker/master
resir014 May 20, 2017
ffe9377
Return code and find literals added
bryanbecker May 25, 2017
8923811
Re add major constants as literal types
bryanbecker May 25, 2017
185003c
BodyPart constants
bryanbecker May 25, 2017
9eb36d7
Color constants
bryanbecker May 25, 2017
1e71b1b
Mineral Literals added; Narrow typings of some Constants
bryanbecker May 25, 2017
88e9f75
Construct Site generified
bryanbecker May 25, 2017
6492750
Change to use native `Record` type
bryanbecker May 25, 2017
e29ee19
Creep typings updated;
bryanbecker May 25, 2017
78c6417
Flag typings finished
bryanbecker May 25, 2017
d0e310c
All structures finished
bryanbecker May 25, 2017
70848b4
Add type to Resource
bryanbecker May 25, 2017
8a137ca
Typed LookAt results
bryanbecker May 25, 2017
c666dee
Generify minerals
bryanbecker May 25, 2017
547d7ad
Add nukes to types
bryanbecker May 25, 2017
f600611
Compiled changes
bryanbecker May 25, 2017
55003ff
Energy constant gauranteed on Store
bryanbecker May 25, 2017
cd7f16c
`find` functions can also return RoomPositions
bryanbecker May 25, 2017
ab047ae
Delete comments; Add missing direction constant return value
bryanbecker May 25, 2017
ab8326f
Update Readme and package.json
bryanbecker May 25, 2017
e6eaed6
Merge pull request #2 from bryanbecker/literals
bryanbecker May 25, 2017
40e8f3e
Merge branch 'TS2' of https://github.com/jyarbro/Screeps-Typescript-D…
bryanbecker May 25, 2017
e64ac07
Fix tuple / array ambiguity
bryanbecker May 25, 2017
5c0424a
Merge pull request #3 from bryanbecker/visuals
bryanbecker May 25, 2017
273a9cd
Compiled visuals changes
bryanbecker May 25, 2017
7dadec8
Merge pull request #4 from bryanbecker/master
bryanbecker May 25, 2017
4618f93
Map is typed
bryanbecker May 25, 2017
fff2671
Make spacing more standard
bryanbecker May 25, 2017
88d6777
Merge pull request #5 from bryanbecker/map
bryanbecker May 25, 2017
f180ac0
Deprecate FIND_DROPPED_ENERGY
bryanbecker May 27, 2017
0375365
Compile changes
bryanbecker May 27, 2017
7869cfa
Merge remote-tracking branch 'upstream/master'
bryanbecker May 27, 2017
be941e4
Merge pull request #6 from bryanbecker/master
bryanbecker May 27, 2017
3830511
Update README.md
bryanbecker May 28, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 60 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,71 @@
# Screeps Typescript Declarations
** This repo has been moved to [typed-screeps](https://github.com/bryanbecker/typed-screeps) **

> The repository for *Screep's* TypeScript type definitions. https://screeps.com/
# Typed-Screeps

Discussion in [screep's community forum](http://support.screeps.com/hc/en-us/community/posts/207116485-Writing-Screep-bots-with-Typescript?page=1#)
> The forked repository for **strong** *Screep's* TypeScript type definitions. https://screeps.com/

# Installation

Using [typings](https://github.com/typings/typings), add this to your typings.json:
```json
{
"globalDependencies": {
"screeps": "github:screepers/Screeps-Typescript-Declarations/dist/screeps.d.ts#TS2"
}
}
```bash
typings install github:resir014/typed-screeps/dist/screeps.d.ts#master -SG
```

# Differences from **[Screeps-Typescript-Declarations](https://github.com/screepers/Screeps-Typescript-Declarations)**:
### Breaking Changes:
- `Memory` is typed by default. The added typings are:
- `CreepMemory`
- `FlagMemory`
- `SpawnMemory`
- `RoomMemory`

If you like the idea of typed memory, but aren't ready to just fully in, just make sure you define an interface for the above four types. Then you can extend them at a later time. Example:
```TypeScript
interface CreepMemory { [name: string]: any };
interface FlagMemory { [name: string]: any };
interface SpawnMemory { [name: string]: any };
interface RoomMemory { [name: string]: any };
```

- Any place in code that uses a constant (ex `STRUCTURE_EXTENSION` or `FIND_MY_SPAWNS` is now constrained to use literal types. Here is the list of the new types:
```
BodyPartConstant
StructureConstant
FindConstant
LookConstant
DirectionConstant
ResourceConstant
MineralConstant (this is a subset of ResourceConstant)
ColorConstant
ScreepsReturnCode
```

To update your code, you just need to change any `string` types to match one of the above. For example, if your code had:
```TypeScript
function getBody(): string[] {
return [ WORK, MOVE, CARRY ];
}
```
Change it to:
```TypeScript
function getBody(): BodyPartConstant[] { // this line changed
return [ WORK, MOVE, CARRY ];
}
```
- Some original functions were incorrectly typed to not include `null` as a possible return. You may need to update your code to reflect this update (ex. `findClosestByPath` or `findClosestByRange`)

### Additional (non-breaking) Features:
- `ConstructionSite` can be optionally constrained by a structure type (ex. `ConstructionSite<STRUCTURE_CONTAINER>`). TypeScript will enforce that the `type` property of the `ConstructionSite` appropriately matches
- `Resource` can optionally be constrained (ex. `Resource<RESOURCE_ENERGY>`)
- `Mineral` can optionally be constrained by `MineralConstant` (ex. `Mineral<RESOURCE_GHODIUM>`)
- `Structure` can optionally be constrained (ex `Structure<STRUCTURE_SPAWN | STRUCTURE_EXTENSION>`)
- Screeps classes derived from `Structure` (ex `StructureContainer`) have their `type` property correspondingly constrained
- `LookAt` results are now constrained to the type looked for
- Results from `Find`-type functions are now constrained to have a `RoomPosition`




# Usage

Note: When using this API, you can't access creeps in manner suggested in Screeps' tutorial:
Expand All @@ -41,102 +92,3 @@ To compile the declarations, run:
npm run compile
```

# Changelog

### v4.2.1 2016-07-25 [ChangeLog](http://support.screeps.com/hc/en-us/articles/210048285-Changelog-2016-07-22)
- Added new toPublic option to `Creep.say`
- Fixed some issue with using `instanceof` with `StructureSpawn`, `Source`, `StructureLink`

### v4.2.0
- New Creep.withdraw
- Added and fixed a lot of constants

### v4.0.1
- Fixed issues with REACTIONS and LOOK_* constants

### v4.0.0
- Changed `Map` to `GameMap` to avoid conflict with new ES6 Map type
- Removed Energy Interface and replace it with Resource. This could potentially break your code. Please change all reference of Energy to Resource and it should fix the issue.
- Spawn will now extends OwnStructure, and StructureContainer will extends Structure.
- Fixed createCreep return type to `number | string`.
- Updated new options for findPath
- Added string as an acceptable params to moveByPath.

### v3.0.0 Change all usage of interface to class.
Please raise an issue if this break your code!

### v2.1.0 2016-06-23 [ChangeLog](http://support.screeps.com/hc/en-us/articles/209164605-Changelog-2016-06-17)
- Added new method StructureRampart.setPublic.
- Added new property StructureRamprt.isPublic.
- Added new global property Game.constructionSites.
- Added new argument asArray to methods Room.lookAtArea and Room.lookForAtArea
- Method Creep.moveByPath now accepts paths returned from PathFinder.search.

### v1.5.4 2016-04-04 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/12)
- Missing constants

Thanks [Strategic-Link-Consulting](https://github.com/Strategic-Link-Consulting)

### v1.5.3 2016-03-31 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/11)
- Problem with the Game arrays.

### v1.5.2 2016-03-19 [Bug](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/10)
- RoomPosition opts fix. Filter and algorithm are optional.

### v1.5.1 2016-03-18 [ChangeLog](http://support.screeps.com/hc/en-us/articles/208013255)
- Added new STRUCTURE_CONTAINER constant
- New structure: Container
- Added Game.map.getRoomLinearDistance method.

### v1.4.3 2016-03-18 Commited by NhanHo
- Added typings for various list of global objects in Game
- Add serializePath and deserializePath to Room
- Allow optional argument and properties in transferEnergy and PathFinderOps

### v1.4.2 2016-03-10
- Fix for CostMatrix

### v1.4.1 2016-03-10 [ChangeLog](http://support.screeps.com/hc/en-us/articles/207929925)
- Added Extractor, Lab, Terminal, Market, Mineral objects
- New constants
- Read more from docs

### v1.3.2 2016-03-10 [ChangeLog](http://support.screeps.com/hc/en-us/articles/207023879-PathFinder)
- Updated all interfaces from 19.02 changelog and added docs to PathFinder [ChangeLog](http://support.screeps.com/hc/en-us/articles/207728995-Changelog-2016-02-19).

### v1.3.1 2016-02-25 [PathFinder](http://support.screeps.com/hc/en-us/articles/207023879-PathFinder)
- NhanHo added new PathFinder interface [ChangeLog](http://support.screeps.com/hc/en-us/articles/207728995-Changelog-2016-02-19).
Unfortunately other changes in that changelog are not added yet. We're working on it

### v1.2.2 2016-02-08 [ChangeLog](http://support.screeps.com/hc/en-us/articles/206897739-Changelog-2016-02-08)
- New body part (CLAIM)
- Documentation updates to support claim
- Added Creep.dismantle()

- Fixed missing NOT_ENOUGH_ENERGY constant

### v1.1.7 2016-02-08
- Change room.controller and room.storage to correct type

### v1.1.5 2016-02-07
- Updated RoomPosition declarations [#1](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/1)
- Removed HashMap from Game interface. It caused migration issues from JS to TS. [#2](https://github.com/MarkoSulamagi/Screeps-Typescript-Declarations/issues/2)
- Declare construction site variable (to fix instanceof problem)

### v1.1.3 2016-02-06
- Removed empty memory interfaces
- Fixed createScreep() method return type
- Updated all declarations. Everything should be quite close to Screep's API (with minor exceptions if I missed something accidentally)

## Authors

* **Nhan Ho** - *Current maintainer* - [NhanHo](https://github.com/NhanHo)
* **Marko Sulamägi** - *Converted Cameron's work to quickly installable TS skeleton app.* - [MarkoSulamagi](https://github.com/MarkoSulamagi)
* **vanhouc** - *Screep project with TS functionality. His gulpfile and screep.d.ts was very useful.* - [vanhouc](https://github.com/vanhouc)


See also the list of [contributors](https://github.com/screepers/Screeps-Typescript-Declarations/contributors) who participated in this project.

## License

This project is licensed under the MIT license.
Loading