mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 07:24:53 +09:00
Flatten lib namespace
Move all functions and classes currently available through lib/name and libName to be under a single flat namespace in lib. This make reorganising the lib namespace much simpler as the location of symbols can move without breaking the consumers of lib. The multi-entrypoint design was already problematic for the web plugin system which couldn't effectively use it due to how webpack's shared module system is awkward to set up with multiple entrypoints per package.
This commit is contained in:
1 parent
bb58670597
commit
bfe119eaa3
143 files changed
+1798
-1918
No files matched your search
@@ -2,9 +2,8 @@
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const libFileOps = require("@clusterio/lib/file_ops");
|
||||
const libPlugin = require("@clusterio/lib/plugin");
|
||||
const RateLimiter = require("@clusterio/lib/RateLimiter");
|
||||
const lib = require("@clusterio/lib");
|
||||
const { RateLimiter } = lib;
|
||||
|
||||
const {
|
||||
ContributionEvent,
|
||||
@@ -34,10 +33,10 @@ async function loadTechnologies(controllerConfig, logger) {
|
||||
async function saveTechnologies(controllerConfig, technologies, logger) {
|
||||
let filePath = path.join(controllerConfig.get("controller.database_directory"), "technologies.json");
|
||||
logger.verbose(`writing ${filePath}`);
|
||||
await libFileOps.safeOutputFile(filePath, JSON.stringify([...technologies.entries()], null, 4));
|
||||
await lib.safeOutputFile(filePath, JSON.stringify([...technologies.entries()], null, 4));
|
||||
}
|
||||
|
||||
class ControllerPlugin extends libPlugin.BaseControllerPlugin {
|
||||
class ControllerPlugin extends lib.BaseControllerPlugin {
|
||||
async init() {
|
||||
this.technologies = await loadTechnologies(this.controller.config, this.logger);
|
||||
this.progressRateLimiter = new RateLimiter({
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"use strict";
|
||||
const libPlugin = require("@clusterio/lib/plugin");
|
||||
const libLuaTools = require("@clusterio/lib/lua_tools");
|
||||
const lib = require("@clusterio/lib");
|
||||
const {
|
||||
ContributionEvent,
|
||||
ProgressEvent,
|
||||
@@ -10,7 +9,7 @@ const {
|
||||
} = require("./messages");
|
||||
|
||||
|
||||
class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
class InstancePlugin extends lib.BaseInstancePlugin {
|
||||
unexpectedError(err) {
|
||||
this.logger.error(`Unexpected error:\n${err.stack}`);
|
||||
}
|
||||
@@ -40,7 +39,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
if (!this.syncStarted || !["starting", "running"].includes(this.instance.status)) {
|
||||
return;
|
||||
}
|
||||
let techsJson = libLuaTools.escapeString(JSON.stringify(event.technologies));
|
||||
let techsJson = lib.escapeString(JSON.stringify(event.technologies));
|
||||
await this.sendOrderedRcon(`/sc research_sync.update_progress("${techsJson}")`, true);
|
||||
}
|
||||
|
||||
@@ -54,7 +53,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
}
|
||||
let { name, level } = event;
|
||||
await this.sendOrderedRcon(
|
||||
`/sc research_sync.research_technology("${libLuaTools.escapeString(name)}", ${level})`, true
|
||||
`/sc research_sync.research_technology("${lib.escapeString(name)}", ${level})`, true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
}
|
||||
|
||||
if (techsToSync.length) {
|
||||
let syncJson = libLuaTools.escapeString(JSON.stringify(techsToSync));
|
||||
let syncJson = lib.escapeString(JSON.stringify(techsToSync));
|
||||
await this.sendOrderedRcon(`/sc research_sync.sync_technologies("${syncJson}")`, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
const { libData } = require("@clusterio/lib");
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
class ContributionEvent {
|
||||
static type = "event";
|
||||
@@ -41,7 +41,7 @@ class ProgressEvent {
|
||||
static dst = "instance";
|
||||
static plugin = "research_sync";
|
||||
|
||||
/** @type {Array<>} */
|
||||
/** @type {Array<Technology>} */
|
||||
technologies;
|
||||
|
||||
constructor(technologies) {
|
||||
@@ -167,7 +167,7 @@ class SyncTechnologiesRequest {
|
||||
return new this(json.map(e => Technology.fromJSON(e)));
|
||||
}
|
||||
|
||||
static Response = libData.jsonArray(Technology);
|
||||
static Response = lib.jsonArray(Technology);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in new issue
Block a user