MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / loadIcons

Function loadIcons

packages/blockly/core/serialization/blocks.ts:626–645  ·  view source on GitHub ↗

* Applies icon state to the icons on the block, based on the given state * object. * * @param block The block to set the icon state of. * @param state The state object to reference.

(block: Block, state: State)

Source from the content-addressed store, hash-verified

624 * @param state The state object to reference.
625 */
626function loadIcons(block: Block, state: State) {
627 if (!state['icons']) return;
628
629 const iconTypes = Object.keys(state['icons']);
630 for (const iconType of iconTypes) {
631 const iconState = state['icons'][iconType];
632 let icon = block.getIcon(iconType);
633 if (!icon) {
634 const constructor = registry.getClass(
635 registry.Type.ICON,
636 iconType,
637 false,
638 );
639 if (!constructor) throw new UnregisteredIcon(iconType, block, state);
640 icon = new constructor(block);
641 block.addIcon(icon);
642 }
643 if (isSerializable(icon)) icon.loadState(iconState);
644 }
645}
646
647/**
648 * Applies any field information available on the state object to the block.

Callers 1

appendPrivateFunction · 0.85

Calls 4

getIconMethod · 0.80
loadStateMethod · 0.65
isSerializableFunction · 0.50
addIconMethod · 0.45

Tested by

no test coverage detected