diff --git a/packages/animation/src/plugin.js b/packages/animation/src/plugin.js index b602af1f..e4b11925 100644 --- a/packages/animation/src/plugin.js +++ b/packages/animation/src/plugin.js @@ -1,8 +1,10 @@ import { App, Plugin } from '@wimaengine/app' import { AssetPlugin, Assets } from '@wimaengine/asset' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' -import { typeidGeneric } from '@wimaengine/type' +import { ReflectPlugin } from '@wimaengine/reflect' +import { TimePlugin } from '@wimaengine/time' +import { typeidGeneric, typeid } from '@wimaengine/type' import { AnimationClip } from './assets' import { AnimationPlayer, dropAnimationPlayer } from './components' import { AnimationClipAssets } from './resources' @@ -27,4 +29,8 @@ export class AnimationPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: applyAnimations }) .setResourceAlias(typeidGeneric(Assets, [AnimationClip]), AnimationClipAssets) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(TimePlugin)] + } } diff --git a/packages/app/src/app.js b/packages/app/src/app.js index 869e5e38..51f03e7c 100644 --- a/packages/app/src/app.js +++ b/packages/app/src/app.js @@ -21,26 +21,66 @@ export class PluginRegistry { */ names = new Set() + /** + * Tracks the parent plugin for nested registrations. + * + * @type {Map} + */ + parents = new Map() + + /** + * Tracks the active plugin registration stack. + * + * @type {TypeId[]} + */ + stack = [] + /** * @param {Plugin} plugin + * @throws When a dublicate plugin is registered. */ add(plugin) { + const pluginId = plugin.name() + + if (this.names.has(pluginId)) { + throw new Error(`The plugin \`${pluginId}\` is already registered.${formatRegistrationTrace(this, pluginId)}`) + } + + const parentId = this.stack[this.stack.length - 1] + this.list.push(plugin) - this.names.add(plugin.name()) + this.names.add(pluginId) + + if (parentId === undefined) { + this.parents.delete(pluginId) + } else { + this.parents.set(pluginId, parentId) + } } /** - * @param {TypeId} plugin + * @param {TypeId} pluginId */ - hasTypeId(plugin) { - this.names.has(plugin) + hasTypeId(pluginId) { + return this.names.has(pluginId) } /** - * @param {Plugin} plugin + * @param {TypeId} pluginId */ - has(plugin) { - this.hasTypeId(plugin.name()) + has(pluginId) { + return this.hasTypeId(pluginId) + } + + /** + * @param {TypeId} pluginId + */ + enter(pluginId) { + this.stack.push(pluginId) + } + + leave() { + this.stack.pop() } /** @@ -48,7 +88,46 @@ export class PluginRegistry { */ register(app) { for (let i = 0; i < this.list.length; i++) { - this.list[i].register(app) + const plugin = this.list[i] + + this.enter(plugin.name()) + plugin.register(app) + this.leave() + } + } + + /** + * @param {App} app + */ + finish(app) { + for (let i = 0; i < this.list.length; i++) { + const plugin = this.list[i] + + this.enter(plugin.name()) + plugin.finish(app) + this.leave() + } + } + + /** + * Validates that registered plugins only require plugins that already exist. + * + * @param {App} app + */ + assertDependencies(app) { + for (let i = 0; i < this.list.length; i++) { + const plugin = this.list[i] + const pluginId = plugin.name() + const requires = plugin.requires() + + for (let j = 0; j < requires.length; j++) { + const requiredId = requires[j] + + assertTrue( + app.hasPlugin(requiredId), + `The plugin \`${pluginId}\` requires \`${requiredId}\`, but it is not registered.` + ) + } } } } @@ -118,6 +197,16 @@ export class App { return this.worlds.getWorld(label) } + /** + * Checks whether a plugin has been registered. + * + * @param {TypeId} pluginId + * @returns {boolean} + */ + hasPlugin(pluginId) { + return this.plugins.hasTypeId(pluginId) + } + /** * Creates a world by label. * @@ -194,6 +283,7 @@ export class App { * {@link App.defaultWorld}, {@link App.setComponentHooks}, * {@link App.setResourceAlias}, * {@link App.setResource} and {@link App.setResourceByTypeId}. + * Invokes registered plugin finish callbacks after dependency validation and before queued hooks and resources are applied. * Applies queued resource aliases to every world before the runner starts. * Applies queued component hooks to every world before the runner starts. * Flushes any resources staged through {@link App.setResource} into their target worlds before the runner starts. @@ -202,6 +292,8 @@ export class App { */ run() { this.plugins.register(this) + this.plugins.assertDependencies(this) + this.plugins.finish(this) this.applyComponentHooks() this.applyResourceAliases() this.flushResources() @@ -390,6 +482,20 @@ export class Plugin { */ register(_app) { } + /** + * @param {App} _app + */ + finish(_app) { } + + /** + * Returns the type ids of plugins required by this plugin. + * + * @returns {TypeId[]} + */ + requires() { + return [] + } + /** * @returns {TypeId} */ @@ -454,3 +560,41 @@ export class PluginGroup extends Plugin { } } } + +/** + * Formats the registration chain for error output. + * + * @param {PluginRegistry} registry + * @param {TypeId} pluginId + * @returns {string} + */ +function formatRegistrationTrace(registry, pluginId) { + const chain = [] + let current = pluginId + + while (current !== undefined) { + chain.push(current) + current = registry.parents.get(current) + } + + chain.reverse() + + if (!chain.length) { + return '' + } + + const lines = ['Plugin registration stack:'] + + for (let i = 0; i < chain.length; i++) { + const currentId = chain[i] + const parentId = chain[i - 1] + + if (parentId === undefined) { + lines.push(`- \`${currentId}\` registered directly on the app`) + } else { + lines.push(`- \`${currentId}\` registered by \`${parentId}\``) + } + } + + return `\n\n${lines.join('\n')}` +} diff --git a/packages/app/tests/app.test.js b/packages/app/tests/app.test.js new file mode 100644 index 00000000..f8ea2304 --- /dev/null +++ b/packages/app/tests/app.test.js @@ -0,0 +1,152 @@ +import { test, describe } from "vitest"; +import { ok, strictEqual, throws } from "node:assert"; +import { App, Plugin } from "../src"; +import { typeid } from "@wimaengine/type"; + +class ProvidedPlugin extends Plugin { } + +class ChildPlugin extends Plugin { + requires() { + return [typeid(ProvidedPlugin)] + } +} + +class ProviderBootstrapPlugin extends Plugin { + register(app) { + app.registerPlugin(new ProvidedPlugin()) + } +} + +class ParentPlugin extends Plugin { + register(app) { + app.registerPlugin(new ChildPlugin()) + } +} + +class BootstrapPlugin extends Plugin { + register(app) { + app.registerPlugin(new ProviderBootstrapPlugin()) + } +} + +class MissingPlugin extends Plugin { } + +class MissingDependencyPlugin extends Plugin { + requires() { + return [typeid(MissingPlugin)] + } +} + +class FinishResource { } + +class FinishPlugin extends Plugin { + finish(app) { + strictEqual(app.initialized, false) + app.setResource(finishResource) + } +} + +const finishResource = new FinishResource() + +describe("Testing `App` plugin registry behavior", () => { + test("`App.hasPlugin` checks by type id", () => { + const app = new App() + + app.registerPlugin(new ParentPlugin()) + + strictEqual(app.hasPlugin(typeid(ParentPlugin)), true) + strictEqual(app.hasPlugin(typeid(ProvidedPlugin)), false) + }) + + test("`App.run` validates plugins registered during registration", () => { + const app = new App() + + app + .registerPlugin(new ParentPlugin()) + .registerPlugin(new BootstrapPlugin()) + .setRunner(() => {}) + .run() + + strictEqual(app.hasPlugin(typeid(ProvidedPlugin)), true) + strictEqual(app.hasPlugin(typeid(ChildPlugin)), true) + }) + + test("`App.registerPlugin` reports a duplicate plugin registered by another plugin", () => { + const app = new App() + const parent = new ParentPlugin() + + parent.register = (app) => { + app.registerPlugin(new ChildPlugin()) + app.registerPlugin(new ChildPlugin()) + } + + let error + + try { + app + .registerPlugin(parent) + .setRunner(() => {}) + .run() + } catch (caught) { + error = caught + } + + ok(error instanceof Error) + + const message = error.message + const parentId = typeid(ParentPlugin) + const childId = typeid(ChildPlugin) + + ok(message.includes(`The plugin \`${childId}\` is already registered.`)) + ok(message.includes("Plugin registration stack:")) + ok(message.includes(`- \`${parentId}\` registered directly on the app`)) + ok(message.includes(`- \`${childId}\` registered by \`${parentId}\``)) + }) + + test("`App.run` throws when a plugin dependency is missing", () => { + const app = new App() + + app + .registerPlugin(new MissingDependencyPlugin()) + .setRunner(() => {}) + + throws(() => app.run(), /requires .* but it is not registered/) + }) + + test("`App.registerPlugin` reports a duplicate plugin registered on app", () => { + const app = new App() + + let error + + try { + app + .registerPlugin(new ChildPlugin()) + .registerPlugin(new ChildPlugin()) + } catch (caught) { + error = caught + } + + ok(error instanceof Error) + + const message = error.message + const childId = typeid(ChildPlugin) + + ok(message.includes(`The plugin \`${childId}\` is already registered.`)) + ok(message.includes("Plugin registration stack:")) + ok(message.includes(`- \`${childId}\` registered directly on the app`)) + }) + + test("`Plugin.finish` runs after dependencies are checked and before resources are flushed", () => { + const app = new App() + const world = class DefaultWorld { } + + app + .setWorld(world) + .defaultWorld(world) + .setRunner(() => {}) + .registerPlugin(new FinishPlugin()) + .run() + + strictEqual(app.getWorld(world).getResource(FinishResource), finishResource) + }) +}) diff --git a/packages/asset/src/plugins/asset.js b/packages/asset/src/plugins/asset.js index cacec8b4..f585b967 100644 --- a/packages/asset/src/plugins/asset.js +++ b/packages/asset/src/plugins/asset.js @@ -1,8 +1,9 @@ /** @import { Constructor } from '@wimaengine/type' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { EventPlugin } from '@wimaengine/event' +import { ReflectPlugin } from '@wimaengine/reflect' import { typeid, typeidGeneric } from '@wimaengine/type' import { Assets } from '../resources' import { registerAssetTypes, registerAssetOnAssetServer, unloadDroppedAssets, updateAssetChannel, updateAssetEvents } from '../systems' @@ -91,6 +92,10 @@ export class AssetPlugin extends Plugin { } } + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } + name() { return typeidGeneric(AssetPlugin, [this.asset]) } diff --git a/packages/asset/src/plugins/assetServer.js b/packages/asset/src/plugins/assetServer.js index 1d7dd16d..ca404456 100644 --- a/packages/asset/src/plugins/assetServer.js +++ b/packages/asset/src/plugins/assetServer.js @@ -1,6 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { EventPlugin } from '@wimaengine/event' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { AssetLoadFail, AssetLoadSuccess, AssetSaveSuccess } from '../events' import { AssetServer } from '../resources' import { updateAssets, logFailedLoads, registerAssetServerTypes } from '../systems' @@ -34,4 +36,8 @@ export class AssetServerPlugin extends Plugin { }) .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.End, system: logFailedLoads }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } diff --git a/packages/asset/src/plugins/exporter.js b/packages/asset/src/plugins/exporter.js index 8eb5f6aa..ee1cc821 100644 --- a/packages/asset/src/plugins/exporter.js +++ b/packages/asset/src/plugins/exporter.js @@ -1,9 +1,10 @@ /** @import {Constructor} from '@wimaengine/type' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { typeid, typeidGeneric } from '@wimaengine/type' import { Exporter } from '../core' import { registerAssetExporterOnAssetServer } from '../systems' +import { AssetServerPlugin } from './assetServer' /** * @template T @@ -48,6 +49,10 @@ export class AssetExporterPlugin extends Plugin { }) } + requires() { + return [typeid(CorePlugin), typeid(AssetServerPlugin)] + } + name() { return typeidGeneric(AssetExporterPlugin, [this.asset]) } diff --git a/packages/asset/src/plugins/importer.js b/packages/asset/src/plugins/importer.js index 7e8d1860..d0e42af5 100644 --- a/packages/asset/src/plugins/importer.js +++ b/packages/asset/src/plugins/importer.js @@ -1,9 +1,10 @@ /** @import {Constructor} from '@wimaengine/type' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { typeid, typeidGeneric } from '@wimaengine/type' import { Importer } from '../core' import { registerAssetImporterOnAssetServer } from '../systems' +import { AssetServerPlugin } from './assetServer' /** * @template T @@ -49,6 +50,10 @@ export class AssetImporterPlugin extends Plugin { }) } + requires() { + return [typeid(CorePlugin), typeid(AssetServerPlugin)] + } + name() { return typeidGeneric(AssetImporterPlugin, [this.asset]) } diff --git a/packages/audio/src/plugin.js b/packages/audio/src/plugin.js index b7d396db..81ebcd9d 100644 --- a/packages/audio/src/plugin.js +++ b/packages/audio/src/plugin.js @@ -1,8 +1,10 @@ import { App, Plugin } from '@wimaengine/app' import { AssetImporterPlugin, AssetPlugin, Assets } from '@wimaengine/asset' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' -import { typeidGeneric } from '@wimaengine/type' +import { ReflectPlugin } from '@wimaengine/reflect' +import { TimePlugin } from '@wimaengine/time' +import { typeidGeneric, typeid } from '@wimaengine/type' import { Audio } from './assets' import { AudioPlayer, AudioOscillator, removeAudioPlayerSink, removeOscillatorSink } from './components' import { AudioAdded, AudioDropped, AudioModified } from './events' @@ -58,4 +60,8 @@ export class AudioPlugin extends Plugin { } } } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(TimePlugin)] + } } diff --git a/packages/broadphase/src/plugin.js b/packages/broadphase/src/plugin.js index 44f7c233..0dbc22c8 100644 --- a/packages/broadphase/src/plugin.js +++ b/packages/broadphase/src/plugin.js @@ -1,6 +1,9 @@ /** @import {Broadphasable2D} from './resources'*/ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { CollisionPairs, Broadphase2D } from './resources' import { getCollisionPairs, registerBroadphaseTypes2D, updateBroadphase2D } from './systems' @@ -31,6 +34,10 @@ export class Broadphase2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: getCollisionPairs }) .registerSystem({ schedule: AppSchedule.Update, system: updateBroadphase2D }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(MathPlugin)] + } } /** diff --git a/packages/color/src/plugin.js b/packages/color/src/plugin.js index 617eea8b..3a9378f4 100644 --- a/packages/color/src/plugin.js +++ b/packages/color/src/plugin.js @@ -1,5 +1,7 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CorePlugin, AppSchedule } from '@wimaengine/core' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { registerColorTypes } from './systems' export class ColorPlugin extends Plugin { @@ -10,4 +12,8 @@ export class ColorPlugin extends Plugin { register(app) { app.registerSystem({ schedule: AppSchedule.Startup, system: registerColorTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } diff --git a/packages/command/src/plugin.js b/packages/command/src/plugin.js index 9b1ce0c9..6d194889 100644 --- a/packages/command/src/plugin.js +++ b/packages/command/src/plugin.js @@ -1,6 +1,7 @@ /** @import { App } from '@wimaengine/app' */ import { Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { CorePlugin, AppSchedule, CoreSystems } from '@wimaengine/core' +import { typeid } from '@wimaengine/type' import { CommandQueue } from './resources' import { executeCommands } from './systems' @@ -23,4 +24,8 @@ export class CommandsPlugin extends Plugin { system: executeCommands }) } + + requires() { + return [typeid(CorePlugin)] + } } diff --git a/packages/core/src/plugin.js b/packages/core/src/plugin.js index 7bb1ca32..d78bebfc 100644 --- a/packages/core/src/plugin.js +++ b/packages/core/src/plugin.js @@ -1,6 +1,8 @@ /** @import { App } from '@wimaengine/app' */ import { Plugin } from '@wimaengine/app' +import { ReflectPlugin } from '@wimaengine/reflect' import { SchedulerBuilder } from '@wimaengine/schedule' +import { typeid } from '@wimaengine/type' import { AppSchedule, CoreSystems, MainWorld, defaultRunner } from './core' import { registerCoreTypes, registerPrimitiveTypes } from './systems' @@ -83,4 +85,8 @@ export class CorePlugin extends Plugin { system: registerPrimitiveTypes }) } + + requires() { + return [typeid(ReflectPlugin)] + } } diff --git a/packages/damping/src/plugin.js b/packages/damping/src/plugin.js index 7c143ced..44eaa0b5 100644 --- a/packages/damping/src/plugin.js +++ b/packages/damping/src/plugin.js @@ -1,5 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { Movable2DPlugin, Movable3DPlugin } from '@wimaengine/movable' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { Linear2DDamping, Angular2DDamping, Linear3DDamping, Angular3DDamping } from './resources' import { dampenRotation2D, dampenRotation3D, dampenVelocity2D, dampenVelocity3D, registerDamping2DTypes, registerDamping3DTypes } from './systems' @@ -16,6 +19,10 @@ export class Damping2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: dampenVelocity2D }) .registerSystem({ schedule: AppSchedule.Update, system: dampenRotation2D }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(Movable2DPlugin)] + } } export class Damping3DPlugin extends Plugin { @@ -31,4 +38,8 @@ export class Damping3DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: dampenVelocity3D }) .registerSystem({ schedule: AppSchedule.Update, system: dampenRotation3D }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(Movable3DPlugin)] + } } diff --git a/packages/device/src/plugin.js b/packages/device/src/plugin.js index f99ba945..f9ac915e 100644 --- a/packages/device/src/plugin.js +++ b/packages/device/src/plugin.js @@ -1,5 +1,7 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CorePlugin, AppSchedule } from '@wimaengine/core' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { Browser, PlatformOS } from './core' import { Device } from './resources' import { registerDeviceTypes } from './systems' @@ -51,4 +53,8 @@ export class DevicePlugin extends Plugin { device.browser = Browser.Safari } } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } diff --git a/packages/diagnostic/src/entitycount.js b/packages/diagnostic/src/entitycount.js index 26c6077a..01d33e60 100644 --- a/packages/diagnostic/src/entitycount.js +++ b/packages/diagnostic/src/entitycount.js @@ -1,8 +1,9 @@ -import { App } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { App, Plugin } from '@wimaengine/app' +import { CorePlugin, AppSchedule, CoreSystems } from '@wimaengine/core' import { World, EntityHandle, Query } from '@wimaengine/ecs' +import { typeid } from '@wimaengine/type' -export class EntityCountDiagnosticPlugin { +export class EntityCountDiagnosticPlugin extends Plugin { /** * @param {App} app @@ -12,6 +13,10 @@ export class EntityCountDiagnosticPlugin { .registerSystem({ schedule: AppSchedule.Startup, systemGroup: CoreSystems.Start, system: setUpUI }) .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.End, system: updateEntityCount }) } + + requires() { + return [typeid(CorePlugin)] + } } /** diff --git a/packages/diagnostic/src/fpsdebugger.js b/packages/diagnostic/src/fpsdebugger.js index c2de1fee..943348d3 100644 --- a/packages/diagnostic/src/fpsdebugger.js +++ b/packages/diagnostic/src/fpsdebugger.js @@ -1,7 +1,9 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { CorePlugin, AppSchedule, CoreSystems } from '@wimaengine/core' import { World } from '@wimaengine/ecs' -import { TimerMode, VirtualClock } from '@wimaengine/time' +import { ReflectPlugin } from '@wimaengine/reflect' +import { TimerMode, VirtualClock, TimePlugin } from '@wimaengine/time' +import { typeid } from '@wimaengine/type' import { RAFTimer } from './resources' import { registerFpsDebuggerTypes } from './systems' @@ -18,6 +20,10 @@ export class FPSDebugger extends Plugin { .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.End, system: updateFPSCounter }) .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.End, system: updateRAFTimer }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(TimePlugin)] + } } /** diff --git a/packages/emitter/src/plugin.js b/packages/emitter/src/plugin.js index e576fa04..0d7726cb 100644 --- a/packages/emitter/src/plugin.js +++ b/packages/emitter/src/plugin.js @@ -1,5 +1,9 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CommandsPlugin } from '@wimaengine/command' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { TimePlugin } from '@wimaengine/time' +import { Transform2DPlugin, Transform3DPlugin } from '@wimaengine/transform' +import { typeid } from '@wimaengine/type' import { despawnParticles, emitParticles2D, emitParticles3D } from './systems' export class Emitter2DPlugin extends Plugin { @@ -13,6 +17,15 @@ export class Emitter2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: emitParticles2D }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(CommandsPlugin), + typeid(TimePlugin), + typeid(Transform2DPlugin) + ] + } } export class Emitter3DPlugin extends Plugin { @@ -26,4 +39,13 @@ export class Emitter3DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: emitParticles3D }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(CommandsPlugin), + typeid(TimePlugin), + typeid(Transform3DPlugin) + ] + } } diff --git a/packages/event/src/plugin.js b/packages/event/src/plugin.js index 3883b018..c3210f40 100644 --- a/packages/event/src/plugin.js +++ b/packages/event/src/plugin.js @@ -1,7 +1,8 @@ /** @import { Constructor } from '@wimaengine/type'*/ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { CorePlugin, AppSchedule, CoreSystems } from '@wimaengine/core' +import { ReflectPlugin } from '@wimaengine/reflect' import { typeid, typeidGeneric } from '@wimaengine/type' import { Events } from './core' import { makeEventClear, registerEventTypes } from './systems' @@ -61,6 +62,10 @@ export class EventPlugin extends Plugin { } } + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } + name() { return typeidGeneric(EventPlugin, [this.event]) } diff --git a/packages/geometry/src/plugin.js b/packages/geometry/src/plugin.js index 682b42ca..61282f17 100644 --- a/packages/geometry/src/plugin.js +++ b/packages/geometry/src/plugin.js @@ -1,5 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CorePlugin, AppSchedule } from '@wimaengine/core' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { registerGeometryTypes } from './systems' export class GeometryPlugin extends Plugin { @@ -10,4 +13,8 @@ export class GeometryPlugin extends Plugin { register(app) { app.registerSystem({ schedule: AppSchedule.Startup, system: registerGeometryTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(MathPlugin)] + } } diff --git a/packages/gizmo/src/plugins/2d.js b/packages/gizmo/src/plugins/2d.js index d9d238ae..57f9a391 100644 --- a/packages/gizmo/src/plugins/2d.js +++ b/packages/gizmo/src/plugins/2d.js @@ -1,7 +1,11 @@ /** @import { Constructor } from '@wimaengine/type' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' -import { typeidGeneric } from '@wimaengine/type' +import { ColorPlugin } from '@wimaengine/color' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeidGeneric, typeid } from '@wimaengine/type' +import { WindowPlugin } from '@wimaengine/window' import { Gizmo2D, GizmoSettings } from '../core' import { genenerateDrawGizmo2Dsystem, registerGizmo2DTypes } from '../systems' @@ -46,6 +50,16 @@ export class Gizmo2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: genenerateDrawGizmo2Dsystem(label) }) } + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(ColorPlugin), + typeid(MathPlugin), + typeid(WindowPlugin) + ] + } + name() { return typeidGeneric(Gizmo2DPlugin, [this.label]) } diff --git a/packages/gizmo/src/plugins/3d.js b/packages/gizmo/src/plugins/3d.js index 5f7febfa..e0873629 100644 --- a/packages/gizmo/src/plugins/3d.js +++ b/packages/gizmo/src/plugins/3d.js @@ -1,7 +1,10 @@ /** @import { Constructor } from '@wimaengine/type' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' -import { typeidGeneric } from '@wimaengine/type' +import { ColorPlugin } from '@wimaengine/color' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeidGeneric, typeid } from '@wimaengine/type' import { Gizmo3D, GizmoSettings } from '../core' import { genenerateDrawGizmo3Dsystem, registerGizmo3DTypes } from '../systems' @@ -46,6 +49,15 @@ export class Gizmo3DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: genenerateDrawGizmo3Dsystem(label) }) } + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(ColorPlugin), + typeid(MathPlugin) + ] + } + name() { return typeidGeneric(Gizmo3DPlugin, [this.label]) } diff --git a/packages/gravity/src/plugin.js b/packages/gravity/src/plugin.js index 18c06150..9d77a1fc 100644 --- a/packages/gravity/src/plugin.js +++ b/packages/gravity/src/plugin.js @@ -1,6 +1,10 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' -import { Vector2, Vector3 } from '@wimaengine/math' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { Vector2, Vector3, MathPlugin } from '@wimaengine/math' +import { Movable2DPlugin, Movable3DPlugin } from '@wimaengine/movable' +import { NarrowPhase2DPlugin } from '@wimaengine/narrowphase' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { Gravity2D, Gravity3D } from './resources' import { applyGravity2D, applyGravity3D, registerGravity2DTypes, registerGravity3DTypes } from './systems' @@ -29,6 +33,16 @@ export class Gravity2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Startup, system: registerGravity2DTypes }) .registerSystem({ schedule: AppSchedule.Update, system: applyGravity2D }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(MathPlugin), + typeid(Movable2DPlugin), + typeid(NarrowPhase2DPlugin) + ] + } } export class Gravity3DPlugin extends Plugin { @@ -56,6 +70,16 @@ export class Gravity3DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Startup, system: registerGravity3DTypes }) .registerSystem({ schedule: AppSchedule.Update, system: applyGravity3D }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(MathPlugin), + typeid(Movable3DPlugin), + typeid(NarrowPhase2DPlugin) + ] + } } /** diff --git a/packages/hierarchy/src/plugin.js b/packages/hierarchy/src/plugin.js index d33871be..27f589e6 100644 --- a/packages/hierarchy/src/plugin.js +++ b/packages/hierarchy/src/plugin.js @@ -1,6 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CorePlugin, AppSchedule } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { Children, Parent } from './components' import { addSelfToChildren, despawnChildren, addSelfToParent, removeSelfFromParent } from './hooks' import { registerHierarchyTypes } from './systems' @@ -24,4 +26,8 @@ export class HierarchyPlugin extends Plugin { )) .registerSystem({ schedule: AppSchedule.Startup, system: registerHierarchyTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } diff --git a/packages/integrator/src/plugins/euler.js b/packages/integrator/src/plugins/euler.js index 2fb371b0..54548556 100644 --- a/packages/integrator/src/plugins/euler.js +++ b/packages/integrator/src/plugins/euler.js @@ -1,5 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { Movable2DPlugin, Movable3DPlugin } from '@wimaengine/movable' +import { Transform2DPlugin, Transform3DPlugin } from '@wimaengine/transform' +import { typeid } from '@wimaengine/type' import { updateAngularEuler2D, updateOrientationEuler2D, @@ -23,6 +26,10 @@ export class EulerIntegrator2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: updateOrientationEuler2D }) .registerSystem({ schedule: AppSchedule.Update, system: updateAngularEuler2D }) } + + requires() { + return [typeid(CorePlugin), typeid(Movable2DPlugin), typeid(Transform2DPlugin)] + } } export class EulerIntegrator3DPlugin extends Plugin { @@ -37,4 +44,8 @@ export class EulerIntegrator3DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: updateOrientationEuler3D }) .registerSystem({ schedule: AppSchedule.Update, system: updateAngularEuler3D }) } + + requires() { + return [typeid(CorePlugin), typeid(Movable3DPlugin), typeid(Transform3DPlugin)] + } } diff --git a/packages/integrator/src/plugins/verlet.js b/packages/integrator/src/plugins/verlet.js index f714d2f1..985da915 100644 --- a/packages/integrator/src/plugins/verlet.js +++ b/packages/integrator/src/plugins/verlet.js @@ -1,5 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { Movable2DPlugin } from '@wimaengine/movable' +import { Transform2DPlugin } from '@wimaengine/transform' +import { typeid } from '@wimaengine/type' import { updatePositionVerlet2D, updateOrientationVerlet2D } from '../systems' export class VerletIntegrator2DPlugin extends Plugin { @@ -12,4 +15,8 @@ export class VerletIntegrator2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, system: updatePositionVerlet2D }) .registerSystem({ schedule: AppSchedule.Update, system: updateOrientationVerlet2D }) } + + requires() { + return [typeid(CorePlugin), typeid(Movable2DPlugin), typeid(Transform2DPlugin)] + } } diff --git a/packages/keyboard/src/plugin.js b/packages/keyboard/src/plugin.js index 7611e8a7..3b444dda 100644 --- a/packages/keyboard/src/plugin.js +++ b/packages/keyboard/src/plugin.js @@ -1,9 +1,10 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { World } from '@wimaengine/ecs' import { Events } from '@wimaengine/event' -import { typeidGeneric } from '@wimaengine/type' -import { KeyUp, KeyDown } from '@wimaengine/window' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeidGeneric, typeid } from '@wimaengine/type' +import { KeyUp, KeyDown, WindowPlugin } from '@wimaengine/window' import { KeyCode } from './core' import { Keyboard } from './resources' import { registerKeyboardTypes } from './systems' @@ -19,6 +20,10 @@ export class KeyboardPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Startup, systemGroup: CoreSystems.Start, system: registerKeyboardTypes }) .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.Start, system: updateKeyBoard }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(WindowPlugin)] + } } /** diff --git a/packages/math/src/plugin.js b/packages/math/src/plugin.js index 0a2b9412..8bdcae22 100644 --- a/packages/math/src/plugin.js +++ b/packages/math/src/plugin.js @@ -1,5 +1,7 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CorePlugin, AppSchedule } from '@wimaengine/core' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { registerMathTypes } from './systems' export class MathPlugin extends Plugin { @@ -10,4 +12,8 @@ export class MathPlugin extends Plugin { register(app) { app.registerSystem({ schedule: AppSchedule.Startup, system: registerMathTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } diff --git a/packages/mouse/src/plugin.js b/packages/mouse/src/plugin.js index c7f06d14..07f94aa8 100644 --- a/packages/mouse/src/plugin.js +++ b/packages/mouse/src/plugin.js @@ -1,10 +1,11 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { World } from '@wimaengine/ecs' import { Events } from '@wimaengine/event' -import { Vector2 } from '@wimaengine/math' -import { typeidGeneric } from '@wimaengine/type' -import { PointerDown, PointerMove, PointerUp } from '@wimaengine/window' +import { MathPlugin, Vector2 } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeidGeneric, typeid } from '@wimaengine/type' +import { PointerDown, PointerMove, PointerUp, WindowPlugin } from '@wimaengine/window' import { MouseButton } from './core' import { Mouse, MouseButtons } from './resources' import { registerMouseTypes } from './systems' @@ -23,6 +24,10 @@ export class MousePlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.Start, system: updateMouse }) .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.Start, system: updateMouseButtons }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(MathPlugin), typeid(WindowPlugin)] + } } /** diff --git a/packages/movable/src/plugins/three.js b/packages/movable/src/plugins/three.js index fc6cfe66..c1fa5348 100644 --- a/packages/movable/src/plugins/three.js +++ b/packages/movable/src/plugins/three.js @@ -1,5 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { registerMovable3DTypes } from '../systems' export class Movable3DPlugin extends Plugin { @@ -11,4 +14,8 @@ export class Movable3DPlugin extends Plugin { app .registerSystem({ schedule: AppSchedule.Startup, system: registerMovable3DTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(MathPlugin)] + } } diff --git a/packages/movable/src/plugins/two.js b/packages/movable/src/plugins/two.js index 66f332d3..513f064d 100644 --- a/packages/movable/src/plugins/two.js +++ b/packages/movable/src/plugins/two.js @@ -1,5 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { registerMovable2DTypes } from '../systems' export class Movable2DPlugin extends Plugin { @@ -11,4 +14,8 @@ export class Movable2DPlugin extends Plugin { app .registerSystem({ schedule: AppSchedule.Startup, system: registerMovable2DTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(MathPlugin)] + } } diff --git a/packages/name/src/plugin.js b/packages/name/src/plugin.js index f5f0e485..5c20e420 100644 --- a/packages/name/src/plugin.js +++ b/packages/name/src/plugin.js @@ -1,5 +1,7 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CorePlugin, AppSchedule } from '@wimaengine/core' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { registerNameTypes } from './systems' export class NamePlugin extends Plugin { @@ -11,4 +13,8 @@ export class NamePlugin extends Plugin { app .registerSystem({ schedule: AppSchedule.Startup, system: registerNameTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } diff --git a/packages/narrowphase/src/plugin.js b/packages/narrowphase/src/plugin.js index 66863263..95ed292f 100644 --- a/packages/narrowphase/src/plugin.js +++ b/packages/narrowphase/src/plugin.js @@ -1,6 +1,9 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { PhysicsProperties } from './components' import { physicspropertiesAddHook } from './hooks' import { Contacts, SATNarrowphase2D } from './resources' @@ -30,4 +33,8 @@ export class NarrowPhase2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Startup, system: registerNarrowphase2DTypes }) .registerSystem({ schedule: AppSchedule.Update, system: getSATContacts }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(MathPlugin)] + } } diff --git a/packages/physics/src/plugins/debugger.js b/packages/physics/src/plugins/debugger.js index ed150b0a..60c238a1 100644 --- a/packages/physics/src/plugins/debugger.js +++ b/packages/physics/src/plugins/debugger.js @@ -1,6 +1,12 @@ /** @import {EntityHandle} from '@wimaengine/ecs' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { Broadphase2DPlugin } from '@wimaengine/broadphase' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { Movable2DPlugin } from '@wimaengine/movable' +import { NarrowPhase2DPlugin } from '@wimaengine/narrowphase' +import { Transform2DPlugin } from '@wimaengine/transform' +import { typeid } from '@wimaengine/type' +import { WindowPlugin } from '@wimaengine/window' import { drawArms, drawBounds, @@ -40,6 +46,17 @@ export class Physics2DDebuggerPlugin extends Plugin { if (options.drawPosition) app.registerSystem({ schedule: AppSchedule.Update, system: drawPosition }) if (options.drawVelocity) app.registerSystem({ schedule: AppSchedule.Update, system: drawVelocity }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(WindowPlugin), + typeid(Broadphase2DPlugin), + typeid(NarrowPhase2DPlugin), + typeid(Transform2DPlugin), + typeid(Movable2DPlugin) + ] + } } /** diff --git a/packages/physics/src/plugins/plugin.js b/packages/physics/src/plugins/plugin.js index 53f56ba3..0fc6fa04 100644 --- a/packages/physics/src/plugins/plugin.js +++ b/packages/physics/src/plugins/plugin.js @@ -1,8 +1,10 @@ import { App, Plugin } from '@wimaengine/app' import { Broadphase2DPlugin, NaiveBroadphase2D } from '@wimaengine/broadphase' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' import { EulerIntegrator2DPlugin } from '@wimaengine/integrator' import { NarrowPhase2DPlugin } from '@wimaengine/narrowphase' +import { Transform2DPlugin } from '@wimaengine/transform' +import { typeid } from '@wimaengine/type' import { collisionResponse, updateBodies, updateBounds } from '../systems' // TODO: Convert to a plugin group @@ -42,6 +44,10 @@ export class Physics2DPlugin extends Plugin { .registerPlugin(this.narrowphase) .registerSystem({ schedule: AppSchedule.Update, system: collisionResponse }) } + + requires() { + return [typeid(CorePlugin), typeid(Transform2DPlugin)] + } } /** diff --git a/packages/profiler/src/plugin.js b/packages/profiler/src/plugin.js index f0feca1d..75b3511d 100644 --- a/packages/profiler/src/plugin.js +++ b/packages/profiler/src/plugin.js @@ -1,8 +1,10 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { CorePlugin, AppSchedule, CoreSystems } from '@wimaengine/core' import { World } from '@wimaengine/ecs' import { warn } from '@wimaengine/logger' -import { TimerMode, VirtualClock } from '@wimaengine/time' +import { ReflectPlugin } from '@wimaengine/reflect' +import { TimerMode, VirtualClock, TimePlugin } from '@wimaengine/time' +import { typeid } from '@wimaengine/type' import { Profiler, ProfilerTimer } from './resources' import { registerProfilerTypes } from './systems' @@ -19,6 +21,10 @@ export class ProfilerPlugin extends Plugin { app.registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.End, system: updateProfileViewer }) app.registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.End, system: updateProfileTimer }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(TimePlugin)] + } } /** diff --git a/packages/render-canvas2d/src/plugin.js b/packages/render-canvas2d/src/plugin.js index 64e23719..90bfe112 100644 --- a/packages/render-canvas2d/src/plugin.js +++ b/packages/render-canvas2d/src/plugin.js @@ -1,6 +1,9 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' +import { ReflectPlugin } from '@wimaengine/reflect' import { TextureCache, BasicMaterial } from '@wimaengine/render-core' +import { typeid } from '@wimaengine/type' +import { WindowPlugin } from '@wimaengine/window' import { renderBasicMaterial } from './core' import { Canvas2DMaterialPlugin } from './plugins' import { clearCanvas2d, registerCanvas2DTypes } from './systems' @@ -24,4 +27,8 @@ export class Canvas2DRendererPlugin extends Plugin { update:renderBasicMaterial })) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(WindowPlugin)] + } } diff --git a/packages/render-canvas2d/src/plugins/index.js b/packages/render-canvas2d/src/plugins/index.js index b7641596..3dc70c73 100644 --- a/packages/render-canvas2d/src/plugins/index.js +++ b/packages/render-canvas2d/src/plugins/index.js @@ -2,9 +2,12 @@ /** @import { Canvas2DFunction } from '../types' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' -import { Material } from '@wimaengine/render-core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' +import { Material, RenderCorePlugin } from '@wimaengine/render-core' +import { Transform2DPlugin } from '@wimaengine/transform' import { typeid, typeidGeneric } from '@wimaengine/type' +import { WindowPlugin } from '@wimaengine/window' +import { Canvas2DRendererPlugin } from '../plugin' import { genrender } from '../systems' /** @@ -47,6 +50,16 @@ export class Canvas2DMaterialPlugin extends Plugin { }) } + requires() { + return [ + typeid(CorePlugin), + typeid(Canvas2DRendererPlugin), + typeid(RenderCorePlugin), + typeid(Transform2DPlugin), + typeid(WindowPlugin) + ] + } + name() { return typeidGeneric(Canvas2DMaterialPlugin, [this.material]) } diff --git a/packages/render-core/src/plugin.js b/packages/render-core/src/plugin.js index 8d1c6e16..6477e06e 100644 --- a/packages/render-core/src/plugin.js +++ b/packages/render-core/src/plugin.js @@ -1,8 +1,11 @@ import { App, Plugin } from '@wimaengine/app' import { AssetImporterPlugin, AssetPlugin, Assets } from '@wimaengine/asset' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { ColorPlugin } from '@wimaengine/color' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' -import { typeidGeneric } from '@wimaengine/type' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeidGeneric, typeid } from '@wimaengine/type' import { Mesh, Shader, Image, BasicMaterial } from './assets' import { BasicMaterialInstance, @@ -83,4 +86,13 @@ export class RenderCorePlugin extends Plugin { .setResourceAlias(typeidGeneric(Assets, [Mesh]), MeshAssets) .setResourceAlias(typeidGeneric(Assets, [BasicMaterial]), BasicMaterialAssets) } + + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(ColorPlugin), + typeid(MathPlugin) + ] + } } diff --git a/packages/render-core/src/plugins/material.js b/packages/render-core/src/plugins/material.js index 91994ef3..07f6194a 100644 --- a/packages/render-core/src/plugins/material.js +++ b/packages/render-core/src/plugins/material.js @@ -1,10 +1,13 @@ /** @import { Constructor, TypeId } from '@wimaengine/type' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' +import { ReflectPlugin } from '@wimaengine/reflect' +import { Transform2DPlugin, Transform3DPlugin } from '@wimaengine/transform' import { typeid, typeidGeneric } from '@wimaengine/type' import { Material } from '../assets' import { dropMaterialInstance, MaterialInstance } from '../components' +import { RenderCorePlugin } from '../plugin' import { genBinRenderables2D, genBinRenderables3D, registerMaterialTypes } from '../systems' /** @@ -64,6 +67,16 @@ export class MaterialInstancePlugin extends Plugin { }) } + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(RenderCorePlugin), + typeid(Transform2DPlugin), + typeid(Transform3DPlugin) + ] + } + /** * @returns {TypeId} */ diff --git a/packages/render-webgl/src/plugin.js b/packages/render-webgl/src/plugin.js index 14333019..b735639f 100644 --- a/packages/render-webgl/src/plugin.js +++ b/packages/render-webgl/src/plugin.js @@ -1,9 +1,11 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { EntityHandle, Query, World } from '@wimaengine/ecs' import { warn } from '@wimaengine/logger' -import { MeshAttribute, ProgramCache, BasicMaterial } from '@wimaengine/render-core' -import { MainWindow, Window, Windows } from '@wimaengine/window' +import { ReflectPlugin } from '@wimaengine/reflect' +import { MeshAttribute, ProgramCache, BasicMaterial, RenderCorePlugin } from '@wimaengine/render-core' +import { typeid } from '@wimaengine/type' +import { MainWindow, Window, Windows, WindowPlugin } from '@wimaengine/window' import { WebglMaterialPlugin } from './plugins' import { AttributeMap, ClearColor, MeshCache, UBOCache, WebglProgramCache } from './resources' import { basicMaterial3DFragment, basicMaterial3DVertex } from './shaders' @@ -35,6 +37,15 @@ export class WebglRendererPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.PostMain, system: disposeDroppedMeshes }) .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.PostMain, system: queueMeshes }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(RenderCorePlugin), + typeid(WindowPlugin) + ] + } } /** diff --git a/packages/render-webgl/src/plugins/index.js b/packages/render-webgl/src/plugins/index.js index 5669b20f..6d3837eb 100644 --- a/packages/render-webgl/src/plugins/index.js +++ b/packages/render-webgl/src/plugins/index.js @@ -1,16 +1,19 @@ /** @import {Constructor} from '@wimaengine/type' */ /** @import {UniformBind} from '@wimaengine/render-core' */ -import { App } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' -import { Material } from '@wimaengine/render-core' +import { App, Plugin } from '@wimaengine/app' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' +import { Material, RenderCorePlugin } from '@wimaengine/render-core' +import { Transform3DPlugin } from '@wimaengine/transform' import { typeid, typeidGeneric } from '@wimaengine/type' +import { WindowPlugin } from '@wimaengine/window' +import { WebglRendererPlugin } from '../plugin' import { genRegisterBuffer, genRender, genRenderPipeline } from '../systems' /** * @template {Material & UniformBind} T */ -export class WebglMaterialPlugin { +export class WebglMaterialPlugin extends Plugin { /** * @readonly @@ -38,6 +41,7 @@ export class WebglMaterialPlugin { vertex3d, material }) { + super() this.vertex3d = vertex3d this.fragment3d = fragment3d this.material = material @@ -70,6 +74,16 @@ export class WebglMaterialPlugin { }) } + requires() { + return [ + typeid(CorePlugin), + typeid(WebglRendererPlugin), + typeid(RenderCorePlugin), + typeid(Transform3DPlugin), + typeid(WindowPlugin) + ] + } + name() { return typeidGeneric(WebglMaterialPlugin, [this.material]) } diff --git a/packages/scene/src/plugin.js b/packages/scene/src/plugin.js index e6ea31b1..8c5b81e7 100644 --- a/packages/scene/src/plugin.js +++ b/packages/scene/src/plugin.js @@ -1,8 +1,10 @@ import { App, Plugin } from '@wimaengine/app' import { AssetExporterPlugin, AssetImporterPlugin, AssetPlugin, Assets } from '@wimaengine/asset' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' -import { typeidGeneric } from '@wimaengine/type' +import { HierarchyPlugin } from '@wimaengine/hierarchy' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeidGeneric, typeid } from '@wimaengine/type' import { Scene } from './assets' import { SceneInstance } from './components' import { SceneAdded, SceneDropped, SceneModified } from './events' @@ -42,4 +44,8 @@ export class ScenePlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.End, system: spawnScenes }) .setResourceAlias(typeidGeneric(Assets, [Scene]), SceneAssets) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(HierarchyPlugin)] + } } diff --git a/packages/storage/src/plugin.js b/packages/storage/src/plugin.js index 761e043c..bd245431 100644 --- a/packages/storage/src/plugin.js +++ b/packages/storage/src/plugin.js @@ -1,5 +1,7 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { CorePlugin, AppSchedule } from '@wimaengine/core' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { Session, Storage, Cookies } from './resources' import { registerStorageTypes } from './systems' @@ -15,4 +17,8 @@ export class StoragePlugin extends Plugin { .setResource(new Cookies()) .registerSystem({ schedule: AppSchedule.Startup, system: registerStorageTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } diff --git a/packages/time/src/plugin.js b/packages/time/src/plugin.js index f30d39e4..865f8b57 100644 --- a/packages/time/src/plugin.js +++ b/packages/time/src/plugin.js @@ -1,6 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { CorePlugin, AppSchedule, CoreSystems } from '@wimaengine/core' import { World } from '@wimaengine/ecs' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { Clock } from './clock' import { VirtualClock } from './resource' import { registerTimeTypes, updateTimers } from './systems' @@ -17,6 +19,10 @@ export class TimePlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.Start, system: updateVirtualClock }) .registerSystem({ schedule: AppSchedule.Update, systemGroup: CoreSystems.Start, system: updateTimers }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin)] + } } /** diff --git a/packages/touch/src/plugin.js b/packages/touch/src/plugin.js index dce2fa35..cdc351cf 100644 --- a/packages/touch/src/plugin.js +++ b/packages/touch/src/plugin.js @@ -1,9 +1,10 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { World } from '@wimaengine/ecs' import { Events } from '@wimaengine/event' -import { typeidGeneric } from '@wimaengine/type' -import { PointerCancel, PointerDown, PointerMove, PointerUp } from '@wimaengine/window' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeidGeneric, typeid } from '@wimaengine/type' +import { PointerCancel, PointerDown, PointerMove, PointerUp, WindowPlugin } from '@wimaengine/window' import { TouchPointer } from './core' import { Touches } from './resources' import { registerTouchTypes } from './systems' @@ -19,6 +20,10 @@ export class TouchPlugin extends Plugin { .setResource(new Touches()) .registerSystem({ schedule: AppSchedule.Startup, systemGroup: CoreSystems.Start, system: registerTouchTypes }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(WindowPlugin)] + } } /** diff --git a/packages/transform/src/plugins/remote.js b/packages/transform/src/plugins/remote.js index 8ddf7b4a..a68d3332 100644 --- a/packages/transform/src/plugins/remote.js +++ b/packages/transform/src/plugins/remote.js @@ -1,6 +1,10 @@ import { Plugin, App } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { MathPlugin } from '@wimaengine/math' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { registerRemoteTransform2DTypes, registerRemoteTransform3DTypes, transformRemote2D, transformRemote3D } from '../systems' +import { Transform2DPlugin, Transform3DPlugin } from './transform' export class RemoteTransform2DPlugin extends Plugin { @@ -12,6 +16,15 @@ export class RemoteTransform2DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Startup, system: registerRemoteTransform2DTypes }) .registerSystem({ schedule: AppSchedule.Update, system: transformRemote2D }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(MathPlugin), + typeid(Transform2DPlugin) + ] + } } export class RemoteTransform3DPlugin extends Plugin { @@ -24,4 +37,13 @@ export class RemoteTransform3DPlugin extends Plugin { .registerSystem({ schedule: AppSchedule.Startup, system: registerRemoteTransform3DTypes }) .registerSystem({ schedule: AppSchedule.Update, system: transformRemote3D }) } + + requires() { + return [ + typeid(CorePlugin), + typeid(ReflectPlugin), + typeid(MathPlugin), + typeid(Transform3DPlugin) + ] + } } diff --git a/packages/transform/src/plugins/transform.js b/packages/transform/src/plugins/transform.js index 46528e75..f2cdff57 100644 --- a/packages/transform/src/plugins/transform.js +++ b/packages/transform/src/plugins/transform.js @@ -1,5 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' +import { HierarchyPlugin } from '@wimaengine/hierarchy' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { propagateTransform2D, propagateTransform3D, registerTransform2DTypes, registerTransform3DTypes, synctransform2D, synctransform3D } from '../systems' export class TransformSystems { } @@ -30,6 +33,10 @@ export class Transform2DPlugin extends Plugin { after: [synctransform2D] }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(HierarchyPlugin)] + } } export class Transform3DPlugin extends Plugin { @@ -55,4 +62,8 @@ export class Transform3DPlugin extends Plugin { after: [synctransform3D] }) } + + requires() { + return [typeid(CorePlugin), typeid(ReflectPlugin), typeid(HierarchyPlugin)] + } } diff --git a/packages/tween/src/plugin.js b/packages/tween/src/plugin.js index 0e720e54..1be37ec0 100644 --- a/packages/tween/src/plugin.js +++ b/packages/tween/src/plugin.js @@ -1,7 +1,8 @@ /** @import {TweenLerp} from './typedef' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule } from '@wimaengine/core' +import { AppSchedule, CorePlugin } from '@wimaengine/core' import { Vector2, Quaternion, Vector3, Rotary } from '@wimaengine/math' +import { TimePlugin } from '@wimaengine/time' import { Orientation2D, Orientation3D, Position2D, Position3D, Scale2D, Scale3D } from '@wimaengine/transform' import { typeid, typeidGeneric } from '@wimaengine/type' import { @@ -129,6 +130,10 @@ export class TweenPlugin extends Plugin { }) } + requires() { + return [typeid(CorePlugin), typeid(TimePlugin)] + } + name() { return typeidGeneric(TweenPlugin, [this.component]) } diff --git a/packages/window-dom/src/plugin.js b/packages/window-dom/src/plugin.js index 7a92d787..fb3093b3 100644 --- a/packages/window-dom/src/plugin.js +++ b/packages/window-dom/src/plugin.js @@ -1,7 +1,8 @@ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { ComponentHooks } from '@wimaengine/ecs' -import { Window } from '@wimaengine/window' +import { typeid } from '@wimaengine/type' +import { Window, WindowPlugin } from '@wimaengine/window' import { closeWindow, openWindow } from './hooks' import { resizeWindow } from './systems' @@ -19,4 +20,8 @@ export class DOMWindowPlugin extends Plugin { system: resizeWindow }) } + + requires() { + return [typeid(CorePlugin), typeid(WindowPlugin)] + } } diff --git a/packages/window/src/plugin.js b/packages/window/src/plugin.js index df82166f..8108aaa8 100644 --- a/packages/window/src/plugin.js +++ b/packages/window/src/plugin.js @@ -1,8 +1,11 @@ /** @import {WindowOptions} from './components' */ import { App, Plugin } from '@wimaengine/app' +import { CommandsPlugin } from '@wimaengine/command' import { EntityCommands } from '@wimaengine/commands' -import { AppSchedule, CoreSystems } from '@wimaengine/core' +import { AppSchedule, CoreSystems, CorePlugin } from '@wimaengine/core' import { EventPlugin } from '@wimaengine/event' +import { ReflectPlugin } from '@wimaengine/reflect' +import { typeid } from '@wimaengine/type' import { Window, MainWindow } from './components' import { FileDrag, @@ -97,6 +100,16 @@ export class WindowPlugin extends Plugin { if (this.initPrimaryWindow) app.registerSystem({ schedule: AppSchedule.Startup, system: initPrimaryWindow(this.primaryWindowOptions) }) } + + requires() { + const requires = [typeid(CorePlugin), typeid(ReflectPlugin)] + + if (this.initPrimaryWindow) { + requires.push(typeid(CommandsPlugin)) + } + + return requires + } } /**