mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +09:00
Update common files
This commit is contained in:
9 files changed
+57
-1726
No files matched your search
@@ -3,6 +3,8 @@ const { logger } = require("./logging");
|
|||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
|
const _package = require("./package.json");
|
||||||
|
|
||||||
async function copyTemplateFile(src, dst, properties) {
|
async function copyTemplateFile(src, dst, properties) {
|
||||||
logger.verbose(`Writing ${dst} from template ${src}`);
|
logger.verbose(`Writing ${dst} from template ${src}`);
|
||||||
|
|
||||||
@@ -139,7 +141,6 @@ async function copyPluginTemplates(pluginName, templates) {
|
|||||||
|
|
||||||
// Files for lua modules
|
// Files for lua modules
|
||||||
if (templates.includes("module")) {
|
if (templates.includes("module")) {
|
||||||
files.set(".luacheckrc", path.join(commonPath, ".luacheckrc"));
|
|
||||||
files.set("module/module.json", path.join(commonPath, "module/module.json"));
|
files.set("module/module.json", path.join(commonPath, "module/module.json"));
|
||||||
files.set("module/control.lua", path.join(commonPath, "module/control.lua"));
|
files.set("module/control.lua", path.join(commonPath, "module/control.lua"));
|
||||||
files.set("module/module_exports.lua", path.join(commonPath, "module/module_exports.lua"));
|
files.set("module/module_exports.lua", path.join(commonPath, "module/module_exports.lua"));
|
||||||
@@ -147,7 +148,6 @@ async function copyPluginTemplates(pluginName, templates) {
|
|||||||
files.set("module/globals.lua", path.join(commonPath, "module/globals.lua"));
|
files.set("module/globals.lua", path.join(commonPath, "module/globals.lua"));
|
||||||
} else {
|
} else {
|
||||||
files.set(`instance.${ext}`, path.join(templatePath, `instance_empty.${ext}`));
|
files.set(`instance.${ext}`, path.join(templatePath, `instance_empty.${ext}`));
|
||||||
pluginContexts += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,18 +164,25 @@ async function copyPluginTemplates(pluginName, templates) {
|
|||||||
|
|
||||||
// Properties that will control the replacements in the templates
|
// Properties that will control the replacements in the templates
|
||||||
const properties = {
|
const properties = {
|
||||||
config: config,
|
// Weather this is ts or js
|
||||||
typescript: !javascriptOnly,
|
typescript: !javascriptOnly,
|
||||||
|
ext: ext,
|
||||||
|
// Which templates where requested
|
||||||
|
multi_context: pluginContexts > 1,
|
||||||
controller: templates.includes("controller"),
|
controller: templates.includes("controller"),
|
||||||
host: templates.includes("host"),
|
host: templates.includes("host"),
|
||||||
instance: templates.includes("instance"),
|
instance: templates.includes("instance"),
|
||||||
module: templates.includes("module"),
|
module: templates.includes("module"),
|
||||||
ctl: templates.includes("ctl"),
|
ctl: templates.includes("ctl"),
|
||||||
web: templates.includes("web"),
|
web: templates.includes("web"),
|
||||||
multi_context: pluginContexts > 1,
|
// Macro flags for context requirements
|
||||||
plugin_name: pluginName,
|
webpack: webpack,
|
||||||
|
config: config,
|
||||||
|
// String values for package json
|
||||||
|
clusterio_version: _package.version,
|
||||||
|
node_version: _package.engines.node,
|
||||||
prepare: prepare.join(" && "),
|
prepare: prepare.join(" && "),
|
||||||
ext: ext,
|
plugin_name: pluginName,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write all the template files
|
// Write all the template files
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
dist/
|
|
||||||
node_modules/
|
node_modules/
|
||||||
package-lock.json
|
dist/
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,3 +1,3 @@
|
|||||||
webpack.config.js
|
webpack.config.js
|
||||||
dist/web/build
|
|
||||||
dist/browser
|
dist/browser
|
||||||
|
dist/web
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
|
--[[
|
||||||
|
The 'control' file within factorio is used as the entry point for mods, in Clusterio this is only a convention
|
||||||
|
You can change which files are loaded (exports event handlers) and required (no events) by Clusterio within module.json
|
||||||
|
It is highly advised to use FMTK (justarandomgeek.factoriomod-debug) when writing Lua code for factorio
|
||||||
|
Most of your code will be within this one file, but you can create more and require them
|
||||||
|
|
||||||
|
clusterio_api exposes functions to enable communication with your InstancePlugin
|
||||||
|
compat exposes shims to simplify compatibly between factorio versions, use the following to require 2.0
|
||||||
|
`assert(compat.version_ge("2.0.0"), "__plugin_name__ requires factorio 2.0")`
|
||||||
|
]]
|
||||||
|
|
||||||
local clusterio_api = require("modules/clusterio/api")
|
local clusterio_api = require("modules/clusterio/api")
|
||||||
local compat = require("modules/clusterio/compat")
|
local compat = require("modules/clusterio/compat")
|
||||||
|
|
||||||
@@ -6,10 +17,12 @@ local compat = require("modules/clusterio/compat")
|
|||||||
local MyModule = {
|
local MyModule = {
|
||||||
}
|
}
|
||||||
|
|
||||||
--- script_data is 'synced' between players, you should use your plugin name to avoid name conflicts
|
--[[
|
||||||
-- The following helper function is desync safe and avoids name conflicts after being called during on_server_startup
|
`compat.script_data` persists between restarts and is shared between modules, therefore you should use your plugin name to avoid conflicts
|
||||||
-- There are edge cases in the following events: pre player left, player left, console command, and config changed
|
The following helper function is desync safe and avoids name conflicts after being called during `clusterio_api.events.on_server_startup`
|
||||||
-- If you use any of these events and access globalData then make sure to call this function first
|
There are edge cases in the following events: pre player left, player left, console command, and config changed
|
||||||
|
If you use any of these events and access `script_data` then make sure to call this function first
|
||||||
|
]]
|
||||||
local script_data = {}
|
local script_data = {}
|
||||||
local function setup_script_data()
|
local function setup_script_data()
|
||||||
if compat.script_data["__plugin_name__"] == nil then
|
if compat.script_data["__plugin_name__"] == nil then
|
||||||
@@ -28,12 +41,13 @@ end
|
|||||||
|
|
||||||
--- Public methods should be available though your top level module table
|
--- Public methods should be available though your top level module table
|
||||||
function MyModule.foo()
|
function MyModule.foo()
|
||||||
game.print("foo")
|
game.print("foo: " .. (script_data.counter or 0))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Private methods should be local to the file, this will prevent others from calling it
|
--- Private methods should be local to the file, this will prevent others from calling it
|
||||||
local function bar()
|
local function bar()
|
||||||
game.print("bar")
|
script_data.counter = (script_data.counter or 0) + 1
|
||||||
|
game.print("bar: " .. script_data.counter)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Clusterio provides a few custom events, on_server_startup is the most useful and should be used in place of on_init
|
--- Clusterio provides a few custom events, on_server_startup is the most useful and should be used in place of on_init
|
||||||
@@ -61,7 +75,7 @@ local function on_nth_tick_300()
|
|||||||
bar()
|
bar()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Factorio events are accessible through defines.events, you can have one handler per event per module
|
--- Factorio events are accessible through defines.events, you can have one handler per event per file
|
||||||
local e = defines.events
|
local e = defines.events
|
||||||
local events = {
|
local events = {
|
||||||
[clusterio_api.events.on_server_startup] = on_server_startup,
|
[clusterio_api.events.on_server_startup] = on_server_startup,
|
||||||
@@ -73,7 +87,7 @@ local on_nth_tick = {
|
|||||||
[300] = on_nth_tick_300,
|
[300] = on_nth_tick_300,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Always return the top level module table from control, this is how clusterio will access your event handlers
|
--- Always return the top level module table from control, this is how Clusterio will access your event handlers
|
||||||
MyModule.events = events --- @package
|
MyModule.events = events --- @package
|
||||||
MyModule.on_nth_tick = on_nth_tick --- @package
|
MyModule.on_nth_tick = on_nth_tick --- @package
|
||||||
return MyModule
|
return MyModule
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
--- Expose any globals here, typically just your control file if you want to access it through rcon or commands
|
--[[
|
||||||
-- luacheck: globals __plugin_name__
|
It is best practice to not expose any globals because all modules share a global environment
|
||||||
|
However, sometimes you need globals, for example to access functions within rcon commands
|
||||||
|
Therefore, we advise that this should be the only file in your module to expose globals
|
||||||
|
Typically this would be your control file as shown in the example below
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- Access using `/sc __plugin_name__.foo()`
|
||||||
__plugin_name__ = require("modules/__plugin_name__/control")
|
__plugin_name__ = require("modules/__plugin_name__/control")
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
--- Can contain anything you want to allow other plugins to have access to, this example exposes the control file
|
--[[
|
||||||
--- If you only export a single file then it may be better to rename that file to module_exports and save the redirection
|
It is typical for a module to have a control file as the entry point, although this is not a requirement
|
||||||
-- Access the exports from other modules using require("modules/__plugin_name__")
|
Therefore, Clusterio allows you to specify a single default export that can be accessed by other modules
|
||||||
|
You are not required to specify any default export, but note that a module can still require yours directly
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- Access using `local __plugin_name__ = require("modules/__plugin_name__")`
|
||||||
return require("modules/__plugin_name__/control")
|
return require("modules/__plugin_name__/control")
|
||||||
@@ -12,10 +12,10 @@
|
|||||||
"prepare": "__prepare__"
|
"prepare": "__prepare__"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": "__node_version__"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@clusterio/lib": "workspace:*"
|
"@clusterio/lib": "__clusterio_version__"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
//%// Typescript and type declarations
|
//%// Typescript and type declarations
|
||||||
@@ -32,13 +32,13 @@
|
|||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
//%endif
|
//%endif
|
||||||
//%if web | controller // The controller uses webpack even when there is no plugin code
|
//%if webpack
|
||||||
"webpack": "^5.88.2",
|
"webpack": "^5.88.2",
|
||||||
"webpack-cli": "^5.1.4",
|
"webpack-cli": "^5.1.4",
|
||||||
"webpack-merge": "^5.9.0",
|
"webpack-merge": "^5.9.0",
|
||||||
"@clusterio/web_ui": "workspace:*",
|
"@clusterio/web_ui": "__clusterio_version__",
|
||||||
//%endif
|
//%endif
|
||||||
"@clusterio/lib": "workspace:*"
|
"@clusterio/lib": "__clusterio_version__"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sinclair/typebox": "^0.30.4"
|
"@sinclair/typebox": "^0.30.4"
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ module.exports = (env = {}) => merge(common(env), {
|
|||||||
exposes: {
|
exposes: {
|
||||||
"./": "./index.__ext__",
|
"./": "./index.__ext__",
|
||||||
"./package.json": "./package.json",
|
"./package.json": "./package.json",
|
||||||
//%if web
|
|
||||||
"./web": "./web/index.__ext__x",
|
"./web": "./web/index.__ext__x",
|
||||||
//%endif
|
|
||||||
},
|
},
|
||||||
shared: {
|
shared: {
|
||||||
"@clusterio/lib": { import: false },
|
"@clusterio/lib": { import: false },
|
||||||
|
|||||||
Reference in new issue
Block a user