Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/01-packages_bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ body:
- ecs-lib
- ecs-server
- graphics-2d
- graphics-2d-editor
- input
- music
- network-client
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/03-feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ body:
- ecs-lib
- ecs-server
- graphics-2d
- graphics-2d-editor
- input
- music
- network-client
Expand Down
4 changes: 4 additions & 0 deletions .github/issue-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ packages:graphics-2d:
- "### Which (package|utils|package or utils) is this (bug
report|feature request) for\\?\\n\\ngraphics-2d\\n"

packages:graphics-2d-editor:
- "### Which (package|utils|package or utils) is this (bug
report|feature request) for\\?\\n\\ngraphics-2d-editor\\n"

packages:input:
- "### Which (package|utils|package or utils) is this (bug
report|feature request) for\\?\\n\\ninput\\n"
Expand Down
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ packages:graphics-2d:
- packages/graphics-2d/*
- packages/graphics-2d/**/*

packages:graphics-2d-editor:
- changed-files:
- any-glob-to-any-file:
- packages/graphics-2d-editor/*
- packages/graphics-2d-editor/**/*

packages:input:
- changed-files:
- any-glob-to-any-file:
Expand Down
4 changes: 4 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
description: "Related to Graphics2D library"
color: "aaa3dc"

- name: "packages:graphics-2d-editor"
description: "Related to Graphics2D Editor library"
color: "aaa3dc"

- name: "packages:input"
description: "Related to Input library"
color: "aaa3dc"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/alpha-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- "@nanoforge-dev/ecs-lib"
- "@nanoforge-dev/ecs-server"
- "@nanoforge-dev/graphics-2d"
- "@nanoforge-dev/graphics-2d-editor"
- "@nanoforge-dev/input"
- "@nanoforge-dev/music"
- "@nanoforge-dev/network-client"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Create release PR
uses: ./node_modules/@nanoforge-dev/actions/actions/create-packages-release-pr
with:
packages: "@nanoforge-dev/asset-manager,@nanoforge-dev/common,@nanoforge-dev/config,@nanoforge-dev/core,@nanoforge-dev/core-editor,@nanoforge-dev/ecs-client,@nanoforge-dev/ecs-lib,@nanoforge-dev/ecs-server,@nanoforge-dev/graphics-2d,@nanoforge-dev/input,@nanoforge-dev/music,@nanoforge-dev/network-client,@nanoforge-dev/network-server,@nanoforge-dev/sound"
packages: "@nanoforge-dev/asset-manager,@nanoforge-dev/common,@nanoforge-dev/config,@nanoforge-dev/core,@nanoforge-dev/core-editor,@nanoforge-dev/ecs-client,@nanoforge-dev/ecs-lib,@nanoforge-dev/ecs-server,@nanoforge-dev/graphics-2d,@nanoforge-dev/graphics-2d-editor,@nanoforge-dev/input,@nanoforge-dev/music,@nanoforge-dev/network-client,@nanoforge-dev/network-server,@nanoforge-dev/sound"
version: ${{ inputs.version }}
branch-format: "releases/nanoforge@{version}"
commit-format: "chore: release @nanoforge-dev/engine@{version}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Release packages
uses: ./node_modules/@nanoforge-dev/actions/actions/release-packages
with:
packages: "@nanoforge-dev/asset-manager,@nanoforge-dev/common,@nanoforge-dev/config,@nanoforge-dev/core,@nanoforge-dev/core-editor,@nanoforge-dev/ecs-client,@nanoforge-dev/ecs-lib,@nanoforge-dev/ecs-server,@nanoforge-dev/graphics-2d,@nanoforge-dev/input,@nanoforge-dev/music,@nanoforge-dev/network-client,@nanoforge-dev/network-server,@nanoforge-dev/sound"
packages: "@nanoforge-dev/asset-manager,@nanoforge-dev/common,@nanoforge-dev/config,@nanoforge-dev/core,@nanoforge-dev/core-editor,@nanoforge-dev/ecs-client,@nanoforge-dev/ecs-lib,@nanoforge-dev/ecs-server,@nanoforge-dev/graphics-2d,@nanoforge-dev/graphics-2d-editor,@nanoforge-dev/input,@nanoforge-dev/music,@nanoforge-dev/network-client,@nanoforge-dev/network-server,@nanoforge-dev/sound"
tag-format: "{version}"
latest: true
env:
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/library/libraries/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type { ILibrary } from "./library.type";
export { Library } from "./library";

export * from "./abstracts";
export * from "./consts";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type LibraryContext } from "../../../context";
import { type ILibrary } from "../../libraries";
import { LibraryHandle } from "../handle/library.handle";
import { DefaultLibrariesEnum } from "./library.manager";

export class BaseLibraryManager {
protected _libraries: LibraryHandle[] = [];
Expand All @@ -16,7 +17,7 @@ export class BaseLibraryManager {
}

protected setNewLibrary(sym: symbol, library: ILibrary, context: LibraryContext): void {
const index = this._libraries.length;
const index = Math.max(this._libraries.length, Object.keys(DefaultLibrariesEnum).length);
this._setIndex(sym, index);
this._set(index, sym, library, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {
type IComponentSystemLibrary,
type ILibrary,
type INetworkLibrary,
type IRunOptions,
NfNotInitializedException,
} from "@nanoforge-dev/common";

import { ApplicationConfig } from "../../../core/src/application/application-config";
import type { IApplicationOptions } from "../../../core/src/application/application-options.type";
import { EditableApplicationContext } from "../../../core/src/common/context/contexts/application.editable-context";
import { type IEditorRunOptions } from "../common/context/options.type";
import { Core } from "../core/core";

/**
Expand Down Expand Up @@ -77,9 +77,9 @@ export abstract class NanoforgeApplication {
/**
* Initialise all registered libraries and prepare the engine for the game loop.
*
* @param options - Editor run options including save/load callbacks and canvas container.
* @param options - Editor run options including save/events callbacks and canvas container.
*/
public init(options: IEditorRunOptions): Promise<void> {
public init(options: IRunOptions): Promise<void> {
this._core = new Core(
this.applicationConfig,
new EditableApplicationContext(this.applicationConfig.libraryManager),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
type ApplicationContext,
type IConfigRegistry,
type IRunOptions,
InitContext,
type LibraryManager,
} from "@nanoforge-dev/common";

import { type EventEmitter } from "../event-emitter";

export class EditorInitContext extends InitContext {
private readonly _eventEmitter: EventEmitter;

constructor(
context: ApplicationContext,
libraryManager: LibraryManager,
configRegistry: IConfigRegistry,
options: IRunOptions,
eventEmitter: EventEmitter,
) {
super(context, libraryManager, configRegistry, options);
this._eventEmitter = eventEmitter;
}

override get eventEmitter(): EventEmitter {
return this._eventEmitter;
}
}
30 changes: 30 additions & 0 deletions packages/core-editor/src/common/context/event-emitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { IRunOptions } from "@nanoforge-dev/common";

import type { IEventEmitter, ListenerType } from "./event-emitter.type";
import type { CoreEvents, CoreEventsMap } from "./events/core-events";
import type { EditorEvents, EditorEventsMap } from "./events/editor-events";

export class EventEmitter {
private coreEvents: IEventEmitter<CoreEvents, CoreEventsMap>;
private editorEvents: IEventEmitter<EditorEvents, EditorEventsMap>;

constructor(opts: IRunOptions["editor"]) {
this.coreEvents = opts.coreEvents;
this.editorEvents = opts.editorEvents;
}

runEvents(): void {
this.coreEvents.runEvents();
}

emit<K extends keyof EditorEventsMap>(event: K, ...args: EditorEventsMap[K]): void {
this.editorEvents.emitEvent(event, ...args);
}

on<K extends keyof CoreEventsMap>(
event: K,
listener: ListenerType<CoreEvents, CoreEventsMap, K>,
): void {
this.coreEvents.on(event, listener);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// ! Please do not remove this event unless a new one replaces it, it causes types issues

export enum EditorEvents {
EMPTY = "empty",
MOVE_COMPONENT = "move-component",
}

export interface EditorEventsMap {
[EditorEvents.EMPTY]: [];
[EditorEvents.MOVE_COMPONENT]: [
entityId: string,
componentId: string,
position: { x: number; y: number },
];
}
3 changes: 3 additions & 0 deletions packages/core-editor/src/common/context/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { CoreEvents } from "./events/core-events";
export { EditorEvents } from "./events/editor-events";
export type { EventEmitter } from "./event-emitter";
4 changes: 4 additions & 0 deletions packages/core-editor/src/common/context/options.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { type Save } from "./save.type";
/**
* Union of client and server editor run options accepted by
* `NanoforgeApplication.init` in editor mode.
*
* @deprecated Use `IRunOptions` instead.
*/
export type IEditorRunOptions = IEditorRunClientOptions | IEditorRunServerOptions;

/**
* Run options for a client-side editor application.
*
* @deprecated Use `IRunClientOptions` instead.
* @remarks
* Extends the base run options with editor-specific communication channels.
*/
Expand All @@ -36,6 +39,7 @@ export interface IEditorRunClientOptions {
/**
* Run options for a server-side editor application.
*
* @deprecated Use `IRunServerOptions` instead.
* @remarks
* Extends the base server run options with editor-specific communication channels.
*/
Expand Down
23 changes: 15 additions & 8 deletions packages/core-editor/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {
ClientLibraryManager,
Context,
type IRunnerLibrary,
InitContext,
type InitContext,
type LibraryHandle,
LibraryStatusEnum,
NfNotInitializedException,
} from "@nanoforge-dev/common";
import { type IRunOptions } from "@nanoforge-dev/common";
import { type ECSClientLibrary } from "@nanoforge-dev/ecs-client";

import { type ApplicationConfig } from "../../../core/src/application/application-config";
Expand All @@ -16,7 +17,7 @@ import { type EditableApplicationContext } from "../../../core/src/common/contex
import { EditableExecutionContext } from "../../../core/src/common/context/contexts/executions/execution.editable-context";
import { type EditableLibraryContext } from "../../../core/src/common/context/contexts/library.editable-context";
import { ConfigRegistry } from "../../../core/src/config/config-registry";
import { type IEditorRunOptions } from "../common/context/options.type";
import { EditorInitContext } from "../common/context/contexts/init.context";
import { CoreEditor } from "../editor/core-editor";

export class Core {
Expand All @@ -31,19 +32,19 @@ export class Core {
this.context = context;
}

public async init(options: IEditorRunOptions, appOptions: IApplicationOptions): Promise<void> {
public async init(options: IRunOptions, appOptions: IApplicationOptions): Promise<void> {
this.options = appOptions;
this._configRegistry = new ConfigRegistry(options.env);
await this.runInit(this.getInitContext(options));
this.editor = new CoreEditor(
this,
options.editor,
this.config.getComponentSystemLibrary<ECSClientLibrary>().library,
);
await this.runInit(this.getInitContext(options));
}

public async run(): Promise<void> {
if (!this.options) throw new NfNotInitializedException("Core");
if (!this.options) throw new NfNotInitializedException("Core Editor");

const context = this.getExecutionContext();
const clientContext = this.getClientContext();
Expand Down Expand Up @@ -77,10 +78,16 @@ export class Core {
return new EditableExecutionContext(this.context, this.config.libraryManager);
}

private getInitContext(options: IEditorRunOptions): InitContext {
if (!this._configRegistry) throw new NfNotInitializedException("Core");
private getInitContext(options: IRunOptions): InitContext {
if (!this._configRegistry || !this.editor) throw new NfNotInitializedException("Core Editor");

return new InitContext(this.context, this.config.libraryManager, this._configRegistry, options);
return new EditorInitContext(
this.context,
this.config.libraryManager,
this._configRegistry,
options,
this.editor.eventEmitter,
);
}

private getClearContext(): ClearContext {
Expand Down
36 changes: 19 additions & 17 deletions packages/core-editor/src/editor/core-editor.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { NfNotFound } from "@nanoforge-dev/common";
import { type ECSClientLibrary, type Entity } from "@nanoforge-dev/ecs-client";
import { type IRunOptions, NfNotFound } from "@nanoforge-dev/common";
import type { ECSClientLibrary, Entity } from "@nanoforge-dev/ecs-client";

import { EventEmitter } from "../common/context/event-emitter";
import { CoreEvents } from "../common/context/events/core-events";
import { type IEditorRunOptions } from "../common/context/options.type";
import { type Save } from "../common/context/save.type";
import { type Core } from "../core/core";
import type { Save } from "../common/context/save.type";
import type { Core } from "../core/core";

export class CoreEditor {
private editor: IEditorRunOptions["editor"];
public eventEmitter: EventEmitter;
private ecsLibrary: ECSClientLibrary;
private lastLoadedSave: Save;
private core: Core;
private _isPaused: boolean = false;

constructor(core: Core, editor: IEditorRunOptions["editor"], ecsLibrary: ECSClientLibrary) {
this.editor = editor;
this.lastLoadedSave = JSON.parse(JSON.stringify(this.editor.save));
constructor(core: Core, editor: IRunOptions["editor"], ecsLibrary: ECSClientLibrary) {
this.eventEmitter = new EventEmitter(editor);
this.lastLoadedSave = JSON.parse(JSON.stringify(editor.save));
this.ecsLibrary = ecsLibrary;
this.editor.coreEvents?.addListener(CoreEvents.HOT_RELOAD, this.hotReloadEvent.bind(this));
this.editor.coreEvents?.addListener(CoreEvents.HARD_RELOAD, this.hardReloadEvent.bind(this));
this.editor.coreEvents?.addListener(CoreEvents.PAUSE_GAME, this.pauseGameEvent.bind(this));
this.editor.coreEvents?.addListener(CoreEvents.STOP_GAME, this.stopGameEvent.bind(this));
this.editor.coreEvents?.addListener(CoreEvents.UNPAUSE_GAME, this.unpauseGameEvent.bind(this));
this.eventEmitter.on(CoreEvents.HOT_RELOAD, this.hotReloadEvent.bind(this));
this.eventEmitter.on(CoreEvents.HARD_RELOAD, this.hardReloadEvent.bind(this));
this.eventEmitter.on(CoreEvents.PAUSE_GAME, this.pauseGameEvent.bind(this));
this.eventEmitter.on(CoreEvents.STOP_GAME, this.stopGameEvent.bind(this));
this.eventEmitter.on(CoreEvents.UNPAUSE_GAME, this.unpauseGameEvent.bind(this));
this.core = core;
}

Expand All @@ -30,7 +30,7 @@ export class CoreEditor {
}

public runEvents() {
this.editor.coreEvents?.runEvents();
this.eventEmitter.runEvents();
}

public hotReloadEvent(save: Save): void {
Expand Down Expand Up @@ -93,8 +93,10 @@ export class CoreEditor {
const reg = this.ecsLibrary.registry;
return reg.entityFromIndex(
reg
.getComponents({ name: "__RESERVED_ENTITY_ID" })
.getIndex({ name: "__RESERVED_ENTITY_ID", entityId: entityId }),
.getComponents({ name: "__RESERVED_entityId" })
// @todo There is an issue here, getIndex return index from 1 but entityFromIndex get index from 0
// This is a temp fix
.getIndex({ name: "__RESERVED_entityId", entityId: entityId }) - 1,
);
}
}
Loading
Loading