Giter Club home page Giter Club logo

screeps-typescript-declarations's Introduction

Screeps Typescript Declarations

The repository for Screep's TypeScript type definitions. https://screeps.com/

Discussion in screep's community forum

Installation

Using typings, add this to your typings.json:

{
  "globalDependencies": {
    "screeps": "github:screepers/Screeps-Typescript-Declarations/dist/screeps.d.ts"
  }
}

Usage

Note: When using this API, you can't access creeps in manner suggested in Screeps' tutorial:

Game.creeps.Worker1  // This is not allowed by TypeScript compiler

Instead, you have to use

Game.creeps['Worker1']

Contribute

This library will stay up to date only with the help of you! If active players don't update it, it'll get lost.

To update the declarations, edit the files in ./src folder.

To compile the declarations, run:

npm run compile

Changelog

v4.2.1 2016-07-25 ChangeLog

  • 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

  • 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

  • Missing constants

Thanks Strategic-Link-Consulting

v1.5.3 2016-03-31 Bug

  • Problem with the Game arrays.

v1.5.2 2016-03-19 Bug

  • RoomPosition opts fix. Filter and algorithm are optional.

v1.5.1 2016-03-18 ChangeLog

  • 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

  • Added Extractor, Lab, Terminal, Market, Mineral objects
  • New constants
  • Read more from docs

v1.3.2 2016-03-10 ChangeLog

  • Updated all interfaces from 19.02 changelog and added docs to PathFinder ChangeLog.

v1.3.1 2016-02-25 PathFinder

  • NhanHo added new PathFinder interface ChangeLog. Unfortunately other changes in that changelog are not added yet. We're working on it

v1.2.2 2016-02-08 ChangeLog

  • 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
  • Removed HashMap from Game interface. It caused migration issues from JS to TS. #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
  • Marko Sulamägi - Converted Cameron's work to quickly installable TS skeleton app. - MarkoSulamagi
  • vanhouc - Screep project with TS functionality. His gulpfile and screep.d.ts was very useful. - vanhouc

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT license.

screeps-typescript-declarations's People

Contributors

anisoptera avatar bonzaiferroni avatar chriskitching avatar dessix avatar distantcam avatar glukki avatar kotarou avatar lewinke avatar lf- avatar markosulamagi avatar mschultheiss83 avatar mxth avatar nachimehta avatar nhanho avatar o4kapuk avatar remz-jay avatar resir014 avatar roncli avatar seancl avatar sheeo avatar stargateur avatar thaelina avatar valerian avatar vanhouc avatar viezevingertjes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

screeps-typescript-declarations's Issues

Missing extrends

It seems both StructureContainer and Spawn is missing the extends Structure in declaration.

I am very new to the game, so I might be overlooking something though. The error I'm getting is I cannot use them as RoomObject in i.e. moveTo

Allow typing of default memory objects

It seems that currently, you can't apply an interface to members of the built-in Memory objects (such as Memory.creeps) because they're defined in index.d.ts as any. I'd like to propose making a dummy interface for each of the four built-in Memory objects so that a player can then extend those interfaces in their own definition files.

For example, say I make my own interface for a room's memory:

interface MemRoom {
  name: string;
  type: string;
  threat: boolean;
}

If I try to apply it to Memory as follows:

interface Memory {
  rooms: {
    [name: string]: MemRoom;
  };
}

Then with the current typings I will get this error:

error TS2403: Subsequent variable declarations must have the same type.  Variable 'rooms' must be of type '{ [name: string]: any; }', but here has type '{ [name: string]: MemRoom; }'.

If however, there were already a "dummy" interface in the typings called MemRoom:

interface Memory {
    [name: string]: any;
    ...
    rooms: {
        [name: string]: MemRoom;
    };
    ...
}
interface MemRoom {
  [name: string]: any;
}
declare class Room {
  ...
    /**
     * A shorthand to Memory.rooms[room.name]. You can use it for quick access the room’s specific memory data object.
     */
    memory: MemRoom;
  ...
}

Then I could extend MemRoom to give specific types to any variables I want (as I tried to do above). This could be done for all four default Memory objects, and would allow users to type things that they want to store in memory - a huge advantage, I think, since Memory is the biggest source of errors for me these days!

If there is already a way to accomplish this that doesn't require modifying the current screeps declarations, please let me know as I'd be very curious!

"Map" definition conflicts with ES6 "Map" target

It seems that, since the definition for Map has no accessible constructor, we should be able to just rename it to something that doesn't conflict, so the Map type is usable for non-string dictionary keys?

Problem with the Game arrays

Thanks for creating and keeping this updated.

I noticed issues compiling and I think I see the problem but I'm pretty new at this.
It's the declarations for Game.rooms/flags/creeps etc. Instead of just an array, shouldn't they be like this?

  creeps: {[creepName: string]: Creep};
  rooms: {[roomName: string]: Room};
  spawns: {[spawnName: string]: Spawn};
  structures: {[structureId: string]: Structure};

Many types are 1-tuples where they should be arrays

Throughout the declarations there are many occurrences of 1-tuples where it should have been an array.

[string] is a 1-tuple containing 1 element of type string.

string[] is an array of string elements.

And what is even more confusing is that tuples are bugged in TypeScript, allowing to use more elements than defined: microsoft/TypeScript#6229

An example of this issue in the present declarations:

RoomPosition.findClosestByRange<T>(objects: [T|RoomPosition], opts?: {filter: any|string }): T;

Which should actually be:

RoomPosition.findClosestByRange<T>(objects: T[]|RoomPosition[], opts?: {filter: any|string }): T;

I will try to fix all of them and do a pull request.

Question - how to make ts-jest happy at test runtime?

Hello there!

I'm struggling with setting up unit tests that depend on Screeps types.

For example, when trying to extend Creeps like this:

Creep.prototype.someFunction = ...

My IDE is happy, the compiled code runs in game just fine, all types are resolved. But, when executing a unit test that imports the above code, it always fails with

ReferenceError: Creep is not defined

How to teach ts-jest to look at the right place and resolve Creep and other types located in node_modules/@types/screeps/index.d.ts ?

Thank you in advance!

Object for defining globals

In screeps, there's an object global which can be used to store values globally (i.e. for use from the console). It should be as simple as adding a declare var global:any; in the code, but I'm not sure where it should be put (hence an issue instead of a PR)

helpers.ts LookAtResultMatrix interface

Think it should be declared as a string for named array, compiler was balking til I changed it.

interface LookAtResultMatrix {
    [coord: string]: LookAtResultMatrix|LookAtResult[]
}

filter and algorithm should be made optional.

I added the question marks (?) to the opts object. This was causing my code to throw errors since I was only using filter and not specifying the algorithm (using the default).

    /**
     * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm.
     * @param type See Room.find
     * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm
     */
    findClosestByPath<T>(type: number, opts?: {
        filter?: any | string;
        algorithm?: string;
    }): T;
    /**
     * Find an object with the shortest path from the given position. Uses A* search algorithm and Dijkstra's algorithm.
     * @param objects An array of room's objects or RoomPosition objects that the search should be executed against.
     * @param opts An object containing pathfinding options (see Room.findPath), or one of the following: filter, algorithm
     */
    findClosestByPath<T>(objects: [T | RoomPosition], opts?: {
        filter?: any | string;
        algorithm?: string;
    }): T;

Take over of the repo and npm package

I just had a move across the planet and didn't get your message until now. I will take over the repo and package if you don't want to maintain them anymore

Source should be class?

I had problems using a variable of Source | Ressource, as instanceof only works for classes it seems, and I need to narrow the type for a function call to Creep.harvest. Should Source be a class, or is there another way to narrow the type?

nuker added to CONSTRUCTION_COST constant.ts

Needs to be added to end.

declare var CONSTRUCTION_COST: {
    spawn: number;
    extension: number;
    road: number;
    constructedWall: number;
    rampart: number;
    link: number;
    storage: number;
    tower: number;
    observer: number;
    powerSpawn: number;
    extractor: number;
    lab: number;
    terminal: number;
    container: number;
    nuker: number;
};

Creep body part typings suggestion

With some uses of literal types, we can allow body part typings to accurately reflect their values while not affecting backward compatibility with those who are using the existing typings:

image

This can also be extended to other locations such as the Direction types.

assigning literal values to constants

I recently imported screeps.d.ts and noticed that there were a few issues related to literal values assigned to game constants. Previously they were declared like this:

declare const SOURCE_ENERGY_CAPACITY: number;

Now they are declared like this:

declare const SOURCE_ENERGY_CAPACITY: 3000;

This caused a lot of compiler errors, here is an example:

let score = SOURCE_ENERGY_CAPACITY;
if (WorldMap.roomTypeFromName(sourcePos.roomName) === ROOMTYPE_SOURCEKEEPER) {
    // TS2322: Type '4000' is not assignable to type '3000'
    score = SOURCE_ENERGY_KEEPER_CAPACITY;
}

I'm curious about the rationale for this specific way of declaring types and what situations that it would help. I'm also wondering if there is some setting that I can use to allow it to understand that I'm aiming for a number type here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.