Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions example/pong/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const main = async (options: IRunOptions) => {

await app.init(options);

const ball = ecsLibrary.createEntity();
const ball = ecsLibrary.spawnEntity();
ecsLibrary.addComponent(ball, new Velocity(0.04, 0));
ecsLibrary.addComponent(ball, new Position(0.5, 0));
ecsLibrary.addComponent(ball, new Bounce());
Expand All @@ -45,7 +45,7 @@ export const main = async (options: IRunOptions) => {
),
);

const bg = ecsLibrary.createEntity();
const bg = ecsLibrary.spawnEntity();
ecsLibrary.addComponent(
bg,
new RectangleComponent(
Expand All @@ -57,7 +57,7 @@ export const main = async (options: IRunOptions) => {
),
);

const topWall = ecsLibrary.createEntity();
const topWall = ecsLibrary.spawnEntity();
ecsLibrary.addComponent(
topWall,
new RectangleComponent(
Expand All @@ -69,7 +69,7 @@ export const main = async (options: IRunOptions) => {
ecsLibrary.addComponent(topWall, new Position(-1.8, 0.91));
ecsLibrary.addComponent(topWall, new Hitbox(3.6, 0.1));

const botWall = ecsLibrary.createEntity();
const botWall = ecsLibrary.spawnEntity();
ecsLibrary.addComponent(
botWall,
new RectangleComponent(
Expand All @@ -81,7 +81,7 @@ export const main = async (options: IRunOptions) => {
ecsLibrary.addComponent(botWall, new Position(-1.8, -1));
ecsLibrary.addComponent(botWall, new Hitbox(3.6, 0.1));

const player1 = ecsLibrary.createEntity();
const player1 = ecsLibrary.spawnEntity();
ecsLibrary.addComponent(player1, new Position(-1.8, -0.3));
ecsLibrary.addComponent(player1, new Velocity(0, 0.1));
ecsLibrary.addComponent(player1, new Hitbox(0.1, 0.5));
Expand All @@ -95,7 +95,7 @@ export const main = async (options: IRunOptions) => {
),
);

const player2 = ecsLibrary.createEntity();
const player2 = ecsLibrary.spawnEntity();
ecsLibrary.addComponent(player2, new Position(1.7, -0.3));
ecsLibrary.addComponent(player2, new Velocity(0, 0.1));
ecsLibrary.addComponent(player2, new Hitbox(0.1, 0.5));
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,27 @@
"devDependencies": {
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"@eslint/js": "^9.22.0",
"@eslint/js": "^9.23.0",
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"@types/node": "^22.13.10",
"eslint": "^9.22.0",
"@types/node": "^22.13.13",
"eslint": "^9.23.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-format": "^1.0.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-prettier": "^5.2.5",
"globals": "^16.0.0",
"husky": "^9.1.7",
"lerna": "^8.2.1",
"lint-staged": "^15.4.3",
"lint-staged": "^15.5.0",
"prettier": "^3.5.3",
"taze": "^19.0.2",
"typescript": "^5.8.2",
"typescript-eslint": "^8.26.0"
"typescript-eslint": "^8.28.0"
},
"engines": {
"node": "23.6.0",
"pnpm": "10.6.2"
"pnpm": "10.6.5"
},
"packageManager": "[email protected].2",
"packageManager": "[email protected].5",
"lint-staged": {
"**/*.{js,ts}": [
"eslint --fix",
Expand Down
18 changes: 10 additions & 8 deletions packages/asset-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,29 @@
"devDependencies": {
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"@eslint/js": "^9.22.0",
"@eslint/js": "^9.23.0",
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"@types/jest": "^29.5.14",
"@types/node": "^22.13.10",
"eslint": "^9.22.0",
"@types/node": "^22.13.13",
"eslint": "^9.23.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-format": "^1.0.1",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-prettier": "^5.2.5",
"globals": "^16.0.0",
"jest": "^29.7.0",
"lint-staged": "^15.4.3",
"lint-staged": "^15.5.0",
"prettier": "^3.5.3",
"ts-jest": "^29.2.6",
"taze": "^19.0.2",
"ts-jest": "^29.3.0",
"typescript": "^5.8.2",
"typescript-eslint": "^8.26.0"
"typescript-eslint": "^8.28.0"
},
"engines": {
"node": "23.6.0",
"pnpm": "10.6.2"
"pnpm": "10.6.5"
},
"packageManager": "[email protected]",
"lint-staged": {
"**/*.{js,ts}": [
"eslint --fix",
Expand Down
14 changes: 8 additions & 6 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,23 @@
"devDependencies": {
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"@eslint/js": "^9.22.0",
"@eslint/js": "^9.23.0",
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"eslint": "^9.22.0",
"eslint": "^9.23.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-format": "^1.0.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-prettier": "^5.2.5",
"globals": "^16.0.0",
"lint-staged": "^15.4.3",
"lint-staged": "^15.5.0",
"prettier": "^3.5.3",
"typescript-eslint": "^8.26.0"
"taze": "^19.0.2",
"typescript-eslint": "^8.28.0"
},
"engines": {
"node": "23.6.0",
"pnpm": "10.6.2"
"pnpm": "10.6.5"
},
"packageManager": "[email protected]",
"lint-staged": {
"**/*.{js,ts}": [
"eslint --fix",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { type ILibraryOptions } from "../library.type";

export const DEFAULT_LIBRARY_OPTIONS: ILibraryOptions = {
dependencies: [],
runBefore: [],
runAfter: [],
};
23 changes: 22 additions & 1 deletion packages/common/src/library/libraries/library.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import { type ClearContext, type InitContext } from "../../context";
import { type ILibrary } from "./library.type";
import { RelationshipHandler } from "../relationship/relationship-handler";
import { DEFAULT_LIBRARY_OPTIONS } from "./consts/library-options-default.const";
import { type ILibrary, type ILibraryOptions } from "./library.type";

export abstract class Library implements ILibrary {
protected _relationship: RelationshipHandler;

constructor(rawOptions?: Partial<ILibraryOptions>) {
const options = {
...DEFAULT_LIBRARY_OPTIONS,
...rawOptions,
};

this._relationship = new RelationshipHandler(
options.dependencies,
options.runBefore,
options.runAfter,
);
}

get relationship(): RelationshipHandler {
return this._relationship;
}

abstract get name(): string;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
9 changes: 9 additions & 0 deletions packages/common/src/library/libraries/library.type.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { type ApplicationContext, type ClearContext } from "../../context";
import { type RelationshipHandler } from "../relationship/relationship-handler";

export interface ILibrary {
get name(): string;

get relationship(): RelationshipHandler;

init(context: ApplicationContext): Promise<void>;

clear(context: ClearContext): Promise<void>;
}

export interface ILibraryOptions {
dependencies: symbol[];
runBefore: symbol[];
runAfter: symbol[];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type LibraryContext } from "../../../context";
import { type ILibrary } from "../../libraries/library.type";
import { type ILibrary } from "../../libraries";

export class LibraryHandle<T extends ILibrary = ILibrary> {
private readonly _symbol: symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import { BaseLibraryManager } from "./base-library.manager";

export enum DefaultLibrariesEnum {
ASSET_MANAGER,
INPUT,
COMPONENT_SYSTEM,
NETWORK,
GRAPHICS,
INPUT,
NETWORK,
}

const DEFAULT_LIBRARIES: { index: DefaultLibrariesEnum; sym: symbol }[] = [
{ index: DefaultLibrariesEnum.ASSET_MANAGER, sym: ASSET_MANAGER_LIBRARY },
{ index: DefaultLibrariesEnum.COMPONENT_SYSTEM, sym: COMPONENT_SYSTEM_LIBRARY },
{ index: DefaultLibrariesEnum.NETWORK, sym: NETWORK_LIBRARY },
{ index: DefaultLibrariesEnum.GRAPHICS, sym: GRAPHICS_LIBRARY },
{ index: DefaultLibrariesEnum.NETWORK, sym: NETWORK_LIBRARY },
];

export class LibraryManager extends BaseLibraryManager {
Expand Down
30 changes: 30 additions & 0 deletions packages/common/src/library/relationship/relationship-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export class RelationshipHandler {
private readonly _dependencies: symbol[];
private readonly _runBefore: symbol[];
private readonly _runAfter: symbol[];

/**
* Constructor for RelationshipHandler
*
* @param dependencies - Dependencies of the library
* @param runBefore - Libraries needed to run before this one
* @param runAfter - Libraries needed to run after this one
*/
constructor(dependencies: symbol[], runBefore: symbol[], runAfter: symbol[]) {
this._dependencies = dependencies;
this._runBefore = runBefore;
this._runAfter = runAfter;
}

get dependencies(): symbol[] {
return this._dependencies;
}

get runBefore(): symbol[] {
return this._runBefore;
}

get runAfter(): symbol[] {
return this._runAfter;
}
}
19 changes: 13 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,31 @@
"taze": "taze major -w",
"lint-staged": "lint-staged"
},
"dependencies": {
"@nanoforge/asset-manager": "workspace:^",
"@nanoforge/common": "workspace:^",
"@nanoforge/input": "workspace:^"
},
"devDependencies": {
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"@eslint/js": "^9.22.0",
"@eslint/js": "^9.23.0",
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"eslint": "^9.22.0",
"eslint": "^9.23.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-format": "^1.0.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-prettier": "^5.2.5",
"globals": "^16.0.0",
"lint-staged": "^15.4.3",
"lint-staged": "^15.5.0",
"prettier": "^3.5.3",
"typescript-eslint": "^8.26.0"
"taze": "^19.0.2",
"typescript-eslint": "^8.28.0"
},
"engines": {
"node": "23.6.0",
"pnpm": "10.6.2"
"pnpm": "10.6.5"
},
"packageManager": "[email protected]",
"lint-staged": {
"**/*.{js,ts}": [
"eslint --fix",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/application/nanoforge-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export abstract class NanoforgeApplication {
}

public run() {
this._core.run().then(() => {
console.info("Game ended successfully.");
});
this._core.run();
}
}
12 changes: 10 additions & 2 deletions packages/core/src/application/nanoforge-factory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { AssetManagerLibrary } from "@nanoforge/asset-manager";
import { InputLibrary } from "@nanoforge/input";

import { type IApplicationOptions } from "./application-options.type";
import { NanoforgeClient } from "./nanoforge-client";
import { NanoforgeServer } from "./nanoforge-server";

class NanoforgeFactoryStatic {
createClient(options?: Partial<IApplicationOptions>): NanoforgeClient {
return new NanoforgeClient(options);
const app = new NanoforgeClient(options);
app.useAssetManager(new AssetManagerLibrary());
app.useInput(new InputLibrary());
return app;
}

createServer(options?: Partial<IApplicationOptions>): NanoforgeServer {
return new NanoforgeServer(options);
const app = new NanoforgeServer(options);
app.useAssetManager(new AssetManagerLibrary());
return app;
}
}

Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/common/library/manager/library.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "@nanoforge/common";

import { EditableLibraryContext } from "../../context/contexts/library.editable-context";
import { Relationship } from "../relationship-functions";

export class EditableLibraryManager extends LibraryManager {
public set(sym: symbol, library: ILibrary) {
Expand Down Expand Up @@ -58,11 +59,23 @@ export class EditableLibraryManager extends LibraryManager {
this._set(DefaultLibrariesEnum.INPUT, INPUT_LIBRARY, library, new EditableLibraryContext());
}

public getLibraries(): LibraryHandle<ILibrary>[] {
public getLibraries(): LibraryHandle[] {
return this._libraries;
}

public getRunnerLibraries(): LibraryHandle<IRunnerLibrary>[] {
public getInitLibraries(): LibraryHandle[] {
return Relationship.getLibrariesByDependencies(this._libraries);
}

public getExecutionLibraries(): LibraryHandle<IRunnerLibrary>[] {
return Relationship.getLibrariesByRun(this._getRunnerLibraries());
}

public getClearLibraries(): LibraryHandle[] {
return Relationship.getLibrariesByDependencies(this._libraries, true);
}

private _getRunnerLibraries(): LibraryHandle<IRunnerLibrary>[] {
return this._libraries.filter(
(handle) => handle && typeof handle.library["run"] === "function",
) as LibraryHandle<IRunnerLibrary>[];
Expand Down
Loading
Loading