@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
93 lines (90 loc) • 3.09 kB
JavaScript
import { k as FlowGraphExecutionBlock, i as isNumeric, g as getNumericValue } from './KHR_interactivity-Bmb38TjL.esm.js';
import { R as RichTypeAny } from './declarationMapper-rcGCdcDP.esm.js';
import { R as RegisterClass } from './index-FzOfPXLV.esm.js';
import './objectModelMapping-CJnQ6at_.esm.js';
/**
* A block that executes a branch based on a selection.
*/
class FlowGraphSwitchBlock extends FlowGraphExecutionBlock {
constructor(
/**
* the configuration of the block
*/
config) {
super(config);
this.config = config;
/**
* The default case to execute if no other case is found.
*/
this.default = this._registerSignalOutput("default");
this._caseToOutputFlow = new Map();
this.case = this.registerDataInput("case", RichTypeAny);
// iterate the set not using for of
const array = this.config.cases || [];
for (const caseValue of array) {
this._caseToOutputFlow.set(caseValue, this._registerSignalOutput(`out_${caseValue}`));
}
}
_execute(context, _callingSignal) {
const selectionValue = this.case.getValue(context);
let outputFlow;
if (isNumeric(selectionValue)) {
outputFlow = this._getOutputFlowForCase(getNumericValue(selectionValue));
}
else {
outputFlow = this._getOutputFlowForCase(selectionValue);
}
if (outputFlow) {
outputFlow._activateSignal(context);
}
else {
this.default._activateSignal(context);
}
}
/**
* Adds a new case to the switch block.
* @param newCase the new case to add.
*/
addCase(newCase) {
if (this.config.cases.includes(newCase)) {
return;
}
this.config.cases.push(newCase);
this._caseToOutputFlow.set(newCase, this._registerSignalOutput(`out_${newCase}`));
}
/**
* Removes a case from the switch block.
* @param caseToRemove the case to remove.
*/
removeCase(caseToRemove) {
if (!this.config.cases.includes(caseToRemove)) {
return;
}
const index = this.config.cases.indexOf(caseToRemove);
this.config.cases.splice(index, 1);
this._caseToOutputFlow.delete(caseToRemove);
}
/**
* @internal
*/
_getOutputFlowForCase(caseValue) {
return this._caseToOutputFlow.get(caseValue);
}
/**
* @returns class name of the block.
*/
getClassName() {
return "FlowGraphSwitchBlock" /* FlowGraphBlockNames.Switch */;
}
/**
* Serialize the block to a JSON representation.
* @param serializationObject the object to serialize to.
*/
serialize(serializationObject) {
super.serialize(serializationObject);
serializationObject.cases = this.config.cases;
}
}
RegisterClass("FlowGraphSwitchBlock" /* FlowGraphBlockNames.Switch */, FlowGraphSwitchBlock);
export { FlowGraphSwitchBlock };
//# sourceMappingURL=flowGraphSwitchBlock-LOsA8ZFz.esm.js.map