Initial commit
This commit is contained in:
commit
53be595352
9 changed files with 1134 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/node_modules/
|
||||
/dist/
|
||||
/screeps.json
|
13
README.md
Normal file
13
README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
This is a template / example repository for using TypeScript for Screeps
|
||||
|
||||
To get started, install [Node](https://nodejs.org/en/download/) and run `npm install` in this folder
|
||||
|
||||
Now you can edit the source files in `src/` and build using `npm run build`. To get faster build times (and to not manually start building all the time) you can use `npm watch` to start building in watch mode. This way, everytime a source code file is changed the compiler will run automatically
|
||||
|
||||
Your code will be compiled into a single file `dist/main.js` for easier uploading
|
||||
|
||||
## Automatic uploading
|
||||
|
||||
To automatically upload your generated files to Screeps World or your private server, copy `screeps.example.json` to `screeps.json` and fill in your data
|
||||
|
||||
Then, you can run `npm run push` to build and upload your script. As a bonus, `npm run watch-push` is also available to automatically upload any changes made to the source files
|
1001
package-lock.json
generated
Normal file
1001
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
22
package.json
Normal file
22
package.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "screeps-template",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"build": "rollup --config --configPlugin=typescript",
|
||||
"watch": "rollup -c --configPlugin=typescript --watch",
|
||||
"push": "rollup --config=rollup.config.push.ts --configPlugin=typescript",
|
||||
"watch-push": "rollup --config=rollup.config.push.ts --configPlugin=typescript --watch"
|
||||
},
|
||||
"author": "Kascheml",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@kascheml/screeps-types": "^0.0.2",
|
||||
"@rollup/plugin-typescript": "^10.0.1",
|
||||
"@types/rollup": "^0.54.0",
|
||||
"rollup": "^3.5.1",
|
||||
"rollup-plugin-screeps": "^1.0.1",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^4.9.3"
|
||||
}
|
||||
}
|
11
rollup.config.push.ts
Normal file
11
rollup.config.push.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import screeps from "rollup-plugin-screeps";
|
||||
import type { InputPluginOption } from "rollup";
|
||||
import { create } from "./rollup.config";
|
||||
|
||||
const pushConfig = create();
|
||||
|
||||
(pushConfig.plugins as InputPluginOption[]).push(screeps({
|
||||
configFile: "./screeps.json"
|
||||
}));
|
||||
|
||||
export default pushConfig;
|
15
rollup.config.ts
Normal file
15
rollup.config.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import type { RollupOptions } from "rollup";
|
||||
import typescript from "@rollup/plugin-typescript";
|
||||
|
||||
export function create(): RollupOptions {
|
||||
return {
|
||||
input: "src/index.ts",
|
||||
output: {
|
||||
file: "dist/main.js",
|
||||
format: "commonjs"
|
||||
},
|
||||
plugins: [typescript()]
|
||||
};
|
||||
}
|
||||
|
||||
export default create();
|
9
screeps.example.json
Normal file
9
screeps.example.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"email": "example@example.org",
|
||||
"password": "p455w0rD",
|
||||
"protocol": "https",
|
||||
"hostname": "screeps.com",
|
||||
"port": 443,
|
||||
"path": "/",
|
||||
"branch": "auto"
|
||||
}
|
35
src/index.ts
Normal file
35
src/index.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
let max = Object.getOwnPropertyNames(Game.creeps)
|
||||
.map(name => /([0-9]+)[^0-9]*$/.exec(name))
|
||||
.filter(match => match !== null)
|
||||
.map(match => parseInt((match as RegExpMatchArray)[1]))
|
||||
.sort()
|
||||
.pop() ?? 0;
|
||||
|
||||
const directions = [
|
||||
TOP,
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT,
|
||||
];
|
||||
|
||||
export function loop() {
|
||||
for (const spawnName in Game.spawns) {
|
||||
if (Game.spawns[spawnName].spawning !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Game.spawns[spawnName].spawnCreep([MOVE], `Creep${max + 1}`) === OK) {
|
||||
++max;
|
||||
console.log(`Creep${max} has been spawned`)
|
||||
}
|
||||
}
|
||||
|
||||
for (const creepName in Game.creeps) {
|
||||
Game.creeps[creepName].move(directions[Math.floor(Math.random() * directions.length)]);
|
||||
Game.creeps[creepName].say(`Me ${creepName}`);
|
||||
}
|
||||
}
|
25
tsconfig.json
Normal file
25
tsconfig.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2018",
|
||||
"lib": [
|
||||
"ES2018"
|
||||
],
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib/",
|
||||
"types": [
|
||||
"@kascheml/screeps-types"
|
||||
],
|
||||
"noEmit": true
|
||||
},
|
||||
"include": [
|
||||
"src/",
|
||||
"rollup.config*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules/"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue