Change to new preprocessor style

This commit is contained in:
Cooldude2606 committed 2024-02-27 23:07:38 +00:00
1 parent ec19d5456e
commit 62abfa903b
37 files changed
+692 -2193

No files matched your search

@@ -1,26 +1,38 @@
"use strict";
const lib = require("@clusterio/lib");
const { BaseControllerPlugin } = require("@clusterio/controller");
const { PluginExampleEvent, PluginExampleRequest,/*/ [subscribable] /*/ ExampleSubscribableUpdate, ExampleSubscribableValue/*/ [] /*/ } = require("./messages");
class ControllerPlugin extends BaseControllerPlugin {// [subscribable] //
const {
PluginExampleEvent, PluginExampleRequest,
//%if controller & web // Subscribing requires web content and the controller
ExampleSubscribableUpdate, ExampleSubscribableValue,
//%endif
} = require("./messages");
class ControllerPlugin extends BaseControllerPlugin {
//%if controller & web // Subscribing requires web content and the controller
exampleDatabase;
storageDirty = false;
// [] //
//%endif
async init() {
this.controller.handle(PluginExampleEvent, this.handlePluginExampleEvent.bind(this));
this.controller.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));// [subscribable] //
this.controller.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));
//%if controller & web // Subscribing requires web content and the controller
this.controller.subscriptions.handle(ExampleSubscribableUpdate, this.handleExampleSubscription.bind(this));
this.exampleDatabase = new Map(); // If needed, replace with loading from database file // [] //
this.exampleDatabase = new Map(); // If needed, replace with loading from database file
//%endif
}
async onControllerConfigFieldChanged(field, curr, prev) {
this.logger.info(`controller::onControllerConfigFieldChanged ${field}`);
}// [instance] //
}
//%if instance
async onInstanceConfigFieldChanged(instance, field, curr, prev) {
this.logger.info(`controller::onInstanceConfigFieldChanged ${instance.id} ${field}`);
}// [] //
}
//%endif
async onSaveData() {
this.logger.info("controller::onSaveData");
@@ -44,14 +56,16 @@ class ControllerPlugin extends BaseControllerPlugin {// [subscribable] //
myResponseString: request.myString,
myResponseNumbers: request.myNumberArray,
};
}// [subscribable] //
}
//%if controller & web // Subscribing requires web content and the controller
async handleExampleSubscription(request) {
const values = [...this.exampleDatabase.values()].filter(
value => value.updatedAtMs > request.lastRequestTimeMs,
);
return values.length ? new ExampleSubscribableUpdate(values) : null;
}// [] //
}
//%endif
}
module.exports = {