1 | var common = require('@screeps/common');
|
2 |
|
3 | var help = `The supported commands are:\r
|
4 | * help() - Print this help text.\r
|
5 | * print(value) - Print a value to the console.\r
|
6 | * storage - A global database storage object.\r
|
7 | * map - Map editing functions.\r
|
8 | * bots - Manage NPC bot players and their AI scripts.\r
|
9 | * system - System utility functions.\r
|
10 | Type help(object) to learn more about specific usage of the object.`;
|
11 |
|
12 | var storageHelp = {
|
13 | main: `This is the main storage object that allows to perform direct operations on the game database. It contains 3 sub-objects:\r
|
14 | * db - An object containing all database collections in it. Use it to fetch or modify game objects. The database is based on LokiJS project, so you can learn more about available functionality in its documentation.
|
15 | * env - A simple key-value storage with an interface based on Redis syntax.\r
|
16 | * pubsub - A Pub/Sub mechanism allowing to publish events across all processes.`,
|
17 | db: `Database collections: \r
|
18 | ${Object.keys(common.storage.db).map(i => ' - '+i).join('\r\n')}\r
|
19 | Available methods: \r
|
20 | ${Object.keys(common.storage.db.users).map(i => ' - '+i).join('\r\n')}\r
|
21 | Example: storage.db.users.findOne({username: 'User1'}).then(print);`,
|
22 | env: `Keys ('storage.env.keys' object): \r
|
23 | ${Object.keys(common.storage.env.keys).map(i => ' - '+i).join('\r\n')}\r
|
24 | Available methods:\r
|
25 | - get\r
|
26 | - mget\r
|
27 | - set\r
|
28 | - setex\r
|
29 | - expire\r
|
30 | - ttl\r
|
31 | - del\r
|
32 | - hmset\r
|
33 | Example: storage.env.get(storage.env.keys.GAMETIME).then(print);`,
|
34 | pubsub: `Keys ('storage.pubsub.keys' object): \r
|
35 | ${Object.keys(common.storage.pubsub.keys).map(i => ' - '+i).join('\r\n')}\r
|
36 | Available methods:\r
|
37 | - publish\r
|
38 | - subscribe\r
|
39 | Example: storage.pubsub.subscribe(storage.pubsub.keys.ROOMS_DONE, (gameTime) => print(gameTime));`
|
40 | };
|
41 |
|
42 |
|
43 |
|
44 | function helpFn(object) {
|
45 | if(object === undefined) {
|
46 | return help;
|
47 | }
|
48 | if(object === this.storage) {
|
49 | return storageHelp.main;
|
50 | }
|
51 | if(object === this.storage.db) {
|
52 | return storageHelp.db;
|
53 | }
|
54 | if(object === this.storage.env) {
|
55 | return storageHelp.env;
|
56 | }
|
57 | if(object === this.storage.pubsub) {
|
58 | return storageHelp.pubsub;
|
59 | }
|
60 | if(object._help) {
|
61 | return object._help;
|
62 | }
|
63 | return 'There is no help page for this object.';
|
64 | }
|
65 |
|
66 | module.exports = function cliHelp(sandbox) {
|
67 | sandbox.help = helpFn.bind(sandbox);
|
68 | }; |
\ | No newline at end of file |