diff --git a/package-lock.json b/package-lock.json index 575f2374..b6e589ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2478,6 +2478,10 @@ "resolved": "packages/command", "link": true }, + "node_modules/@wimaengine/commands": { + "resolved": "packages/commands", + "link": true + }, "node_modules/@wimaengine/core": { "resolved": "packages/core", "link": true @@ -5248,16 +5252,27 @@ "license": "SEE LICENSE in LICENSE.txt", "dependencies": { "@wimaengine/app": "0.3.0", + "@wimaengine/core": "0.3.0", "@wimaengine/ecs": "0.3.0" } }, + "packages/commands": { + "name": "@wimaengine/commands", + "version": "0.3.0", + "license": "SEE LICENSE in LICENSE.txt", + "dependencies": { + "@wimaengine/command": "0.3.0", + "@wimaengine/ecs": "0.3.0", + "@wimaengine/logger": "0.3.0", + "@wimaengine/type": "0.3.0" + } + }, "packages/core": { "name": "@wimaengine/core", "version": "0.3.0", "license": "SEE LICENSE in LICENSE.txt", "dependencies": { "@wimaengine/app": "0.3.0", - "@wimaengine/command": "0.3.0", "@wimaengine/ecs": "0.3.0", "@wimaengine/logger": "0.3.0", "@wimaengine/reflect": "0.3.0", @@ -5331,6 +5346,7 @@ "license": "SEE LICENSE in LICENSE.txt", "dependencies": { "@wimaengine/app": "0.3.0", + "@wimaengine/commands": "0.3.0", "@wimaengine/core": "0.3.0", "@wimaengine/datastructures": "0.3.0", "@wimaengine/ecs": "0.3.0", @@ -5796,6 +5812,7 @@ "dependencies": { "@wimaengine/app": "0.3.0", "@wimaengine/command": "0.3.0", + "@wimaengine/commands": "0.3.0", "@wimaengine/core": "0.3.0", "@wimaengine/ecs": "0.3.0", "@wimaengine/event": "0.3.0", diff --git a/packages/command/package.json b/packages/command/package.json index 31b9c05d..098d08e2 100644 --- a/packages/command/package.json +++ b/packages/command/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@wimaengine/app": "0.3.0", + "@wimaengine/core": "0.3.0", "@wimaengine/ecs": "0.3.0" }, "types": "./dist/index.d.ts" diff --git a/packages/command/src/core/command.js b/packages/command/src/core/command.js index 9fa282b4..5e638635 100644 --- a/packages/command/src/core/command.js +++ b/packages/command/src/core/command.js @@ -1,4 +1,4 @@ -import { World } from '@wimaengine/ecs' +/** @import { World } from '@wimaengine/ecs' */ export class Command { diff --git a/packages/command/src/index.js b/packages/command/src/index.js index 00ebad19..fa88ac3d 100644 --- a/packages/command/src/index.js +++ b/packages/command/src/index.js @@ -1,4 +1,5 @@ export * from './plugin' export * from './core' export * from './resources' +export * from './systems' export * from './typedef' diff --git a/packages/command/src/plugin.js b/packages/command/src/plugin.js index 8108b1e4..9b1ce0c9 100644 --- a/packages/command/src/plugin.js +++ b/packages/command/src/plugin.js @@ -1,5 +1,8 @@ -import { App, Plugin } from '@wimaengine/app' +/** @import { App } from '@wimaengine/app' */ +import { Plugin } from '@wimaengine/app' +import { AppSchedule, CoreSystems } from '@wimaengine/core' import { CommandQueue } from './resources' +import { executeCommands } from './systems' export class CommandsPlugin extends Plugin { @@ -9,5 +12,15 @@ export class CommandsPlugin extends Plugin { register(app) { app .setResource(new CommandQueue()) + .registerSystem({ + schedule: AppSchedule.Startup, + systemGroup: CoreSystems.End, + system: executeCommands + }) + .registerSystem({ + schedule: AppSchedule.Update, + systemGroup: CoreSystems.End, + system: executeCommands + }) } } diff --git a/packages/core/src/systems/commands.js b/packages/command/src/systems/commands.js similarity index 68% rename from packages/core/src/systems/commands.js rename to packages/command/src/systems/commands.js index a0b49d46..756fe749 100644 --- a/packages/core/src/systems/commands.js +++ b/packages/command/src/systems/commands.js @@ -1,5 +1,5 @@ -import { CommandQueue } from '@wimaengine/command' -import { World } from '@wimaengine/ecs' +/** @import { World } from '@wimaengine/ecs' */ +import { CommandQueue } from '../resources' /** * @param {World} world diff --git a/packages/command/src/systems/index.js b/packages/command/src/systems/index.js new file mode 100644 index 00000000..7418efd2 --- /dev/null +++ b/packages/command/src/systems/index.js @@ -0,0 +1 @@ +export * from './commands' diff --git a/packages/command/tests/executecommands.test.js b/packages/command/tests/executecommands.test.js new file mode 100644 index 00000000..9c55f3cd --- /dev/null +++ b/packages/command/tests/executecommands.test.js @@ -0,0 +1,31 @@ +import { strictEqual } from 'node:assert' +import { describe, test } from 'vitest' +import { Command, CommandQueue, executeCommands } from '@wimaengine/command' +import { World } from '@wimaengine/ecs' + +class TestCommand extends Command { + /** + * @param {World} world + */ + execute(world) { + world.setResource(new TestResource()) + } +} + +class TestResource { } + +describe('Testing `executeCommands`', () => { + test('drains and executes queued commands', () => { + const world = new World() + const queue = new CommandQueue() + const command = new TestCommand() + + queue.add(command) + world.setResource(queue) + + executeCommands(world) + + strictEqual(world.hasResource(TestResource), true) + strictEqual(queue.size(), 0) + }) +}) diff --git a/packages/commands/index.js b/packages/commands/index.js new file mode 100644 index 00000000..6f39cd49 --- /dev/null +++ b/packages/commands/index.js @@ -0,0 +1 @@ +export * from './src' diff --git a/packages/commands/package.json b/packages/commands/package.json new file mode 100644 index 00000000..9f10e8bb --- /dev/null +++ b/packages/commands/package.json @@ -0,0 +1,39 @@ +{ + "name": "@wimaengine/commands", + "description": "Wima engine high-level commands package.", + "version": "0.3.0", + "type": "module", + "license": "SEE LICENSE in LICENSE.txt", + "author": "Wima engine contributors", + "repository": { + "type": "git", + "url": "https://github.com/wimaengine/wima.git" + }, + "homepage": "https://wimaengine.org", + "bugs": { + "url": "https://github.com/wimaengine/wima/issues" + }, + "main": "./dist/index.umd.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.module.js", + "require": "./dist/index.umd.js" + } + }, + "files": [ + "dist" + ], + "scripts": { + "build": "vite build --config ../../.config/vite.config.js", + "test": "vitest run --dir tests --passWithNoTests", + "types": "tsc -p ./tsc.type.json" + }, + "dependencies": { + "@wimaengine/command": "0.3.0", + "@wimaengine/ecs": "0.3.0", + "@wimaengine/logger": "0.3.0", + "@wimaengine/type": "0.3.0" + }, + "types": "./dist/index.d.ts" +} diff --git a/packages/core/src/commands/addresource.js b/packages/commands/src/commands/addresource.js similarity index 88% rename from packages/core/src/commands/addresource.js rename to packages/commands/src/commands/addresource.js index 2665f056..eb0ff16d 100644 --- a/packages/core/src/commands/addresource.js +++ b/packages/commands/src/commands/addresource.js @@ -1,5 +1,5 @@ +/** @import { World } from '@wimaengine/ecs' */ import { Command } from '@wimaengine/command' -import { World } from '@wimaengine/ecs' export class AddResourceCommand extends Command { diff --git a/packages/core/src/commands/despawn.js b/packages/commands/src/commands/despawn.js similarity index 78% rename from packages/core/src/commands/despawn.js rename to packages/commands/src/commands/despawn.js index ac4beff3..350a8fed 100644 --- a/packages/core/src/commands/despawn.js +++ b/packages/commands/src/commands/despawn.js @@ -1,6 +1,5 @@ -/** @import { EntityHandle } from '@wimaengine/ecs' */ +/** @import { EntityHandle, World } from '@wimaengine/ecs' */ import { Command } from '@wimaengine/command' -import { World } from '@wimaengine/ecs' export class DespawnCommand extends Command { diff --git a/packages/core/src/commands/index.js b/packages/commands/src/commands/index.js similarity index 100% rename from packages/core/src/commands/index.js rename to packages/commands/src/commands/index.js diff --git a/packages/core/src/commands/removeresource.js b/packages/commands/src/commands/removeresource.js similarity index 86% rename from packages/core/src/commands/removeresource.js rename to packages/commands/src/commands/removeresource.js index 13ba6732..a82bb027 100644 --- a/packages/core/src/commands/removeresource.js +++ b/packages/commands/src/commands/removeresource.js @@ -1,6 +1,5 @@ /** @import {Constructor} from '@wimaengine/type' */ import { Command } from '@wimaengine/command' -import { World } from '@wimaengine/ecs' export class RemoveResourceCommand extends Command { @@ -19,7 +18,7 @@ export class RemoveResourceCommand extends Command { } /** - * @param {World} world + * @param {import('@wimaengine/ecs').World} world */ execute(world) { world.removeResource(this.resourceType) diff --git a/packages/core/src/commands/setresourcealias.js b/packages/commands/src/commands/setresourcealias.js similarity index 88% rename from packages/core/src/commands/setresourcealias.js rename to packages/commands/src/commands/setresourcealias.js index 2b31c0bd..c93bfee6 100644 --- a/packages/core/src/commands/setresourcealias.js +++ b/packages/commands/src/commands/setresourcealias.js @@ -1,6 +1,5 @@ /** @import {Constructor, TypeId} from '@wimaengine/type' */ import { Command } from '@wimaengine/command' -import { World } from '@wimaengine/ecs' export class SetResourceAliasCommand extends Command { @@ -27,7 +26,7 @@ export class SetResourceAliasCommand extends Command { } /** - * @param {World} world + * @param {import('@wimaengine/ecs').World} world */ execute(world) { world.setResourceAlias(this.id, this.alias) diff --git a/packages/core/src/commands/spawn.js b/packages/commands/src/commands/spawn.js similarity index 91% rename from packages/core/src/commands/spawn.js rename to packages/commands/src/commands/spawn.js index c85f599a..934a5241 100644 --- a/packages/core/src/commands/spawn.js +++ b/packages/commands/src/commands/spawn.js @@ -1,5 +1,5 @@ +/** @import { EntityHandle, World } from '@wimaengine/ecs' */ import { Command } from '@wimaengine/command' -import { World, EntityHandle } from '@wimaengine/ecs' export class SpawnCommand extends Command { diff --git a/packages/core/src/core/entity.js b/packages/commands/src/core/entity.js similarity index 95% rename from packages/core/src/core/entity.js rename to packages/commands/src/core/entity.js index 71ddc0ed..c01b5a75 100644 --- a/packages/core/src/core/entity.js +++ b/packages/commands/src/core/entity.js @@ -1,6 +1,5 @@ -/** @import { EntityHandle } from '@wimaengine/ecs' */ +/** @import { EntityHandle, World } from '@wimaengine/ecs' */ import { CommandQueue } from '@wimaengine/command' -import { World } from '@wimaengine/ecs' import { assert } from '@wimaengine/logger' import { SpawnCommand, DespawnCommand } from '../commands' diff --git a/packages/commands/src/core/index.js b/packages/commands/src/core/index.js new file mode 100644 index 00000000..105b849d --- /dev/null +++ b/packages/commands/src/core/index.js @@ -0,0 +1,2 @@ +export * from './entity' +export * from './resourcecommands' diff --git a/packages/core/src/core/resourcecommands.js b/packages/commands/src/core/resourcecommands.js similarity index 93% rename from packages/core/src/core/resourcecommands.js rename to packages/commands/src/core/resourcecommands.js index 0ffe65d9..2f3c9af0 100644 --- a/packages/core/src/core/resourcecommands.js +++ b/packages/commands/src/core/resourcecommands.js @@ -1,6 +1,5 @@ /** @import {Constructor, TypeId} from '@wimaengine/type' */ import { CommandQueue } from '@wimaengine/command' -import { World } from '@wimaengine/ecs' import { AddResourceCommand, RemoveResourceCommand, SetResourceAliasCommand } from '../commands' export class ResourceCommands { @@ -12,7 +11,7 @@ export class ResourceCommands { buffer /** - * @param {World} world + * @param {import('@wimaengine/ecs').World} world */ constructor(world) { this.buffer = world.getResource(CommandQueue) diff --git a/packages/commands/src/index.js b/packages/commands/src/index.js new file mode 100644 index 00000000..3c3c3bab --- /dev/null +++ b/packages/commands/src/index.js @@ -0,0 +1,2 @@ +export * from './commands' +export * from './core' diff --git a/packages/core/tests/resourcecommands.test.js b/packages/commands/tests/resourcecommands.test.js similarity index 93% rename from packages/core/tests/resourcecommands.test.js rename to packages/commands/tests/resourcecommands.test.js index 3ad06fb9..7adedab2 100644 --- a/packages/core/tests/resourcecommands.test.js +++ b/packages/commands/tests/resourcecommands.test.js @@ -1,10 +1,9 @@ import { strictEqual } from 'node:assert' import { describe, test } from 'vitest' -import { CommandQueue } from '@wimaengine/command' +import { CommandQueue, executeCommands } from '@wimaengine/command' import { World } from '@wimaengine/ecs' import { typeid } from '@wimaengine/type' import { ResourceCommands } from '../src/index.js' -import { executeCommands } from '../src/systems/index.js' class TestResource { } class TestAlias extends TestResource { } diff --git a/packages/commands/tsc.type.json b/packages/commands/tsc.type.json new file mode 100644 index 00000000..ee6b2cc7 --- /dev/null +++ b/packages/commands/tsc.type.json @@ -0,0 +1,15 @@ +{ + "extends": "../../.config/tsc.type.base.json", + "include": [ + "index.js" + ], + "exclude": [ + "dist/**", + "types/**", + "tests/**" + ], + "compilerOptions": { + "declarationDir": "./types", + "rootDir": "." + } +} diff --git a/packages/core/package.json b/packages/core/package.json index bd42afa5..12da9e65 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -31,7 +31,6 @@ }, "dependencies": { "@wimaengine/app": "0.3.0", - "@wimaengine/command": "0.3.0", "@wimaengine/ecs": "0.3.0", "@wimaengine/logger": "0.3.0", "@wimaengine/reflect": "0.3.0", diff --git a/packages/core/src/core/index.js b/packages/core/src/core/index.js index b4768a1a..e2f6884a 100644 --- a/packages/core/src/core/index.js +++ b/packages/core/src/core/index.js @@ -1,7 +1,5 @@ export * from './schedules' export * from './runner' -export * from './entity' -export * from './resourcecommands' export * from './systemgroups' export * from './snapshot' export * from './worlds' diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 96bda7a8..88c7f15c 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -1,3 +1,2 @@ -export * from './commands' export * from './core' export * from './plugin' diff --git a/packages/core/src/plugin.js b/packages/core/src/plugin.js index b2d06e59..7bb1ca32 100644 --- a/packages/core/src/plugin.js +++ b/packages/core/src/plugin.js @@ -1,7 +1,8 @@ -import { App, Plugin } from '@wimaengine/app' +/** @import { App } from '@wimaengine/app' */ +import { Plugin } from '@wimaengine/app' import { SchedulerBuilder } from '@wimaengine/schedule' import { AppSchedule, CoreSystems, MainWorld, defaultRunner } from './core' -import { executeCommands, registerCoreTypes, registerPrimitiveTypes } from './systems' +import { registerCoreTypes, registerPrimitiveTypes } from './systems' export class CorePlugin extends Plugin { @@ -81,15 +82,5 @@ export class CorePlugin extends Plugin { schedule: AppSchedule.Startup, system: registerPrimitiveTypes }) - .registerSystem({ - schedule: AppSchedule.Startup, - systemGroup: CoreSystems.End, - system: executeCommands - }) - .registerSystem({ - schedule: AppSchedule.Update, - systemGroup: CoreSystems.End, - system: executeCommands - }) } } diff --git a/packages/core/src/systems/index.js b/packages/core/src/systems/index.js index 5a366a05..c9f6f047 100644 --- a/packages/core/src/systems/index.js +++ b/packages/core/src/systems/index.js @@ -1,2 +1 @@ export * from './types' -export * from './commands' diff --git a/packages/core/src/systems/types.js b/packages/core/src/systems/types.js index 67a1f519..c53eb358 100644 --- a/packages/core/src/systems/types.js +++ b/packages/core/src/systems/types.js @@ -1,4 +1,5 @@ -import { EntityHandle, World } from '@wimaengine/ecs' +/** @import { World } from '@wimaengine/ecs' */ +import { EntityHandle } from '@wimaengine/ecs' import { ArrayInfo, Field, MapInfo, MethodEntry, OpaqueInfo, StructInfo, TypeEntry, TypeRegistry } from '@wimaengine/reflect' import { setTypeId, typeid, typeidGeneric } from '@wimaengine/type' diff --git a/packages/emitter/package.json b/packages/emitter/package.json index b04ea15a..a3f071ed 100644 --- a/packages/emitter/package.json +++ b/packages/emitter/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@wimaengine/app": "0.3.0", + "@wimaengine/commands": "0.3.0", "@wimaengine/core": "0.3.0", "@wimaengine/datastructures": "0.3.0", "@wimaengine/ecs": "0.3.0", diff --git a/packages/emitter/src/components/emitter.js b/packages/emitter/src/components/emitter.js index cf3008be..793e7c4c 100644 --- a/packages/emitter/src/components/emitter.js +++ b/packages/emitter/src/components/emitter.js @@ -1,4 +1,4 @@ -import { EntityCommands } from '@wimaengine/core' +/** @import { EntityCommands } from '@wimaengine/commands' */ import { Range } from '@wimaengine/datastructures' import { EntityHandle } from '@wimaengine/ecs' diff --git a/packages/emitter/src/systems/index.js b/packages/emitter/src/systems/index.js index f85ed7dd..33b098f5 100644 --- a/packages/emitter/src/systems/index.js +++ b/packages/emitter/src/systems/index.js @@ -1,4 +1,4 @@ -import { EntityCommands } from '@wimaengine/core' +import { EntityCommands } from '@wimaengine/commands' import { EntityHandle, has, Query, World } from '@wimaengine/ecs' import { Timer } from '@wimaengine/time' import { Position2D, Orientation2D, GlobalTransform2D, GlobalTransform3D, Orientation3D, Position3D, Scale3D } from '@wimaengine/transform' diff --git a/packages/window/package.json b/packages/window/package.json index caf65512..98b79b46 100644 --- a/packages/window/package.json +++ b/packages/window/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@wimaengine/app": "0.3.0", + "@wimaengine/commands": "0.3.0", "@wimaengine/command": "0.3.0", "@wimaengine/core": "0.3.0", "@wimaengine/ecs": "0.3.0", diff --git a/packages/window/src/plugin.js b/packages/window/src/plugin.js index 1fdb6505..df82166f 100644 --- a/packages/window/src/plugin.js +++ b/packages/window/src/plugin.js @@ -1,6 +1,7 @@ /** @import {WindowOptions} from './components' */ import { App, Plugin } from '@wimaengine/app' -import { AppSchedule, CoreSystems, EntityCommands } from '@wimaengine/core' +import { EntityCommands } from '@wimaengine/commands' +import { AppSchedule, CoreSystems } from '@wimaengine/core' import { EventPlugin } from '@wimaengine/event' import { Window, MainWindow } from './components' import { diff --git a/src/index.js b/src/index.js index 7aa785c5..2ed7baeb 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ export * from '@wimaengine/audio' export * from '@wimaengine/broadphase' export * from '@wimaengine/color' export * from '@wimaengine/command' +export * from '@wimaengine/commands' export * from '@wimaengine/core' export * from '@wimaengine/damping' export * from '@wimaengine/datastructures'