npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@brisberg/screeps-server-mockup

v1.6.6

Published

_Based on https://github.com/screepers/screeps-server-test_

Downloads

13

Readme

screeps-server-mockup

Based on https://github.com/screepers/screeps-server-test

Private server package for unit tests

This is a project that runs the screeps private server one tick at a time, allowing to easily check data in between ticks and opens the possibilities for automatic testings in a reproductible environment.

Requirements

These are necessary to build the internal Screeps server.

  • Node.js 10 LTS or higher
  • Python (for node-gyp)
  • Build tools (apt install build-essential for Ubuntu, Visual Studio for Windows, etc)

Usage

  1. Install via npm or yarn
  2. Write a test script (see examples and tests folders for details)
  3. Run the test script

Script example (simple)

const _ = require('lodash');
const { ScreepsServer, TerrainMatrix } = require('screeps-server-mockup');

// Initialize server
const server = new ScreepsServer();
await server.world.reset();     // reset world but add invaders and source keepers users
await server.world.stubWorld(); // create a stub world composed of 9 rooms with sources and controller

// Add a bot in W0N1
const modules = {
    main: `module.exports.loop = function() {
        console.log('Tick!',Game.time);
        const directions = [TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, LEFT, TOP_LEFT];
        _.sample(Game.spawns).createCreep([MOVE]);
        _.each(Game.creeps, c => c.move(_.sample(directions)));
    };`
};
const bot = await server.world.addBot({ username: 'bot', room: 'W0N1', x: 15, y: 15, modules });

// Start server and run a tick
await server.start();
await server.tick();

Script example (complete)

const _ = require('lodash');
const { ScreepsServer, TerrainMatrix } = require('screeps-server-mockup');

// Initialize server
const server = new ScreepsServer();
await server.world.reset(); // reset world but add invaders and source keepers users

// Prepare the terrain for a new room
const terrain = new TerrainMatrix();
const walls = [[10, 10], [10, 40], [40, 10], [40, 40]];
_.each(walls, ([x, y]) => terrain.set(x, y, 'wall'));

// Create a new room with terrain and basic objects
await server.world.addRoom('W0N1');
await server.world.setTerrain('W0N1', terrain);
await server.world.addRoomObject('W0N1', 'controller', 10, 10, { level: 0 });
await server.world.addRoomObject('W0N1', 'source', 10, 40, { energy: 1000, energyCapacity: 1000, ticksToRegeneration: 300 });
await server.world.addRoomObject('W0N1', 'mineral', 40, 40, { mineralType: 'H', density: 3, mineralAmount: 3000 });

// Add a bot in W0N1
const modules = {
    main: `module.exports.loop = function() {
        console.log('Tick!',Game.time);
        const directions = [TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, LEFT, TOP_LEFT];
        _.sample(Game.spawns).createCreep([MOVE]);
        _.each(Game.creeps, c => c.move(_.sample(directions)));
    };`
};
const bot = await server.world.addBot({ username: 'bot', room: 'W0N1', x: 25, y: 25, modules });

// Print console logs every tick
bot.on('console', (logs, results, userid, username) => {
    _.each(logs, line => console.log(`[console|${username}]`, line));
});

// Start server and run several ticks
await server.start();
for (let i = 0; i < 10; i++) {
    console.log('[tick]', await server.world.gameTime);
    await server.tick();
    _.each(await bot.newNotifications, ({ message }) => console.log('[notification]', message));
    console.log('[memory]', await bot.memory, '\n');
}

// Stop server and disconnect storage
server.stop();
process.exit(); // required as there is no way to properly shutdown storage :(

Each tick should output something like:

[tick] 1

[console|bot] Tick! 1

[memory] {"creeps":{"Arianna":{}}}

Tests

yarn lint // or npm run lint
yarn test // or npm run test