Blueprint Composition
Blueprint Fragments
Section titled “Blueprint Fragments”Encapsulate reusable logic as fragments:
import { createFragment } from '@esengine/blueprint';
const healthFragment = createFragment('HealthSystem', { inputs: [ { name: 'damage', type: 'number', internalNodeId: 'input1', internalPinName: 'value' } ], outputs: [ { name: 'isDead', type: 'boolean', internalNodeId: 'output1', internalPinName: 'value' } ], graph: { nodes: [...], connections: [...], variables: [...] }});Composing Blueprints
Section titled “Composing Blueprints”import { createComposer, FragmentRegistry } from '@esengine/blueprint';
// Register fragmentsFragmentRegistry.instance.register('health', healthFragment);FragmentRegistry.instance.register('movement', movementFragment);
// Create composerconst composer = createComposer('PlayerBlueprint');
// Add fragments to slotscomposer.addFragment(healthFragment, 'slot1', { position: { x: 0, y: 0 } });composer.addFragment(movementFragment, 'slot2', { position: { x: 400, y: 0 } });
// Connect slotscomposer.connect('slot1', 'onDeath', 'slot2', 'disable');
// Validateconst validation = composer.validate();if (!validation.isValid) { console.error(validation.errors);}
// Compile to blueprintconst blueprint = composer.compile();Fragment Registry
Section titled “Fragment Registry”import { FragmentRegistry } from '@esengine/blueprint';
const registry = FragmentRegistry.instance;
// Register fragmentregistry.register('health', healthFragment);
// Get fragmentconst fragment = registry.get('health');
// Get all fragmentsconst allFragments = registry.getAll();
// Get by categoryconst combatFragments = registry.getByCategory('combat');Trigger System
Section titled “Trigger System”Defining Trigger Conditions
Section titled “Defining Trigger Conditions”import { TriggerCondition, TriggerDispatcher } from '@esengine/blueprint';
const lowHealthCondition: TriggerCondition = { type: 'comparison', left: { type: 'variable', name: 'health' }, operator: '<', right: { type: 'constant', value: 20 }};Using Trigger Dispatcher
Section titled “Using Trigger Dispatcher”const dispatcher = new TriggerDispatcher();
// Register triggerdispatcher.register('lowHealth', lowHealthCondition, (context) => { context.triggerEvent('OnLowHealth');});
// Evaluate each framedispatcher.evaluate(context);Compound Conditions
Section titled “Compound Conditions”const complexCondition: TriggerCondition = { type: 'and', conditions: [ { type: 'comparison', left: { type: 'variable', name: 'health' }, operator: '<', right: { type: 'constant', value: 50 } }, { type: 'comparison', left: { type: 'variable', name: 'inCombat' }, operator: '==', right: { type: 'constant', value: true } } ]};Fragment Best Practices
Section titled “Fragment Best Practices”- Single Responsibility - Each fragment does one thing
- Clear Interface - Name input/output pins clearly
- Documentation - Add descriptions and usage examples
- Version Control - Maintain backward compatibility when updating