mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Add js templates and config templates
This commit is contained in:
23 files changed
+543
-50
No files matched your search
@@ -0,0 +1,3 @@
|
||||
dist/
|
||||
node_modules/
|
||||
package-lock.json
|
||||
@@ -0,0 +1,2 @@
|
||||
webpack.config.js
|
||||
dist/web/build
|
||||
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
const lib = require("@clusterio/lib");
|
||||
const { BaseControllerPlugin } = require("@clusterio/controller");
|
||||
const { PluginExampleEvent, PluginExampleRequest } = require("./messages");
|
||||
|
||||
class ControllerPlugin extends BaseControllerPlugin {
|
||||
async init() {
|
||||
this.controller.handle(PluginExampleEvent, this.handlePluginExampleEvent.bind(this));
|
||||
this.controller.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));
|
||||
}
|
||||
|
||||
async onControllerConfigFieldChanged(field, curr, prev) {
|
||||
this.logger.info(`controller::onControllerConfigFieldChanged ${field}`);
|
||||
}// [instance] //
|
||||
|
||||
async onInstanceConfigFieldChanged(instance, field, curr, prev) {
|
||||
this.logger.info(`controller::onInstanceConfigFieldChanged ${instance.id} ${field}`);
|
||||
}// [] //
|
||||
|
||||
async onSaveData() {
|
||||
this.logger.info("controller::onSaveData");
|
||||
}
|
||||
|
||||
async onShutdown() {
|
||||
this.logger.info("controller::onShutdown");
|
||||
}
|
||||
|
||||
async onPlayerEvent(instance, event) {
|
||||
this.logger.info(`controller::onPlayerEvent ${instance.id} ${JSON.stringify(event)}`);
|
||||
}
|
||||
|
||||
async handlePluginExampleEvent(event) {
|
||||
this.logger.info(JSON.stringify(event));
|
||||
}
|
||||
|
||||
async handlePluginExampleRequest(request) {
|
||||
this.logger.info(JSON.stringify(request));
|
||||
return {
|
||||
myResponseString: request.myString,
|
||||
myResponseNumbers: request.myNumberArray,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ControllerPlugin,
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
const { BaseCtlPlugin } = require("@clusterio/ctl");
|
||||
const { CommandTree, Command } = require("@clusterio/lib");
|
||||
const { PluginExampleEvent, PluginExampleRequest } = require("./messages");
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const pluginCommands = new CommandTree({
|
||||
name: "// plugin_name //", description: "The default description I forgot to change",
|
||||
});
|
||||
|
||||
pluginCommands.add(new Command({
|
||||
definition: ["my-command <foo>", "My command description that I really should change", (yargs) => {
|
||||
yargs.positional("foo", { describe: "foo is foo!", type: "string" });
|
||||
}],
|
||||
handler: async function(args, control) {
|
||||
const response = await control.sendTo("controller", new PluginExampleRequest(args.foo, [1, 2, 3]));
|
||||
console.log(response);
|
||||
console.log(args);
|
||||
},
|
||||
}));
|
||||
|
||||
/* eslint-enable no-console */
|
||||
class CtlPlugin extends BaseCtlPlugin {
|
||||
async addCommands(rootCommand) {
|
||||
rootCommand.add(pluginCommands);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
CtlPlugin,
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
const lib = require("@clusterio/lib");
|
||||
const { BaseHostPlugin } = require("@clusterio/host");
|
||||
const { PluginExampleEvent, PluginExampleRequest } = require("./messages");
|
||||
|
||||
class HostPlugin extends BaseHostPlugin {
|
||||
async init() {
|
||||
this.host.handle(PluginExampleEvent, this.handlePluginExampleEvent.bind(this));
|
||||
this.host.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));
|
||||
}
|
||||
|
||||
async onHostConfigFieldChanged(field, curr, prev) {
|
||||
this.logger.info(`host::onInstanceConfigFieldChanged ${field}`);
|
||||
}
|
||||
|
||||
async onShutdown() {
|
||||
this.logger.info("host::onShutdown");
|
||||
}
|
||||
|
||||
async handlePluginExampleEvent(event) {
|
||||
this.logger.info(JSON.stringify(event));
|
||||
}
|
||||
|
||||
async handlePluginExampleRequest(request) {
|
||||
this.logger.info(JSON.stringify(request));
|
||||
return {
|
||||
myResponseString: request.myString,
|
||||
myResponseNumbers: request.myNumberArray,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
HostPlugin,
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
const { PluginExampleEvent, PluginExampleRequest } = require("./messages");
|
||||
|
||||
lib.definePermission({
|
||||
name: "// plugin_name //.example.permission.event",
|
||||
title: "Example permission event",
|
||||
description: "My plugin's example permission that I forgot to remove",
|
||||
});
|
||||
|
||||
lib.definePermission({
|
||||
name: "// plugin_name //.example.permission.request",
|
||||
title: "Example permission request",
|
||||
description: "My plugin's example permission that I forgot to remove",
|
||||
});// [web] //
|
||||
|
||||
lib.definePermission({
|
||||
name: "// plugin_name //.page.view",
|
||||
title: "Example page view permission",
|
||||
description: "My plugin's example page permission that I forgot to remove",
|
||||
});// [] //
|
||||
|
||||
const plugin = {
|
||||
name: "// plugin_name //",
|
||||
title: "// plugin_name //",
|
||||
description: "I didn't update my description",
|
||||
// entry_points //
|
||||
// [controller] //
|
||||
controlConfigFields: {
|
||||
"// plugin_name //.myControllerField": {
|
||||
title: "My Controller Field",
|
||||
description: "This should be removed",
|
||||
type: "string",
|
||||
initialValue: "Remove Me",
|
||||
},
|
||||
},// [] //// [host] //
|
||||
hostConfigFields: {
|
||||
"// plugin_name //.myHostField": {
|
||||
title: "My Host Field",
|
||||
description: "This should be removed",
|
||||
type: "string",
|
||||
initialValue: "Remove Me",
|
||||
},
|
||||
},// [] //// [instance] //
|
||||
instanceConfigFields: {
|
||||
"// plugin_name //.myInstanceField": {
|
||||
title: "My Instance Field",
|
||||
description: "This should be removed",
|
||||
type: "string",
|
||||
initialValue: "Remove Me",
|
||||
},
|
||||
},// [] //
|
||||
|
||||
messages: [
|
||||
PluginExampleEvent,
|
||||
PluginExampleRequest,
|
||||
],
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
plugin,
|
||||
PluginExampleEvent,
|
||||
PluginExampleRequest,
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
const lib = require("@clusterio/lib");
|
||||
const { BaseInstancePlugin } = require("@clusterio/host");
|
||||
const { PluginExampleEvent, PluginExampleRequest } = require("./messages");
|
||||
|
||||
class InstancePlugin extends BaseInstancePlugin {
|
||||
async init() {
|
||||
this.instance.handle(PluginExampleEvent, this.handlePluginExampleEvent.bind(this));
|
||||
this.instance.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));
|
||||
}
|
||||
|
||||
async onInstanceConfigFieldChanged(field, curr, prev) {
|
||||
this.logger.info(`instance::onInstanceConfigFieldChanged ${field}`);
|
||||
}
|
||||
|
||||
async onStart() {
|
||||
this.logger.info("instance::onStart");
|
||||
}
|
||||
|
||||
async onStop() {
|
||||
this.logger.info("instance::onStop");
|
||||
}
|
||||
|
||||
async onPlayerEvent(event) {
|
||||
this.logger.info(`onPlayerEvent::onPlayerEvent ${JSON.stringify(event)}`);
|
||||
}
|
||||
|
||||
async handlePluginExampleEvent(event) {
|
||||
this.logger.info(JSON.stringify(event));
|
||||
}
|
||||
|
||||
async handlePluginExampleRequest(request) {
|
||||
this.logger.info(JSON.stringify(request));
|
||||
return {
|
||||
myResponseString: request.myString,
|
||||
myResponseNumbers: request.myNumberArray,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
InstancePlugin,
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
const { plainJson, jsonArray, JsonBoolean, JsonNumber, JsonString, StringEnum } = require("@clusterio/lib");
|
||||
const { Type, Static } = require("@sinclair/typebox");
|
||||
|
||||
class PluginExampleEvent {
|
||||
static type = "event";
|
||||
static src = ["host", "control"];
|
||||
static dst = ["controller", "host", "instance"];
|
||||
static plugin = "// plugin_name //";
|
||||
static permission = "// plugin_name //.example.permission.event";
|
||||
|
||||
constructor(myString, myNumberArray) {
|
||||
this.myString = myString;
|
||||
this.myNumberArray = myNumberArray;
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"myString": Type.String(),
|
||||
"myNumberArray": Type.Array(Type.Number()),
|
||||
});
|
||||
|
||||
static fromJson(json) {
|
||||
return new PluginExampleEvent(json.myString, json.myNumberArray);
|
||||
}
|
||||
}
|
||||
|
||||
class PluginExampleRequest {
|
||||
static type = "request";
|
||||
static src = ["host", "control"];
|
||||
static dst = ["controller", "host", "instance"];
|
||||
static plugin = "// plugin_name //";
|
||||
static permission = "// plugin_name //.example.permission.request";
|
||||
|
||||
constructor(myString, myNumberArray) {
|
||||
this.myString = myString;
|
||||
this.myNumberArray = myNumberArray;
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"myString": Type.String(),
|
||||
"myNumberArray": Type.Array(Type.Number()),
|
||||
});
|
||||
|
||||
static fromJson(json) {
|
||||
return new PluginExampleEvent(json.myString, json.myNumberArray);
|
||||
}
|
||||
|
||||
static Response = plainJson(Type.Object({
|
||||
"myResponseString": Type.String(),
|
||||
"myResponseNumbers": Type.Array(Type.Number()),
|
||||
}));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
PluginExampleEvent,
|
||||
PluginExampleRequest,
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
local clusterio_api = require("modules/clusterio/api")
|
||||
|
||||
local MyModule = {
|
||||
events = {},
|
||||
on_nth_tick = {},
|
||||
}
|
||||
|
||||
function MyModule.foo()
|
||||
game.print("foo")
|
||||
end
|
||||
|
||||
MyModule.events[clusterio_api.events.on_server_startup] = function(event)
|
||||
game.print(game.table_to_json(event))
|
||||
end
|
||||
|
||||
MyModule.events[defines.events.on_player_crafted_item] = function(event)
|
||||
game.print(game.table_to_json(event))
|
||||
end
|
||||
|
||||
MyModule.on_nth_tick[300] = function()
|
||||
game.print(game.tick)
|
||||
end
|
||||
|
||||
return MyModule
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "// plugin_name //",
|
||||
"load": [
|
||||
"control.lua"
|
||||
],
|
||||
"require": [
|
||||
|
||||
],
|
||||
"dependencies": [
|
||||
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
return require("./control")
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "// plugin_name //",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"prepare": "// prepare //"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@clusterio/lib": "^2.0.0-alpha.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
// dev_dependencies //
|
||||
"@clusterio/lib": "^2.0.0-alpha.14"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "^0.30.4"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"keywords": [
|
||||
"clusterio",
|
||||
"factorio"
|
||||
]
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,49 @@
|
||||
const { useContext, useEffect, useState } = require("react");
|
||||
// const { } = require("antd");
|
||||
|
||||
const {
|
||||
BaseWebPlugin, PageLayout, Control, ControlContext, notifyErrorHandler,
|
||||
} = require("@clusterio/web_ui");
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
const { PluginExampleEvent, PluginExampleRequest } = require("../messages");
|
||||
|
||||
function MyTemplatePage() {
|
||||
let control = useContext(ControlContext);
|
||||
|
||||
return <PageLayout nav={[{ name: "// plugin_name //" }]}>
|
||||
<h2>// plugin_name //</h2>
|
||||
</PageLayout>;
|
||||
}
|
||||
|
||||
class WebPlugin extends BaseWebPlugin {
|
||||
async init() {
|
||||
this.pages = [
|
||||
{
|
||||
path: "/// plugin_name //",
|
||||
sidebarName: "// plugin_name //",
|
||||
permission: "// plugin_name //.page.view",
|
||||
content: <MyTemplatePage/>,
|
||||
},
|
||||
];
|
||||
|
||||
this.control.handle(PluginExampleEvent, this.handlePluginExampleEvent.bind(this));
|
||||
this.control.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));
|
||||
}
|
||||
|
||||
async handlePluginExampleEvent(event) {
|
||||
this.logger.info(JSON.stringify(event));
|
||||
}
|
||||
|
||||
async handlePluginExampleRequest(request) {
|
||||
this.logger.info(JSON.stringify(request));
|
||||
return {
|
||||
myResponseString: request.myString,
|
||||
myResponseNumbers: request.myNumberArray,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
WebPlugin,
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.jsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "// plugin_name //",
|
||||
library: { type: "var", name: "plugin_// plugin_name //" },
|
||||
exposes: {
|
||||
"./": "./info.js",
|
||||
"./package.json": "./package.json",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
Reference in new issue
Block a user