From 15a8c6198cac6a3f7e540dbadca7ff87a7b68fbb Mon Sep 17 00:00:00 2001 From: Matthew Blackman Date: Thu, 16 Feb 2023 10:41:53 -0500 Subject: [PATCH] Only add groups for extreme elements in DC Lab - see https://github.com/phetsims/circuit-construction-kit-common/issues/900 --- js/model/Circuit.ts | 8 +++--- js/view/CircuitNode.ts | 60 ++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/js/model/Circuit.ts b/js/model/Circuit.ts index 793e344e..ab411381 100644 --- a/js/model/Circuit.ts +++ b/js/model/Circuit.ts @@ -378,7 +378,7 @@ export default class Circuit extends PhetioObject { } ); }, () => createVertices( BATTERY_LENGTH ), { phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), - tandem: this.includeLabElements ? tandem.createTandem( 'extremeBatteryGroup' ) : Tandem.OPT_OUT, + tandem: ( this.includeLabElements && !this.includeACElements ) ? tandem.createTandem( 'extremeBatteryGroup' ) : Tandem.OPT_OUT, phetioDynamicElementName: 'extremeBattery' } ); @@ -402,7 +402,7 @@ export default class Circuit extends PhetioObject { new Resistor( startVertex, endVertex, ResistorType.EXTREME_RESISTOR, tandem ), () => createVertices( ResistorType.EXTREME_RESISTOR.length ), { phetioType: PhetioGroup.PhetioGroupIO( Resistor.ResistorIO ), - tandem: tandem.createTandem( 'extremeResistorGroup' ) + tandem: ( this.includeLabElements && !this.includeACElements ) ? tandem.createTandem( 'extremeResistorGroup' ) : Tandem.OPT_OUT } ); this.householdObjectGroup = new PhetioGroup( @@ -437,7 +437,7 @@ export default class Circuit extends PhetioObject { } ); }, () => createVertices( 100 ), { phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), - tandem: this.includeLabElements ? tandem.createTandem( 'extremeLightBulbGroup' ) : Tandem.OPT_OUT + tandem: ( this.includeLabElements && !this.includeACElements ) ? tandem.createTandem( 'extremeLightBulbGroup' ) : Tandem.OPT_OUT } ); this.capacitorGroup = new PhetioGroup( @@ -478,7 +478,7 @@ export default class Circuit extends PhetioObject { } ); }, () => createVertices( 100 ), { phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), - tandem: this.includeLabElements ? tandem.createTandem( 'realLightBulbGroup' ) : Tandem.OPT_OUT + tandem: ( this.includeLabElements && !this.includeACElements ) ? tandem.createTandem( 'realLightBulbGroup' ) : Tandem.OPT_OUT } ); this.groups = [ diff --git a/js/view/CircuitNode.ts b/js/view/CircuitNode.ts index 9b471533..ed00d550 100644 --- a/js/view/CircuitNode.ts +++ b/js/view/CircuitNode.ts @@ -361,27 +361,6 @@ export default class CircuitNode extends Node { // Only create the relevant groups if ( circuit.includeLabElements ) { - initializeCircuitElementType( ( e: CircuitElement ) => e instanceof Battery && e.batteryType === 'high-voltage', this.fixedCircuitElementLayer, - new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => new BatteryNode( screenView, this, circuitElement as Battery, this.model.viewTypeProperty, tandem ), - () => [ this.circuit.batteryGroup.archetype ], { - phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), - tandem: tandem.createTandem( 'extremeBatteryNodeGroup' ), - supportsDynamicState: false - } ) ); - initializeCircuitElementType( ( e: CircuitElement ) => e instanceof LightBulb && e.isExtreme && !e.isReal, this.fixedCircuitElementLayer, - new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => new CCKCLightBulbNode( screenView, this, circuitElement as LightBulb, this.model.isValueDepictionEnabledProperty, this.model.viewTypeProperty, tandem ), - () => [ this.circuit.extremeLightBulbGroup.archetype ], { - phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), - tandem: tandem.createTandem( 'extremeLightBulbNodeGroup' ), - supportsDynamicState: false - } ) ); - initializeCircuitElementType( ( e: CircuitElement ) => e instanceof LightBulb && e.isReal, this.fixedCircuitElementLayer, - new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => new CCKCLightBulbNode( screenView, this, circuitElement as LightBulb, this.model.isValueDepictionEnabledProperty, this.model.viewTypeProperty, tandem ), - () => [ this.circuit.realLightBulbGroup.archetype ], { - phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), - tandem: tandem.createTandem( 'realLightBulbNodeGroup' ), - supportsDynamicState: false - } ) ); initializeCircuitElementType( ( e: CircuitElement ) => e instanceof SeriesAmmeter, this.fixedCircuitElementLayer, new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => new SeriesAmmeterNode( screenView, this, circuitElement as SeriesAmmeter, tandem, this.model.isValueDepictionEnabledProperty ), @@ -390,6 +369,37 @@ export default class CircuitNode extends Node { tandem: tandem.createTandem( 'seriesAmmeterNodeGroup' ), supportsDynamicState: false } ) ); + if ( !circuit.includeACElements ) { + initializeCircuitElementType( ( e: CircuitElement ) => e instanceof Battery && e.batteryType === 'high-voltage', this.fixedCircuitElementLayer, + new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => new BatteryNode( screenView, this, circuitElement as Battery, this.model.viewTypeProperty, tandem ), + () => [ this.circuit.batteryGroup.archetype ], { + phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), + tandem: tandem.createTandem( 'extremeBatteryNodeGroup' ), + supportsDynamicState: false + } ) ); + initializeCircuitElementType( ( e: CircuitElement ) => e instanceof Resistor && e.resistorType === ResistorType.EXTREME_RESISTOR, this.fixedCircuitElementLayer, + new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => + new ResistorNode( screenView, this, circuitElement as Resistor, this.model.viewTypeProperty, tandem ), + () => [ this.circuit.extremeResistorGroup.archetype ], { + phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), + tandem: tandem.createTandem( 'extremeResistorNodeGroup' ), + supportsDynamicState: false + } ) ); + initializeCircuitElementType( ( e: CircuitElement ) => e instanceof LightBulb && e.isExtreme && !e.isReal, this.fixedCircuitElementLayer, + new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => new CCKCLightBulbNode( screenView, this, circuitElement as LightBulb, this.model.isValueDepictionEnabledProperty, this.model.viewTypeProperty, tandem ), + () => [ this.circuit.extremeLightBulbGroup.archetype ], { + phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), + tandem: tandem.createTandem( 'extremeLightBulbNodeGroup' ), + supportsDynamicState: false + } ) ); + initializeCircuitElementType( ( e: CircuitElement ) => e instanceof LightBulb && e.isReal, this.fixedCircuitElementLayer, + new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => new CCKCLightBulbNode( screenView, this, circuitElement as LightBulb, this.model.isValueDepictionEnabledProperty, this.model.viewTypeProperty, tandem ), + () => [ this.circuit.realLightBulbGroup.archetype ], { + phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), + tandem: tandem.createTandem( 'realLightBulbNodeGroup' ), + supportsDynamicState: false + } ) ); + } } if ( circuit.includeACElements ) { initializeCircuitElementType( ( e: CircuitElement ) => e instanceof Capacitor, this.fixedCircuitElementLayer, @@ -422,14 +432,6 @@ export default class CircuitNode extends Node { tandem: tandem.createTandem( 'resistorNodeGroup' ), supportsDynamicState: false } ) ); - initializeCircuitElementType( ( e: CircuitElement ) => e instanceof Resistor && e.resistorType === ResistorType.EXTREME_RESISTOR, this.fixedCircuitElementLayer, - new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => - new ResistorNode( screenView, this, circuitElement as Resistor, this.model.viewTypeProperty, tandem ), - () => [ this.circuit.extremeResistorGroup.archetype ], { - phetioType: PhetioGroup.PhetioGroupIO( Node.NodeIO ), - tandem: tandem.createTandem( 'extremeResistorNodeGroup' ), - supportsDynamicState: false - } ) ); initializeCircuitElementType( ( e: CircuitElement ) => e instanceof Resistor && e.resistorType !== ResistorType.RESISTOR && e.resistorType !== ResistorType.EXTREME_RESISTOR, this.fixedCircuitElementLayer, new PhetioGroup( ( tandem: Tandem, circuitElement: CircuitElement ) => { if ( circuitElement instanceof Dog ) {