|
| 1 | +import { AssetManagerLibrary } from "@nanoforge-dev/asset-manager"; |
| 2 | +import { type IRunOptions } from "@nanoforge-dev/common"; |
| 3 | +import { NanoforgeFactory } from "@nanoforge-dev/core"; |
| 4 | +import { ECSClientLibrary } from "@nanoforge-dev/ecs-client"; |
| 5 | +import { Graphics2DLibrary } from "@nanoforge-dev/graphics-2d"; |
| 6 | +import { InputLibrary } from "@nanoforge-dev/input"; |
| 7 | +import { MusicLibrary } from "@nanoforge-dev/music"; |
| 8 | +import { NetworkClientLibrary } from "@nanoforge-dev/network-client"; |
| 9 | +import { SoundLibrary } from "@nanoforge-dev/sound"; |
| 10 | + |
| 11 | +import { ExampleComponent } from "./components/example.component"; |
| 12 | +import { exampleSystem } from "./systems/example.system"; |
| 13 | + |
| 14 | +export async function main(options: IRunOptions) { |
| 15 | + const app = NanoforgeFactory.createClient({ |
| 16 | + tickRate: 60, |
| 17 | + environment: { |
| 18 | + serverAddress: "127.0.0.1", |
| 19 | + serverTcpPort: "4445", |
| 20 | + serverUdpPort: "4444", |
| 21 | + }, |
| 22 | + }); |
| 23 | + |
| 24 | + const assetManager = new AssetManagerLibrary(); |
| 25 | + const ecs = new ECSClientLibrary(); |
| 26 | + const graphics = new Graphics2DLibrary(); |
| 27 | + const input = new InputLibrary(); |
| 28 | + const music = new MusicLibrary(); |
| 29 | + const network = new NetworkClientLibrary(); |
| 30 | + const sound = new SoundLibrary(); |
| 31 | + |
| 32 | + app.useAssetManager(assetManager); |
| 33 | + app.useComponentSystem(ecs); |
| 34 | + app.useGraphics(graphics); |
| 35 | + app.useInput(input); |
| 36 | + app.useSound(sound); |
| 37 | + app.useNetwork(network); |
| 38 | + app.use(Symbol("music"), music); |
| 39 | + |
| 40 | + await app.init(options); |
| 41 | + |
| 42 | + const registry = ecs.registry; |
| 43 | + |
| 44 | + const exampleEntity = registry.spawnEntity(); |
| 45 | + registry.addComponent(exampleEntity, new ExampleComponent("example", 10)); |
| 46 | + |
| 47 | + registry.addSystem(exampleSystem); |
| 48 | + |
| 49 | + await app.run(); |
| 50 | +} |
0 commit comments