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
8 changes: 4 additions & 4 deletions src/factories/blueprints-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, IBluePrint>();

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)
Expand Down
8 changes: 4 additions & 4 deletions src/factories/effect-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ 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<number, IGameEffect>();

public create(effect: IEffect): IGameEffect {
const createdEffect: IGameEffect = {
id: createId(),
...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)
}
}
Loading