Skip to content
Merged
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 packages/common/src/library/libraries/abstracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { BaseGraphicsLibrary } from "./graphics.library.abstract";
export { BaseInputLibrary } from "./input.library.abstract";
export { BaseSoundLibrary } from "./sound.library.abstract";
export { BaseNetworkLibrary } from "./network.library.abstract";
export { BaseMusicLibrary } from "./music.library.abstract";
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { type InitContext } from "../../../context";
import { type IMusicLibrary } from "../interfaces";
import { Library } from "../library";

export abstract class BaseMusicLibrary extends Library implements IMusicLibrary {
public abstract init(context: InitContext): Promise<void>;

public abstract play(sound: string): void;

/**
* mutes or unmutes the sound.
*/
public abstract mute(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const COMPONENT_SYSTEM_LIBRARY = Symbol("COMPONENT_SYSTEM_LIBRARY");
export const GRAPHICS_LIBRARY = Symbol("GRAPHICS_LIBRARY");
export const NETWORK_LIBRARY = Symbol("NETWORK_LIBRARY");
export const SOUND_LIBRARY = Symbol("SOUND_LIBRARY");
export const MUSIC_LIBRARY = Symbol("MUSIC_LIBRARY");
export const ASSET_MANAGER_LIBRARY = Symbol("ASSET_MANAGER_LIBRARY");
export const INPUT_LIBRARY = Symbol("INPUT_LIBRARY");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { type ILibrary } from "../../library.type";

export interface IMutableLibrary extends ILibrary {
/**
* mutes or unmutes the sound.
*/
mute(): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { type IExposedLibrary } from "../bases/exposed.library.type";
import { type IMutableLibrary } from "../bases/mutable.library.type";

export interface IMusicLibrary extends IExposedLibrary, IMutableLibrary {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { type IExposedLibrary } from "../bases/exposed.library.type";
import { type IMutableLibrary } from "../bases/mutable.library.type";

export interface ISoundLibrary extends IExposedLibrary {
/**
* mutes or unmutes the sound.
*/
mute(): void;
}
export interface ISoundLibrary extends IExposedLibrary, IMutableLibrary {}
2 changes: 2 additions & 0 deletions packages/common/src/library/libraries/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export { IGraphicsLibrary } from "./finals/graphics.library.type";
export { IInputLibrary } from "./finals/input.library.type";
export { ISoundLibrary } from "./finals/sound.library.type";
export { INetworkLibrary } from "./finals/network.library.type";
export { IMusicLibrary } from "./finals/music.library.type";
export { IMutableLibrary } from "./bases/mutable.library.type";
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
type IComponentSystemLibrary,
type IGraphicsLibrary,
type IInputLibrary,
type IMusicLibrary,
type INetworkLibrary,
type ISoundLibrary,
MUSIC_LIBRARY,
NETWORK_LIBRARY,
SOUND_LIBRARY,
} from "../../libraries";
Expand All @@ -21,6 +23,7 @@ export enum DefaultLibrariesEnum {
INPUT,
NETWORK,
SOUND,
MUSIC,
}

const DEFAULT_LIBRARIES: { index: DefaultLibrariesEnum; sym: symbol }[] = [
Expand All @@ -29,6 +32,7 @@ const DEFAULT_LIBRARIES: { index: DefaultLibrariesEnum; sym: symbol }[] = [
{ index: DefaultLibrariesEnum.GRAPHICS, sym: GRAPHICS_LIBRARY },
{ index: DefaultLibrariesEnum.NETWORK, sym: NETWORK_LIBRARY },
{ index: DefaultLibrariesEnum.SOUND, sym: SOUND_LIBRARY },
{ index: DefaultLibrariesEnum.MUSIC, sym: MUSIC_LIBRARY },
];

export class LibraryManager extends BaseLibraryManager {
Expand Down Expand Up @@ -67,4 +71,8 @@ export class LibraryManager extends BaseLibraryManager {
public getSound<T extends ISoundLibrary = ISoundLibrary>(): LibraryHandle<T> {
return this._get<T>(DefaultLibrariesEnum.SOUND);
}

public getMusic<T extends IMusicLibrary = IMusicLibrary>(): LibraryHandle<T> {
return this._get<T>(DefaultLibrariesEnum.MUSIC);
}
}
13 changes: 13 additions & 0 deletions packages/core/src/application/application-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type IGraphicsLibrary,
type IInputLibrary,
type ILibrary,
type IMusicLibrary,
type INetworkLibrary,
type ISoundLibrary,
type LibraryHandle,
Expand Down Expand Up @@ -77,4 +78,16 @@ export class ApplicationConfig {
public useSoundLibrary(library: ISoundLibrary) {
this._libraryManager.setSound(library);
}

public getMusicLibrary() {
return this._libraryManager.getMusic();
}

public useMusicLibrary(library: IMusicLibrary) {
this._libraryManager.setMusic(library);
}

public getMutableLibraries() {
return this._libraryManager.getMutableLibraries();
}
}
13 changes: 13 additions & 0 deletions packages/core/src/common/library/manager/library.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import {
type IGraphicsLibrary,
type IInputLibrary,
type ILibrary,
type IMusicLibrary,
type IMutableLibrary,
INPUT_LIBRARY,
type INetworkLibrary,
type IRunnerLibrary,
type ISoundLibrary,
type LibraryHandle,
LibraryManager,
MUSIC_LIBRARY,
NETWORK_LIBRARY,
SOUND_LIBRARY,
} from "@nanoforge/common";
Expand Down Expand Up @@ -65,6 +68,10 @@ export class EditableLibraryManager extends LibraryManager {
this._set(DefaultLibrariesEnum.SOUND, SOUND_LIBRARY, library, new EditableLibraryContext());
}

public setMusic(library: IMusicLibrary): void {
this._set(DefaultLibrariesEnum.MUSIC, MUSIC_LIBRARY, library, new EditableLibraryContext());
}

public getLibraries(): LibraryHandle[] {
return this._libraries;
}
Expand All @@ -81,6 +88,12 @@ export class EditableLibraryManager extends LibraryManager {
return Relationship.getLibrariesByDependencies(this._libraries, true);
}

public getMutableLibraries(): LibraryHandle<IMutableLibrary>[] {
return this._libraries.filter(
(handle) => handle && typeof handle.library["mute"] === "function",
) as LibraryHandle<IMutableLibrary>[];
}

private _getRunnerLibraries(): LibraryHandle<IRunnerLibrary>[] {
return this._libraries.filter(
(handle) => handle && typeof handle.library["run"] === "function",
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export class Core {
const intervalHandle = setInterval(render, 1000 / this.options.tickRate);
}

/**
* mutes / unmutes mutable libraries all at once.
*/
public mute(): void {
this.config.getMutableLibraries().map((x) => x.library.mute());
}

private getInitContext(options: IRunOptions): InitContext {
return new InitContext(this.context, this.config.libraryManager, this._configRegistry, options);
}
Expand Down
Loading
Loading