diff --git a/core/src/main/java/com/vzome/core/editor/SymmetrySystem.java b/core/src/main/java/com/vzome/core/editor/SymmetrySystem.java index 9ccb6abf6..3867e4d6d 100644 --- a/core/src/main/java/com/vzome/core/editor/SymmetrySystem.java +++ b/core/src/main/java/com/vzome/core/editor/SymmetrySystem.java @@ -245,9 +245,10 @@ public Direction createAnonymousOrbit( AlgebraicVector vector ) return orbit; } - public Color getVectorColor( AlgebraicVector vector ) { - if( vector.isOrigin() ) { - return Color.WHITE; + public Color getVectorColor( AlgebraicVector vector ) + { + if( vector == null || vector.isOrigin() ) { + return colors .getColor( Colors.CONNECTOR ); } // try to get from cache Axis line = this .vectorToAxis .get( vector.toString() ); @@ -266,7 +267,7 @@ public Color getVectorColor( AlgebraicVector vector ) { public Color getColor( Direction orbit ) { if ( orbit == null ) - return Color.WHITE; + return colors .getColor( Colors.CONNECTOR ); Color shapeColor = this .shapes .getColor( orbit ); // usually null, but see ExportedVEFShapes if ( shapeColor == null ) // the usual case shapeColor = orbitColors .get( orbit .getName() ); @@ -429,4 +430,12 @@ public AlgebraicNumber getOrbitUnitLength( Direction orbit ) { return this .symmetryPerspective .getOrbitUnitLength( orbit ); } + + public void resetColors() + { + for ( Direction orbit : symmetry .getOrbitSet() .getDirections() ) { + Color color = colors .getColor( Colors.DIRECTION + orbit .getName() ); + orbitColors .put( orbit.getName(), color ); + } + } } diff --git a/core/src/main/java/com/vzome/core/edits/ManifestationColorMappers.java b/core/src/main/java/com/vzome/core/edits/ManifestationColorMappers.java index efdea5930..b8094fafe 100644 --- a/core/src/main/java/com/vzome/core/edits/ManifestationColorMappers.java +++ b/core/src/main/java/com/vzome/core/edits/ManifestationColorMappers.java @@ -132,6 +132,8 @@ public Color apply( Manifestation man ) { protected Color applyTo( Manifestation manifestation ) { + // SV 2024-09-02 - I think this can never be called, since all current subclasses override it + Color color = manifestation.getColor(); if( color == null ) { // TODO fix this! Should use techniques like SystemColorMap. color = Color.WHITE; // provide default ball color so it can be manipulated @@ -697,7 +699,7 @@ protected SystemColorMap(OrbitSource symmetry) { @Override protected Color applyToBall(Connector ball, int alpha) { - return Color.WHITE; + return symmetrySystem.getVectorColor( null ); } @Override @@ -797,7 +799,7 @@ protected Color applyToPanel(Panel panel, int alpha) { @Override protected Color applyToVector(AlgebraicVector vector) { if(vector.isOrigin()) { - return Color.WHITE; + return symmetrySystem.getVectorColor( null ); // default ball color } Axis nearestSpecialOrbit = symmetrySystem.getSymmetry().getAxis(vector.toRealVector(), specialOrbits); AlgebraicVector normal = nearestSpecialOrbit.normal(); diff --git a/core/src/main/java/com/vzome/core/model/ConnectorImpl.java b/core/src/main/java/com/vzome/core/model/ConnectorImpl.java index 7eba04e16..411d1e77a 100644 --- a/core/src/main/java/com/vzome/core/model/ConnectorImpl.java +++ b/core/src/main/java/com/vzome/core/model/ConnectorImpl.java @@ -15,7 +15,6 @@ public class ConnectorImpl extends ManifestationImpl implements Connector public ConnectorImpl( AlgebraicVector loc ) { super(); - this.setColor(Color.WHITE); m_center = loc; } diff --git a/desktop/src/main/java/com/vzome/desktop/awt/OrbitSetGraphicsController.java b/desktop/src/main/java/com/vzome/desktop/awt/OrbitSetGraphicsController.java index 620b557c5..c63f54a72 100644 --- a/desktop/src/main/java/com/vzome/desktop/awt/OrbitSetGraphicsController.java +++ b/desktop/src/main/java/com/vzome/desktop/awt/OrbitSetGraphicsController.java @@ -200,6 +200,7 @@ public boolean[] enableContextualCommands( String[] menu, MouseEvent e ) case "setAllDirections": case "usedOrbits": case "configureDirections": + case "resetOrbitColors": result[i] = true; break; diff --git a/desktop/src/main/java/com/vzome/desktop/controller/SymmetryController.java b/desktop/src/main/java/com/vzome/desktop/controller/SymmetryController.java index ce44cb5b2..4a75cf3b0 100644 --- a/desktop/src/main/java/com/vzome/desktop/controller/SymmetryController.java +++ b/desktop/src/main/java/com/vzome/desktop/controller/SymmetryController.java @@ -269,6 +269,11 @@ public void doAction( String action ) throws Exception action += "/" + this .symmetrySystem .getName() + ":" + this .symmetrySystem .getStyle() .getName(); super .doAction( action ); break; + + case "resetOrbitColors": + this .symmetrySystem .resetColors(); + availableController .firePropertyChange( "orbits", true, false ); + break; default: if ( action .startsWith( "setStyle." ) ) diff --git a/desktop/src/main/java/org/vorthmann/zome/ui/DocumentFrame.java b/desktop/src/main/java/org/vorthmann/zome/ui/DocumentFrame.java index 5c70109fb..8daa698d3 100644 --- a/desktop/src/main/java/org/vorthmann/zome/ui/DocumentFrame.java +++ b/desktop/src/main/java/org/vorthmann/zome/ui/DocumentFrame.java @@ -410,6 +410,11 @@ public void actionPerformed( ActionEvent e ) symmetryDialog .setVisible( true ); break; + case "resetOrbitColors": + delegate = mController .getSubController( "symmetry." + system ); + delegate .actionPerformed( e .getSource(), e .getActionCommand() ); + break; + case "addBookmark": String numStr = toolsController .getProperty( "next.tool.number" ); int bookmarkNum = Integer .parseInt( numStr ); @@ -977,6 +982,7 @@ private ActionListener getActionListener( String command, Controller controller case "configureDirections": case "addBookmark": case "export4dPolytope": + case "resetOrbitColors": actionListener = this .localActions; break; diff --git a/desktop/src/main/java/org/vorthmann/zome/ui/OrbitPanel.java b/desktop/src/main/java/org/vorthmann/zome/ui/OrbitPanel.java index 762c39761..0da38c12e 100644 --- a/desktop/src/main/java/org/vorthmann/zome/ui/OrbitPanel.java +++ b/desktop/src/main/java/org/vorthmann/zome/ui/OrbitPanel.java @@ -114,6 +114,7 @@ public void actionPerformed( ActionEvent evt ) directionPopupMenu.add( enabler .setMenuAction( "usedOrbits", drawnOrbits, new JMenuItem( "used in model" ) ) ); directionPopupMenu.add( enabler .setMenuAction( "setAllDirections", drawnOrbits, new JMenuItem( "all" ) ) ); directionPopupMenu.add( enabler .setMenuAction( "configureDirections", drawnOrbits, new JMenuItem( "configure..." ) ) ); + directionPopupMenu.add( enabler .setMenuAction( "resetOrbitColors", drawnOrbits, new JMenuItem( "reset colors" ) ) ); } else directionPopupMenu = null; diff --git a/online/src/app/classic/components/strutbuilder.jsx b/online/src/app/classic/components/strutbuilder.jsx index c0f2b947a..fc3d67f79 100644 --- a/online/src/app/classic/components/strutbuilder.jsx +++ b/online/src/app/classic/components/strutbuilder.jsx @@ -36,6 +36,10 @@ export const StrutBuildPanel = () => setAnchorEl( null ); showOrbitsDialog(); } + const resetOrbitColors = () => { + setAnchorEl( null ); + controllerAction( symmetryController(), 'resetOrbitColors' ); + } return(
@@ -57,6 +61,7 @@ export const StrutBuildPanel = () => predefined all configure... + reset orbit colors diff --git a/online/src/wc/zometool/bom.js b/online/src/wc/zometool/bom.js index 6f9dc3f91..dc2bc3f0f 100644 --- a/online/src/wc/zometool/bom.js +++ b/online/src/wc/zometool/bom.js @@ -25,36 +25,56 @@ const svgMapping = { } const partcodeMapping = { - ball: 'PZB-BAL-W', - b0: 'PST-B0-BLU', - b1: 'PST-B1-BLU', - b2: 'PST-B2-BLU', - y0: 'PST-Y0-YEL', - y1: 'PST-Y1-YEL', - y2: 'PST-Y2-YEL', - r00: 'PST-R00-RED', - r0: 'PST-R0-RED', - r1: 'PST-R1-RED', - r2: 'PST-R2-RED', - g0: 'PST-G0-GRN', - g1: 'PST-G1-GRN', - g2: 'PST-G2-GRN', - hg0: 'PST-HG0-GRN', - hg1: 'PST-HG1-GRN', - hg2: 'PST-HG2-GRN', + ball: 'PZB-BAL-', + b0: 'PST-B0-', + b1: 'PST-B1-', + b2: 'PST-B2-', + y0: 'PST-Y0-', + y1: 'PST-Y1-', + y2: 'PST-Y2-', + r00: 'PST-R00-', + r0: 'PST-R0-', + r1: 'PST-R1-', + r2: 'PST-R2-', + g0: 'PST-G0-', + g1: 'PST-G1-', + g2: 'PST-G2-', + hg0: 'PST-HG0-', + hg1: 'PST-HG1-', + hg2: 'PST-HG2-', +} + +const colorMapping = { + "blue": "BLU", + "yellow": "YEL", + "red": "RED", + "green": "GRN", + "turquoise": "TEA", + "orange": "ORG", + "purple": "PUR", + "white": "W", + "black": "BLK", + "gray": "GRY", } -export const normalizeBOM = rawBoM => +export const normalizeBOM = ( rawBoM, { colors, parts } ) => { const bom = []; + const zometoolCodes = Object.keys( parts ); // not using the values at the moment // the order in partcodeMapping will be the order in bom for (const key in partcodeMapping) { const rawKey = svgMapping[ key ]; if ( Object.hasOwnProperty.call( rawBoM, rawKey ) ) { - const partNum = partcodeMapping[ key ]; - const count = rawBoM[ rawKey ]; - bom .push( { key, partNum, count } ) + // There is a rawBoM entry for this rawKey (e.g. svgMapping["b0"]), itself a histogram by color + const partNumPrefix = partcodeMapping[ key ]; + for (const [ colorName, count ] of Object.entries( rawBoM[ rawKey ]) ) { + const partNum = partNumPrefix + colorMapping[ colorName ]; + if ( zometoolCodes .includes( partNum ) ) { + const color = colors[ colorName ]; + bom .push( { key, partNum, count, color } ) + } + } } } return bom; diff --git a/online/src/wc/zometool/index.jsx b/online/src/wc/zometool/index.jsx index 888776f91..602ebc957 100644 --- a/online/src/wc/zometool/index.jsx +++ b/online/src/wc/zometool/index.jsx @@ -18,6 +18,9 @@ import { normalizeBOM } from './bom.js'; const debug = false; +const parts_catalog_url = 'https://zometool.github.io/vzome-sharing/metadata/zometool-parts.json'; +const partsPromise = fetch( parts_catalog_url ) .then( response => response.text() ) .then( text => JSON.parse( text ) ); + const StepControls = props => { const { scenes, requestScene } = useViewer(); @@ -51,7 +54,10 @@ const StepControls = props => const { subscribeFor } = useWorkerClient(); subscribeFor( 'BOM_CHANGED', bom => { - props.dispatch( new CustomEvent( 'zometool-instructions-loaded', { detail: normalizeBOM( bom ) } ) ); + partsPromise .then( parts => { + const detail = normalizeBOM( bom, parts ); + props.dispatch( new CustomEvent( 'zometool-instructions-loaded', { detail } ) ); + }); } ); return ( diff --git a/online/src/wc/zometool/parts-list.jsx b/online/src/wc/zometool/parts-list.jsx index ea21daa23..ff2b6da7d 100644 --- a/online/src/wc/zometool/parts-list.jsx +++ b/online/src/wc/zometool/parts-list.jsx @@ -49,10 +49,12 @@ const svgStrings = { hg2 : hg2Svg, } -const getSvgNode = key => +const getSvgNode = ( key, color ) => { - let doc = new DOMParser().parseFromString( svgStrings[ key ], 'application/xml' ); - return document .importNode( doc.documentElement, true ); + let doc = new DOMParser() .parseFromString( svgStrings[ key ], 'application/xml' ); + const svg = document .importNode( doc.documentElement, true ); + svg .setAttribute( 'fill', color ); + return svg; } const debug = false; @@ -72,10 +74,10 @@ const ZometoolParts = props => - { ({ key, count }) => + { ({ key, count, color }) => - {getSvgNode( key )} + {getSvgNode( key, color )} { ((key==='ball')? '' : key) .toUpperCase() } {count} diff --git a/online/src/wc/zometool/parts/b0.svg b/online/src/wc/zometool/parts/b0.svg index 73e653d89..08bd39ac5 100644 --- a/online/src/wc/zometool/parts/b0.svg +++ b/online/src/wc/zometool/parts/b0.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d8ccd50bfe505a80477cf9f6a0d91fe8226effd13a2b11d38b1a86c22f5564db -size 1992 +oid sha256:413d914d96c55a5c474c15d6c326bcf8373afb343d57143abb10300c905e0051 +size 1842 diff --git a/online/src/wc/zometool/parts/b1.svg b/online/src/wc/zometool/parts/b1.svg index de2ab195f..cc3316bd0 100644 --- a/online/src/wc/zometool/parts/b1.svg +++ b/online/src/wc/zometool/parts/b1.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:840e5f1d70f19020c6d8533a439b1cf4decfaacd846fca09e17d425972b19f83 -size 1994 +oid sha256:d5e49965220a9003dbdbccda8fc510d653951be540eb838b68016a8064535350 +size 1844 diff --git a/online/src/wc/zometool/parts/b2.svg b/online/src/wc/zometool/parts/b2.svg index 118a9ddaa..558d4549b 100644 --- a/online/src/wc/zometool/parts/b2.svg +++ b/online/src/wc/zometool/parts/b2.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:97d35ef160c5b021477bc1e43f1aa9cad4ceecfe32e4b298c83fbe6722aae6a2 -size 1990 +oid sha256:ef19e4e778898118ae301bd7ce61c12679316d8a587393251d3bf04c17f5a3a7 +size 1840 diff --git a/online/src/wc/zometool/parts/ball.svg b/online/src/wc/zometool/parts/ball.svg index 40449a0fd..f2e42cf17 100644 --- a/online/src/wc/zometool/parts/ball.svg +++ b/online/src/wc/zometool/parts/ball.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:78871bd7f5835d276f8bfa6e17e5a5564c14ef3fb1b65355ed6b96609397c817 -size 5144 +oid sha256:1d96d56da9e830b20ee5872ab8109eb266161813732ab83c7500a409b7d93f58 +size 4724 diff --git a/online/src/wc/zometool/parts/g0.svg b/online/src/wc/zometool/parts/g0.svg index d4e40f2a0..bb1050c34 100644 --- a/online/src/wc/zometool/parts/g0.svg +++ b/online/src/wc/zometool/parts/g0.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:99379076aa52f255ea9d43a072a5b84923f21b9e40f7069c3b3a7193d3bbe124 -size 3362 +oid sha256:541cbea638b05babadfb95eb9039c00f38677a162fd36b4d60250189537d3a7a +size 3092 diff --git a/online/src/wc/zometool/parts/g1.svg b/online/src/wc/zometool/parts/g1.svg index e2160509a..58e894cf6 100644 --- a/online/src/wc/zometool/parts/g1.svg +++ b/online/src/wc/zometool/parts/g1.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:258c8807cd5c0c15a558122b533b9676650f7d81dbff516b52932ac039ef2be7 -size 3443 +oid sha256:0da62ded1bcaabf2384c752645d2118a5af06d6ee4422ccd8d1582c3b87f2cea +size 3173 diff --git a/online/src/wc/zometool/parts/g2.svg b/online/src/wc/zometool/parts/g2.svg index 88c9514ac..e6a51594e 100644 --- a/online/src/wc/zometool/parts/g2.svg +++ b/online/src/wc/zometool/parts/g2.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bbc4a4b08f7e7d3ae28f67068aa65ccf12748dde2249eab60617ad79e907e297 -size 3454 +oid sha256:0e5f1dc8a83047fff4fa1c3a55d50deb4f7a8a4722001e5e23adc78d299fab33 +size 3184 diff --git a/online/src/wc/zometool/parts/hg0.svg b/online/src/wc/zometool/parts/hg0.svg index 4421d7ef4..2c7d51591 100644 --- a/online/src/wc/zometool/parts/hg0.svg +++ b/online/src/wc/zometool/parts/hg0.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:27b91ede29127bef74be8b2d3d5aeb43960711e2c902565c7f9c9bde43a98ef6 -size 3704 +oid sha256:2aad7bd05400996526ae315f28ecbd3cbd36fff36a2ac2b59898875056e6b59b +size 3404 diff --git a/online/src/wc/zometool/parts/hg1.svg b/online/src/wc/zometool/parts/hg1.svg index c74f7c280..388a61794 100644 --- a/online/src/wc/zometool/parts/hg1.svg +++ b/online/src/wc/zometool/parts/hg1.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7403ac00b50d92a6b6a10cfe4e48afb006fc8b677fc90599114c3c98758615f1 -size 3382 +oid sha256:babedd7ecf1ad35ec4a090ea8a6fe04648eb379f4a0547f89b9f0c25709dd24c +size 3111 diff --git a/online/src/wc/zometool/parts/hg2.svg b/online/src/wc/zometool/parts/hg2.svg index 8d731fa4a..7df20eedd 100644 --- a/online/src/wc/zometool/parts/hg2.svg +++ b/online/src/wc/zometool/parts/hg2.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d677c7c7f86ca7aa30b9e228213361f5c5a8c884b0a717435ee809da94b44725 -size 3453 +oid sha256:f346762b396588eeee2a2116cdfa528a1ba87d44447469973f10d3da447ac699 +size 3183 diff --git a/online/src/wc/zometool/parts/r0.svg b/online/src/wc/zometool/parts/r0.svg index b2e622f54..52ffb877b 100644 --- a/online/src/wc/zometool/parts/r0.svg +++ b/online/src/wc/zometool/parts/r0.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:00588bfc4c4f0a78dc25db53a4c3b08e604205aa513ea2ca0f9799854aa51cbe -size 3603 +oid sha256:490bd764c9badbbe3e057ca786be40af37f1ea7121be91d98c009efbd0622840 +size 3303 diff --git a/online/src/wc/zometool/parts/r00.svg b/online/src/wc/zometool/parts/r00.svg index 83f096b7e..5c0df59e6 100644 --- a/online/src/wc/zometool/parts/r00.svg +++ b/online/src/wc/zometool/parts/r00.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4afa15f3da99b3b7d57ce06cf4aa557b1ac1581a8b954bf59ab2592231e240a3 -size 3461 +oid sha256:7f2f77cc09b8208900e2c7b117790c6f1ffd0ac382d58fd631d8ca4d10d7cf48 +size 3136 diff --git a/online/src/wc/zometool/parts/r1.svg b/online/src/wc/zometool/parts/r1.svg index 64c38f173..e5ea3d057 100644 --- a/online/src/wc/zometool/parts/r1.svg +++ b/online/src/wc/zometool/parts/r1.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a521060f9ca271e2e134d6966678235aab4ca332c81aa8063979c92070234e5a -size 3602 +oid sha256:86b29a4db9947228a23c454e87185bec097624a9cfd5046f99ebdbb468ead0f9 +size 3302 diff --git a/online/src/wc/zometool/parts/r2.svg b/online/src/wc/zometool/parts/r2.svg index 35a6feb93..d97556660 100644 --- a/online/src/wc/zometool/parts/r2.svg +++ b/online/src/wc/zometool/parts/r2.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:15ace0046534e01ad19f251fbe7a427a664210c099e538fde84a2a4b40451b37 -size 3604 +oid sha256:cfcd41a9ddab8b8b26ec85faf592b30e6d493552979622477b96a1db59b814f4 +size 3304 diff --git a/online/src/wc/zometool/parts/y0.svg b/online/src/wc/zometool/parts/y0.svg index d3b6acb56..a2361d2f7 100644 --- a/online/src/wc/zometool/parts/y0.svg +++ b/online/src/wc/zometool/parts/y0.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3a8a4e6535e760f981b9a5b763ad9752a83669b2c6e51f14aa5cad823bc4dbed -size 2171 +oid sha256:400fe2ba35e75129374a0350ba62a21ff2c90a82235301318cd0d6a5efc8e8f8 +size 1990 diff --git a/online/src/wc/zometool/parts/y1.svg b/online/src/wc/zometool/parts/y1.svg index 22fafa49a..874e1394e 100644 --- a/online/src/wc/zometool/parts/y1.svg +++ b/online/src/wc/zometool/parts/y1.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ad86b096e2261571141be4e6c68b2a29353948b6bb7fb62bdb131e32008b05e5 -size 2161 +oid sha256:2152c7e63dcef3ce29a1f3c3ef7bad414e13ebeb71b982333a70ce2ba6e85596 +size 1980 diff --git a/online/src/wc/zometool/parts/y2.svg b/online/src/wc/zometool/parts/y2.svg index 0b4a849f8..6da2f6eb5 100644 --- a/online/src/wc/zometool/parts/y2.svg +++ b/online/src/wc/zometool/parts/y2.svg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d7a7248c029848c1cb594bdc2e89407ed76d6aadc9057bba1d58f4bce62d073 -size 2168 +oid sha256:a26303257237b12a2ec5c88212773c25c3014372d4054753aef471bae954c631 +size 1987 diff --git a/online/src/wc/zometool/products-list.jsx b/online/src/wc/zometool/products-list.jsx index c5b44a0e1..7716fc89c 100644 --- a/online/src/wc/zometool/products-list.jsx +++ b/online/src/wc/zometool/products-list.jsx @@ -8,13 +8,11 @@ import { instructionsCSS } from "./zometool.css.js"; const debug = false; const product_catalog_url = 'https://zometool.github.io/vzome-sharing/metadata/zometool-products.json'; -const parts_catalog_url = 'https://zometool.github.io/vzome-sharing/metadata/zometool-parts.json'; const fetchJSON = url => fetch( url ) .then( response => response.text() ) .then( text => JSON.parse( text ) ); const productsPromise = fetchJSON( product_catalog_url ); -const partsPromise = fetchJSON( parts_catalog_url ); -const findProducts = ( bom, parts, products ) => +const findProducts = ( bom, products ) => { const productCoversBom = ( product, bom ) => bom .reduce( (covers, part) => covers && product.bom[ part.partNum ] >= part.count, true ); @@ -33,9 +31,9 @@ const ZometoolProducts = props => { const [ matchingProducts, setMatchingProducts ] = createSignal( [] ); - Promise.all( [ productsPromise, partsPromise ] ) - .then( ([ products, parts ]) => { - setMatchingProducts( findProducts( props.bom, parts, products ) ); + productsPromise + .then( ( products ) => { + setMatchingProducts( findProducts( props.bom, products ) ); } ); return ( diff --git a/online/src/worker/legacy/partslist.js b/online/src/worker/legacy/partslist.js index ba9a3ce78..e27175f04 100644 --- a/online/src/worker/legacy/partslist.js +++ b/online/src/worker/legacy/partslist.js @@ -1,5 +1,5 @@ -export const assemblePartsList = shapes => +export const assemblePartsList = ( shapes, colors ) => { const bom = {}; for (const id in shapes) { @@ -7,10 +7,14 @@ export const assemblePartsList = shapes => if ( !name && !orbit ) continue; const row = name || `${orbit}:${length}` for (const { color } of instances) { + const match = Object.entries( colors ) .filter( ([ name, value ]) => value === color ); + const colorBin = match[0]? match[0][ 0 ] : 'other'; if ( ! bom[ row ] ) - bom[ row ] = 1; + bom[ row ] = {}; + if ( ! bom[ row ][ colorBin ] ) + bom[ row ][ colorBin ] = 1; else - bom[ row ] = bom[ row ] + 1; + bom[ row ][ colorBin ] = bom[ row ][ colorBin ] + 1; } } return bom; diff --git a/online/src/worker/vzome-worker-static.js b/online/src/worker/vzome-worker-static.js index 8556218e9..ef992b0c1 100644 --- a/online/src/worker/vzome-worker-static.js +++ b/online/src/worker/vzome-worker-static.js @@ -113,13 +113,19 @@ const fetchFileText = selected => }) } +// Fetch the official Zometool colors +const parts_catalog_url = 'https://zometool.github.io/vzome-sharing/metadata/zometool-parts.json'; +const partsPromise = fetch( parts_catalog_url ) .then( response => response.text() ) .then( text => JSON.parse( text ) ); + const clientEvents = report => { const sceneChanged = ( scene, edit='--START--' ) => { report( { type: 'SCENE_RENDERED', payload: { scene, edit } } ); - const bom = assemblePartsList( scene.shapes ); - report( { type: 'BOM_CHANGED', payload: bom } ); + partsPromise .then( ({ colors }) => { + const bom = assemblePartsList( scene.shapes, colors ); + report( { type: 'BOM_CHANGED', payload: bom } ); + }); } const shapeDefined = shape => report( { type: 'SHAPE_DEFINED', payload: shape } );