Initial commit
This commit is contained in:
commit
89e29876f9
8 changed files with 1115 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 JavaScript 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
|
1010
package-lock.json
generated
Normal file
1010
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
21
package.json
Normal file
21
package.json
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"name": "screeps-template",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"scripts": {
|
||||||
|
"build": "rollup --config",
|
||||||
|
"watch": "rollup -c --watch",
|
||||||
|
"push": "rollup --config=rollup.config.push.js",
|
||||||
|
"watch-push": "rollup --config=rollup.config.push.js --watch"
|
||||||
|
},
|
||||||
|
"author": "Kascheml",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "module",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
14
rollup.config.js
Normal file
14
rollup.config.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* @returns {import('rollup').RollupOptions}
|
||||||
|
*/
|
||||||
|
export function create() {
|
||||||
|
return {
|
||||||
|
input: "src/index.js",
|
||||||
|
output: {
|
||||||
|
file: "dist/main.js",
|
||||||
|
format: "commonjs"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default create();
|
10
rollup.config.push.js
Normal file
10
rollup.config.push.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import screeps from "rollup-plugin-screeps";
|
||||||
|
import { create } from "./rollup.config.js";
|
||||||
|
|
||||||
|
const pushConfig = create();
|
||||||
|
|
||||||
|
pushConfig.plugins = [screeps({
|
||||||
|
configFile: "./screeps.json"
|
||||||
|
})];
|
||||||
|
|
||||||
|
export default pushConfig;
|
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.js
Normal file
35
src/index.js
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))
|
||||||
|
.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}`);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue