Creating a new node type

Started by Stereodude, October 27, 2018, 03:23:12 PM

Stereodude

In order to create a new node type what files need to be edited?  From reading the documentation I know I need to edit metrics.js, but is that the only file necessary to change?

Edit:  I decided to just try it and I can confirm that a new node type can be made with only changes to metrics.js though you may want to make a new icon and drop it in the www/images/ folder.

Felix

That is correct,
The node and metrics definitions (those defaults) are in metrics.js.
I would recommend keeping your custom node types and metrics defined in the userMetrics folder, follow the given _example.js:

exports.motes = {
  CustomMote: {

You can copy paste an existing node type and make your changes there.
This way upgrading versions is easier as your custom stuff is stored separately.

Stereodude

Quote from: Felix on October 29, 2018, 10:49:34 AM
That is correct,
The node and metrics definitions (those defaults) are in metrics.js.
I would recommend keeping your custom node types and metrics defined in the userMetrics folder, follow the given _example.js:

exports.motes = {
  CustomMote: {

You can copy paste an existing node type and make your changes there.
This way upgrading versions is easier as your custom stuff is stored separately.

Thanks for the reply.  I didn't notice the userMetrics folder.  I switched my new node type to a separate .js file in that folder and removed it from metrics.js.

It seems that according to the log file that _example.js is parsed so it overrides some of the defaults in metrics.js.

[10-29-18_13:28:45.880] [INFO]   LOADING USER METRICS...
[10-29-18_13:28:45.892] [INFO]   LOADING USER METRICS MODULE [_example.js]

Felix

Yes it will merge/override what you add in your userMetrics folder. The _example file is just an example, you can separate them by file, or just dump everything you need in 1 file, up to you. The gateway app just merges everything it finds in userMetrics folder, so all .js files have to have the format of the _example file.

This way you can override default nodes, if you need/want to change anything about them.