| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import {
- FactorioEngineOrchestrator,
- MachineSimulator,
- InserterSimulator,
- FilterableInserterSimulator,
- Chest,
- Belt,
- } from "./simulator";
- import type { Recipe } from "../../scripts/factorio-dump/helpers/recipes.helper";
- import type { Machine } from "../../scripts/factorio-dump/process-data.models";
- import type { MachineSetup } from "./model";
- import data from "../assets/data/2.0/data.json"
- // --- Shared Fixtures ---
- export const StandardSetups = {
- assembler1: { machine: { crafting_speed: 1 } as Machine, machineModules: [], beacons: [], machineQualityLevel: 0 },
- assembler2: { machine: { name: "assembling-machine-2", crafting_speed: 10 } as Machine, machineModules: [], beacons: [], machineQualityLevel: 0 },
- empSpeed: { machine: { name: "electromagnetic-plant", crafting_speed: 6 } as Machine, machineModules: [], beacons: [], machineQualityLevel: 5 },
- fastAssembler: { machine: { crafting_speed: 60 } as Machine, machineModules: [], beacons: [], machineQualityLevel: 0 },
- instantAssembler: { machine: { crafting_speed: 30 } as Machine, machineModules: [], beacons: [], machineQualityLevel: 0 }
- };
- // --- The Builder ---
- export class SimulationBuilder {
- public orchestrator = new FactorioEngineOrchestrator();
-
- public machines: Record<string, MachineSimulator> = {};
- public chests: Record<string, Chest> = {};
- public belts: Record<string, Belt> = {};
- public inserters: Record<string, InserterSimulator | FilterableInserterSimulator> = {};
- addMachine(id: string, recipe: Recipe, setup: MachineSetup = StandardSetups.assembler1 ) {
- const machine = new MachineSimulator(setup, recipe, data.stackSizes);
- this.machines[id] = machine;
- this.orchestrator.registerMachine(machine);
- return this;
- }
- addChest(id: string, initialItem?: string) {
- this.chests[id] = initialItem ? new Chest(initialItem) : new Chest();
- return this;
- }
- addBelt(id: string, ...items: string[]) {
- this.belts[id] = new Belt(...items);
- return this;
- }
- addInserter(
- id: string,
- handSize: number,
- sourceId: string,
- targetId: string,
- filters?: string | string[],
- isDynamicFilter: boolean = false
- ) {
- const source = this.getEntity(sourceId);
- const target = this.getEntity(targetId);
- let inserter;
- if (Array.isArray(filters) || isDynamicFilter) {
- inserter = new FilterableInserterSimulator(handSize, source, target, Array.isArray(filters) ? filters : undefined);
- if (isDynamicFilter) inserter.useDynamicFilters = true;
- } else {
- inserter = new InserterSimulator(handSize, source, target, filters as string);
- }
- this.inserters[id] = inserter;
- this.orchestrator.registerInserter(inserter);
- return this;
- }
- bindToClock(inserterId: string, rowId: string) {
- const inserter = this.inserters[inserterId];
- if (!inserter) throw new Error(`Inserter ${inserterId} not found`);
- this.orchestrator.bindInserterToRow(inserter, rowId);
- return this;
- }
- private getEntity(id: string) {
- const entity = this.chests[id] || this.machines[id] || this.belts[id];
- if (!entity) throw new Error(`Entity '${id}' not found in builder registry. Declare it before using it in an inserter.`);
- return entity;
- }
- build() {
- return {
- orchestrator: this.orchestrator,
- machines: this.machines,
- chests: this.chests,
- belts: this.belts,
- inserters: this.inserters,
- };
- }
- }
|