From 1fde1d0583f3c0fe116201a2f83eb4e995f8c93a Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 18 Apr 2026 14:01:43 +0500 Subject: [PATCH] chore: optimization factories --- src/factories/blueprints-factory.ts | 8 ++++---- src/factories/effect-factory.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/factories/blueprints-factory.ts b/src/factories/blueprints-factory.ts index e062d19..8a3ef44 100644 --- a/src/factories/blueprints-factory.ts +++ b/src/factories/blueprints-factory.ts @@ -9,25 +9,25 @@ import { Entity, type GameObject } from "@world"; export class BluePrintsFactory implements IBluePrintsFactory { private readonly options: IBluePrintsFactoryOptions; - private readonly blueprints: IBluePrint[] = [] + private readonly blueprints = new Map(); public constructor(options: IBluePrintsFactoryOptions) { this.options = options } - public register(blueprint: BlueprintContent) { + public register(blueprint: BlueprintContent): IBluePrint { const createdBlueprint = { id: createId(), blueprint } - this.blueprints.push(createdBlueprint) + this.blueprints.set(createdBlueprint.id, createdBlueprint) return createdBlueprint } public get(id: number) { - return this.blueprints.find((bluprint) => bluprint.id === id) + return this.blueprints.get(id) } public create(blueprint: IBluePrint, position: Position): (Entity | GameObject) diff --git a/src/factories/effect-factory.ts b/src/factories/effect-factory.ts index b2f2564..32bbed3 100644 --- a/src/factories/effect-factory.ts +++ b/src/factories/effect-factory.ts @@ -3,9 +3,9 @@ import { createId } from "@utils"; export class EffectFactory implements IEffectFactory { /** - * Array of all effects + * Map of all effects */ - private readonly effects: IGameEffect[]= []; + private readonly effects = new Map(); public create(effect: IEffect): IGameEffect { const createdEffect: IGameEffect = { @@ -13,12 +13,12 @@ export class EffectFactory implements IEffectFactory { ...effect } - this.effects.push(createdEffect) + this.effects.set(createdEffect.id, createdEffect) return createdEffect } public get(id: number): IGameEffect | undefined { - return this.effects.find((effect) => effect.id === id) + return this.effects.get(id) } } \ No newline at end of file