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,25 +1,37 @@
import * as lib from "@clusterio/lib";
import { BaseControllerPlugin, InstanceInfo } from "@clusterio/controller";
import { PluginExampleEvent, PluginExampleRequest,/*/ [subscribable] /*/ ExampleSubscribableUpdate, ExampleSubscribableValue/*/ [] /*/ } from "./messages";
export class ControllerPlugin extends BaseControllerPlugin {// [subscribable] //
import {
PluginExampleEvent, PluginExampleRequest,
//%if controller & web // Subscribing requires web content and the controller
ExampleSubscribableUpdate, ExampleSubscribableValue,
//%endif
} from "./messages";
export class ControllerPlugin extends BaseControllerPlugin {
//%if controller & web // Subscribing requires web content and the controller
exampleDatabase!: Map<string, ExampleSubscribableValue>;
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();// [] //
this.exampleDatabase = new Map(); // If needed, replace with loading from database file
//%endif
}
async onControllerConfigFieldChanged(field: string, curr: unknown, prev: unknown) {
this.logger.info(`controller::onControllerConfigFieldChanged ${field}`);
}// [instance] //
}
//%if instance
async onInstanceConfigFieldChanged(instance: InstanceInfo, field: string, curr: unknown, prev: unknown) {
this.logger.info(`controller::onInstanceConfigFieldChanged ${instance.id} ${field}`);
}// [] //
}
//%endif
async onSaveData() {
this.logger.info("controller::onSaveData");
@@ -43,12 +55,14 @@ export 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: lib.SubscriptionRequest) {
const values = [...this.exampleDatabase.values()].filter(
value => value.updatedAtMs > request.lastRequestTimeMs,
);
return values.length ? new ExampleSubscribableUpdate(values) : null;
}// [] //
}
//%endif
}