Skip to content

Commit

Permalink
Merge pull request #793 from The-International-Screeps-Bot/Development
Browse files Browse the repository at this point in the history
New minor version(s)
  • Loading branch information
CarsonBurke authored May 24, 2024
2 parents a0b7b98 + fe779d3 commit 2c6a9a8
Show file tree
Hide file tree
Showing 211 changed files with 74,902 additions and 71,833 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/CD-Long.yml

This file was deleted.

9 changes: 7 additions & 2 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ jobs:
run: hostname -I
- name: Install dependencies
run: npm install
- name: Setup required files
run: node helper/preBuild.js
- name: Build bot
run: npm run build
- name: Start instances
run: node server --maxTicks=25000 --debug --tickDuration=5000
run: node helper/server --maxTicks=25000 --debug --tickDuration=10
env:
STEAM_API_KEY: ${{ secrets.STEAM_API_KEY }}
EXPORT_API_URL: ${{ secrets.EXPORT_API_URL }}
EXPORT_DISCORD_WEBHOOK_URL: ${{ secrets.EXPORT_DISCORD_WEBHOOK_URL }}
EXPORT_PASTEBIN_KEY: ${{ secrets.EXPORT_PASTEBIN_KEY }}
ACTIONS_RUNNER_NAME: ${{ runner.name }}
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [10.x,12.x,14.x,16.x]
node: [10.x,12.x,14.x,16.x,18.x,20.x]
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -23,5 +23,5 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm install
- run: npm run build --if-present
# - run: npm run test
- run: node helper/preBuild.js
- run: npm run build
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ collectivizer.ts

src/other/userScript/*
!userScript.example.ts
settings.ts
src/settings.ts
.screeps.yaml

# wasm-pack always puts a .gitignore in here; if you want to not ignore it,
Expand Down
63 changes: 32 additions & 31 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
{
"[javascript]": {
"editor.formatOnSave": false
},
"[json]": {
"editor.formatOnSave": true
},
"[typescript]": {
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"editor.renderWhitespace": "none",
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"search.exclude": {
"_book/**": true,
".rpt2_cache/**": true,
"dist/**": true,
"node_modules/**": true,
"typings/**": true
},
"typescript.tsdk": "./node_modules/typescript/lib",
"eslint.enable": true,
"git.ignoreLimitWarning": true,
"spellright.language": ["en"],
"spellright.documentTypes": ["latex", "plaintext"],
"compile-hero.disable-compile-files-on-did-save-code": true,
"editor.tabSize": 2
"[javascript]": {
"editor.formatOnSave": false
},
"[json]": {
"editor.formatOnSave": true
},
"[typescript]": {
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"editor.renderWhitespace": "none",
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"search.exclude": {
"_book/**": true,
".rpt2_cache/**": true,
"dist/**": true,
"node_modules/**": true,
"typings/**": true
},
"typescript.tsdk": "./node_modules/typescript/lib",
"eslint.enable": true,
"git.ignoreLimitWarning": true,
"spellright.language": ["en"],
"spellright.documentTypes": ["latex", "plaintext"],
"compile-hero.disable-compile-files-on-did-save-code": true,
"editor.tabSize": 4,
"editor.detectIndentation": false
}
88 changes: 88 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Overview

This document should outline the design strategies and guidelines for the bot.

The bot intends to implement a primarily data-oriented style, with some aspects of functional, imparative and object oriented design.

# Data/functional structures

## Utils
- a static class
- does not contain any state
- contains functions/methods
- acts on singular inputs

Utils stands for utilities. These are functions that will generally take inputs and provide information in return.

### Example

CommuneUtils contains utility functions that provide often cached information on call that helps with processing

## Procs
- a static class
- does not contain any state
- contains functions/methods
- acts on singular inputs

Procs stands for processors. These are functions that will generally run logic for specified things.

### Example

CommuneProc runs logic for the commune to update data, make intents, and run sub processes like towers, spawning, creeps, etc.

## Ops
- a static class
- does not contain any state
- contains functions/methods
- acts on singular inputs

Ops stands for Operations. These are functions that will run logic for specified things, sometimes retrieving values.

### Example

HaulerNeedOps contians functions that provide cached information, carry out processes, or whatever else.

## Services
- a static class
- does not contain any state
- contains function/methods
- acts on plural inputs

Services run plural inputs, which in turn are generally ran through procs and utils.

### Example

RoomServices contains functions that runs logic for a list of rooms.

## Manager
- a static class
- can contain state
- contains functions/methods
- should generally be avoided given its combination of data and functions, which breaks data-oriented design ideals

Managers can be a combination of utilities, processors and data.

## Data

A state or set of states generally contained in an object. Should not include functions

should probably be opperated on by Procs.

### Example

The MarketManager handles caching market related data, updating / deleting it as needed, while pruning and optimizing existing orders that the bot controls.

## Use of classes

Classes should be static, and static classes should not be instantiated. If a class "needs" to be instantiated, there is probably a better way to do it.

Inherence of classes should be avoided.
classes should no contain state and alter state. They should do only one or the other.

# Creep Tasks

Allows creeps to track general inter-tick actions that are desired for fulfillment

## Task Runners

Task runners decide what actions to take based on the task data provided. Besides running tasks, runners may delete tasks, stop additional tasks to be ran, and more
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ First you'll want to download or fork the repository. Start by selecting a branc

Ensure you have downloaded [Node](https://nodejs.org/en/)

**Make sure your node version is below 17.0.0**
**Consider using Node version if 20.10.0 if you have issues**

You can check your node version with:

Expand All @@ -64,7 +64,6 @@ After making sure you have correct node version go to the project folder (not in

```powershell
npm i
```

And that's it. Join our [discord server](https://discord.gg/5QubDsB786) if you need help.
Expand All @@ -81,6 +80,8 @@ Using [rollup](https://rollupjs.org/guide/en/) we will translate the code into a

First, you'll need to set up your settings. In `/src` you'll find the `settings.example.ts` file. Please copy the file and rename its clone to `settings.ts`. Then change the `settingsExample` definition to `settings`. You can then add your own prefences, including checks based on the name of the shard for server-specific settings. These same instructions with an example are included in the file.

Head to `src/other/userScript/userScript.example.ts` and follow the instructions at the top of the file. It will be very similar to settings up `settings.ts`.

Next, rename `.screeps.yaml.example` to `.screeps.yaml` and fill in the required information for each environment you want to run the bot in. For the official server, replace the `token` with an [API token](https://docs.screeps.com/auth-tokens.html) for your account. On private servers, edit _(or copy and rename)_ the `pserver` section with `host` set to your server domain or IP then complete `username` and `password` with your credentials on this server. For more information about this file, check the [screeps unified credentials file](https://github.com/screepers/screepers-standards/blob/master/SS3-Unified_Credentials_File.md) spec.

Running `rollup -c` will compile your code and do a "dry run", preparing the code for upload but not actually pushing it. Running `rollup -c --environment DEST:mmo` will compile your code, and then upload it to a screeps server using the `mmo` config from `.screeps.yaml`.
Expand Down Expand Up @@ -110,7 +111,7 @@ I'd also suggest using this less-laggy tool [steamless-client](https://github.co

### Advanced usage

If you want to run custom code without conflicting with the project's source - say, if you want to commit or make pull requests - it's recommended you use the userScript folder. Head to `src/other/userScript/userScript.example.ts` and follow the instructions at the top of the file.
If you want to run custom code without conflicting with the project's source - say, if you want to commit or make pull requests - it's recommended you use the userScript folder.

## Contribution

Expand Down
12 changes: 12 additions & 0 deletions helper/preBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require('fs')

fs.copyFileSync('src/settings.example.ts', 'src/settings.ts')
fs.copyFileSync('src/other/userScript/userScript.example.ts', 'src/other/userScript/userScript.ts')

const settings = fs.readFileSync('src/settings.ts', 'utf8')
const newSettings = settings.replace(/Example/g, '',)
fs.writeFileSync('src/settings.ts', newSettings)

const userScript = fs.readFileSync('src/other/userScript/userScript.ts', 'utf8')
const newUserScript = userScript.replace(/Example/g, '')
fs.writeFileSync('src/other/userScript/userScript.ts', newUserScript)
26 changes: 14 additions & 12 deletions server.js → helper/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { join } = require('path')
const { execSync } = require('child_process')
require('dotenv').config()
const minimist = require('minimist')
const fs = require('fs')

const argv = minimist(process.argv.slice(2))

Expand All @@ -25,20 +26,21 @@ function getPorts() {
const ports = getPorts()

const options = { stdio: 'inherit' }
const botPath = join(__dirname, 'dist')
const botPath = join(__dirname, '../dist')
console.log('START')
// execSync(
// `npx screeps-grafana-go_carbon setup && npx screeps-grafana-go_carbon --grafanaPort=${ports.grafanaPort} --relayPort=${ports.relayPort} --force ${argv.debug ? '--debug' : ''} --deleteLogs --deleteWhisper`,
// options,
// )

const cmdString = `npx screeps-performance-server --maxTickCount=${argv.maxTicks || 20000} --maxBots=10 --botFilePath=${botPath} --steamKey=${
process.env.STEAM_API_KEY
} --discordWebHookUrl=${process.env.EXPORT_DISCORD_WEBHOOK_URL} --pasteBinUrlDevKey=${process.env.EXPORT_PASTEBIN_KEY} --serverPort=${ports.serverPort} --cliPort=${ports.cliPort} --force ${
argv.debug ? '--debug' : ''
} --deleteLogs --tickDuration=${argv.tickDuration || 250} --logFilter='Error:'`;
execSync(
`npx screeps-grafana-go_carbon setup && npx screeps-grafana-go_carbon --grafanaPort=${ports.grafanaPort} --relayPort=${ports.relayPort} --force ${argv.debug ? '--debug' : ''} --deleteLogs --deleteWhisper`,
options,
)
execSync('npm run build', options)
execSync(
`npx screeps-performance-server --maxTickCount=${argv.maxTicks || 20000} --maxBots=10 --botFilePath=${botPath} --steamKey=${
process.env.STEAM_KEY
} --exportUrl=${process.env.EXPORT_API_URL} --serverPort=${ports.serverPort} --cliPort=${ports.cliPort} --force ${
argv.debug ? '--debug' : ''
} --deleteLogs --tickDuration=${argv.tickDuration || 250} --logFilter='Error:'`,
cmdString,
options,
)
if (argv.stopGrafana) execSync('npx screeps-grafana stop')
// if (argv.stopGrafana) execSync('npx screeps-grafana stop')
console.log('END')
Loading

0 comments on commit 2c6a9a8

Please sign in to comment.