Skip to content

Custom Module Overrides

Liam edited this page Mar 24, 2017 · 5 revisions

It is possible to have your own custom changes to the code without touching the original files.
Let's take a common case and assume you want to make individual changes on the parameter file.

Option 1: Full file override

You can create a custom module. To do this, copy file parameter.js and rename it to custom.parameter.js. Make changes to your new file and deploy to screeps. To save some cpu, the program will not look for new custom overrides automatically. To tell it to do so call getPath('parameter', true) from the console. The response should be ./custom.parameter.

You can do this for every file, except main.js.

If you push commits to the repository your custom.* files will be ignored.

Option 2: Partial override

The problem with full file overrides is you always have to copy the whole file, even if you only want to change a little piece of it. Even worse, when there is an update on the common file you need to manually update your custom file.

To provide a finer solution for this, you can also create a partial override containing only the difference to the common file. This works only on properties of the returned module object, this can be functions or values.

Lets take our parameter file sample. Lets say you only want to change one property (like CENSUS_ANNOUNCEMENTS = false to give some peace to the console).

Create a new file, name it viral.parameter.js and write:

var mod = {
    CENSUS_ANNOUNCEMENTS: false
}
module.exports = mod;

Now deploy that to screeps and, again, call getPath('parameter', true) from the console. The response will always be the name of the base file (./parameter or ./custom.parameter). But your viral infection of that file arrived.

In the event the item you want to override is an object, for example VISUALS in parameters, and you don't want to copy the whole object (as that would resolve the left out variables as undefined), you only need to specify the keys you wish to change:

const mod = {
    VISUALS: {
        LABS: false,
    },
};
module.exports = mod;

The above would only change VISUALS.LABS instead of VISUALS.* making it easier for you to override only what you want.

You can do this for every file, except main.js.

If you push commits to the repository your viral.* files will be ignored.