Add support for engine.json fields for plugins
import EventEmitter from "events";
import Path from "path";
-import { readJSON } from "fs-extra";
+import { readJSON, pathExists } from "fs-extra";
import { EngineFieldSchema } from "store/features/engine/engineState";
import { engineRoot } from "../../consts";
import l10n from "lib/helpers/l10n";
-import { clampToCType, is16BitCType } from "lib/helpers/engineFields";
+import { clampToCType } from "lib/helpers/engineFields";
import { setDefault } from "lib/helpers/setDefault";
import { ScriptEventFieldSchema } from "store/features/entities/entitiesTypes";
+import glob from "glob";
interface EngineData {
fields?: EngineFieldSchema[];
@@ -77,6 +78,7 @@ export const initEngineFields = async (projectRoot: string) => {
"engine",
"engine.json"
);
+ const pluginsPath = Path.join(projectRoot, "plugins");
let defaultEngine: EngineData = {};
let localEngine: EngineData = {};
@@ -95,6 +97,19 @@ export const initEngineFields = async (projectRoot: string) => {
fields = defaultEngine.fields;
}
+ const enginePlugins = glob.sync(`${pluginsPath}/*/engine`);
+ for (const enginePluginPath of enginePlugins) {
+ const englinePluginJsonPath = Path.join(enginePluginPath, "engine.json");
+ if (await pathExists(englinePluginJsonPath)) {
+ try {
+ const pluginEngine = await readJSON(englinePluginJsonPath);
+ fields = fields.concat(pluginEngine.fields);
+ } catch(e) {
+ console.warn(e);
+ }
+ }
+ }
+
engineFieldsEmitter.emit("sync", {
fields,
schemaLookup: getEngineFieldSchemas(fields),
