A DI factory for the game service
Pass the game settings and progress service to the constructor.
When a scene opens, the SDK requests the services listed in registerServices. For Gameplay, the container calls the factory (provider.useFactory(this)). The factory passes the board, piece, and scoring settings and the progress service to the constructor. scene.di.ts
registrar.singletonFactory(BlockPuzzleServices.Gameplay, (container) => {
const configs = container.get<ConfigStore>(SystemServices.ConfigStore);
return new BlockPuzzleGameplayService(
configs.get(
BlockPuzzleConfigEntries.Board.fileId,
BlockPuzzleConfigEntries.Board.decoder,
),
configs.get(
BlockPuzzleConfigEntries.Shapes.fileId,
BlockPuzzleConfigEntries.Shapes.decoder,
),
configs.get(
BlockPuzzleConfigEntries.Scoring.fileId,
BlockPuzzleConfigEntries.Scoring.decoder,
),
container.get<BlockPuzzlePlayerProgressService>(
CommonServices.Progress,
),
);
});
RequestThe container receives the Gameplay token
Call the factoryThe factory passes dependencies to new BlockPuzzleGameplayService
InstanceThe container keeps the service for later requests