Skip to content

rickpelletier/screeps-typescript-starter

 
 

Repository files navigation

screeps-starter

Starter kit for TypeScript-based Screeps AI codes.

This starter kit is a modified version of the original Screeps/TypeScript sample project by Marko Sulamägi.

Before You Start

DO NOT run the Steam client directly out of the same location as the gulp file watcher. The steam client will attempt to sync new files on the server back down to your local workspace.

Getting Started

After you create a spawn, this bot will create 4 creeps which will start to harvest the closest source. The bots harvest, then transfer energy back to Spawn. If a creep's lifespan has depleted enough, it will refill in Spawn.

Requirements

  • Node.js (v4.0.0+)
  • Gulp - npm install -g gulp
  • TypeScript - npm install -g typescript
  • Typings - npm install -g typings

Quick setup

First, create a copy of config.example.json and rename it to config.json.

$ cp config.example.json config.json

Then change the username and password properties with your Screeps credentials.

If you want to push your code to another branch, for example, if you have some sort of a staging branch where you test around in Simulation mode, we have left a branch option for you to easily change the target branch of the upload process. The default branch is set as the default.

WARNING: DO NOT commit this file into your repository!

Then run the following the command to install the required npm packages and TypeScript type definitions.

$ npm install

Running the compiler

# To compile your TypeScript files on the fly
$ npm start

# To deploy the code to Screeps
$ npm run deploy

Notes

The noImplicitAny compiler flag

TypeScript developers disagree about whether the noImplicitAny flag should be true or false. There is no correct answer and you can change the flag later. But your choice now can make a difference in larger projects so it merits discussion.

When the noImplicitAny flag is false (the default), the compiler silently defaults the type of a variable to any if it cannot infer the type based on how the variable is used.

When the noImplicitAny flag is true and the TypeScript compiler cannot infer the type, it still generates the JavaScript files. But it also reports an error. Many seasoned developers prefer this stricter setting because type checking catches more unintentional errors at compile time.

In this starter kit, the noImplicitAny compiler flag is set to false to make it easier for beginners. If you want a more stricter environment, you can change the noImplicitAny flag to true on the tsconfig.json file.

Source: https://angular.io/docs/ts/latest/guide/typescript-configuration.html

TSLint

TSLint checks your TypeScript code for readability, maintainability, and functionality errors, and can also enforce coding style standards.

After each successful compiling of the project, TSLint will parse the TypeScript source files and display a warning for any issues it will find.

This project provides TSLint rules through a tslint.json file, which extends the recommended set of rules from TSLint github repository: https://github.com/palantir/tslint/blob/next/src/configs/recommended.ts

We made some changes to those rules, which we considered necessary and/or relevant to a proper Screeps project:

  • set the forin rule to false, it was forcing for ( ... in ...) loops to check if object members were not coming from the class prototype.
  • set the interface-name rule to false, in order to allow interfaces that are not prefixed with I.
  • set the no-console rule to false, in order to allow using console.
  • in the variable-name rule, added allow-leading-underscore.

If you believe that some rules should not apply to a part of your code, you can use flags to let TSLint know about it: https://palantir.github.io/tslint/usage/rule-flags/

More info about TSLint: https://palantir.github.io/tslint/

Contributing

  1. Fork it
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Create a new Pull Request

Special thanks

Marko Sulamägi, for the original Screeps/TypeScript sample project.

About

Starter kit for TypeScript-based Screeps AI codes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 57.2%
  • JavaScript 42.8%