Skip to content

Sim

Overview

Main class that represents one simulation. Provides default initialization, such as polyfills as well. If the simulation has only one screen, then there is no homescreen, home icon or screen icon in the navigation bar.

The type for the contained Screen instances is Screen<any,any> since we do not want to parameterize Sim<[{M1,V1},{M2,V2}] etc.

@author Sam Reid (PhET Interactive Simulations) @author Chris Malley (PixelZoom, Inc.) @author Jonathan Olson <jonathan.olson@colorado.edu>

Class Sim

import { Sim } from 'scenerystack/sim';

Constructor

new Sim( simNameProperty : TReadOnlyProperty<string>, allSimScreens : AnyScreen[], providedOptions? : SimOptions )

Instance Methods

showPopup( popup : PopupableNode, isModal : boolean )

Adds a popup in the global coordinate frame. If the popup is model, it displays a semi-transparent black input barrier behind it. A modal popup prevent the user from interacting with the reset of the application until the popup is hidden. Use hidePopup() to hide the popup. @param popup - the popup, must implemented node.hide(), called by hidePopup @param isModal - whether popup is modal

hidePopup( popup : PopupableNode, isModal : boolean )

Hides a popup that was previously displayed with showPopup() @param popup @param isModal - whether popup is modal

start()

stepOneFrame()

Run a single frame including model, view and display updates, used by Legends of Learning

stepSimulation( dt : number )

Update the simulation model, view, scenery display with an elapsed time of dt. @param dt - in seconds (phet-io)

setPDOMViewsVisible( visible : boolean )

Hide or show all accessible content related to the sim ScreenViews, and navigation bar. This content will remain visible, but not be tab navigable or readable with a screen reader. This is generally useful when displaying a pop up or modal dialog.

setSimVoicingVisible( visible : boolean )

Set the voicingVisible state of simulation components. When false, ONLY the Toolbar and its buttons will be able to announce Voicing utterances. This is used by the "Sim Voicing" switch in the toolbar which will disable all Voicing in the sim so that only Toolbar content is announced.

setNonModalVoicingVisible( visible : boolean )

Sets voicingVisible on all elements "behind" the modal node stack. In this case, voicing should not work for those components when set to false. @param visible

getAssertionDebugInfo() : object

Get helpful information for replicating the bug when an assertion occurs.

Instance Properties

isConstructionCompleteProperty : TReadOnlyProperty<boolean>

(readonly)

dimensionProperty : TReadOnlyProperty<Dimension2>

(readonly)

Stores the effective self dimensions that the simulation will be taking up

homeScreen : HomeScreen | null

(readonly)

frameStartedEmitter : Emitter

(readonly)

Sim screens normally update by implementing model.step(dt) or view.step(dt). When that is impossible or relatively awkward, it is possible to listen for a callback when a frame begins, when a frame is being processed or after the frame is complete. See https://github.com/phetsims/joist/issues/534 Indicates when a frame starts. Listen to this Emitter if you have an action that must be performed before the step begins.

frameEndedEmitter : Emitter

(readonly)

stepSimulationAction : PhetioAction<[ number ]>

(readonly)

Steps the simulation. This Action is implemented so it can be automatically played back for PhET-iO record/playback. Listen to this Action if you have an action that happens during the simulation step.

simScreens : AnyScreen[]

(readonly)

the ordered list of sim-specific screens that appear in this runtime of the sim

screens : AnyScreen[]

(readonly)

all screens that appear in the runtime of this sim, with the homeScreen first if it was created

displayedSimNameProperty : TReadOnlyProperty<string>

(readonly)

the displayed name in the sim. This depends on what screens are shown this runtime (effected by query parameters).

selectedScreenProperty : Property<AnyScreen>

(readonly)

activeSimScreensProperty : ReadOnlyProperty<AnyScreen[]>

activeProperty : BooleanProperty

(readonly)

When the sim is active, scenery processes inputs and stepSimulation(dt) runs from the system clock. Set to false for when the sim will be paused.

browserTabVisibleProperty : TReadOnlyProperty<boolean>

(readonly)

indicates whether the browser tab containing the simulation is currently visible

lookAndFeel : LookAndFeel

(readonly)

hasKeyboardHelpContent : boolean

(readonly)

If any sim screen has keyboard help content, trigger creation of a keyboard help button.

frameCounter

number of animation frames that have occurred

locale : Locale

(readonly)

Make our locale available

display : SimDisplay

(readonly)

preferencesModel : PreferencesModel

(readonly)

Manages state related to preferences. Enabled features for preferences are provided through the PreferencesModel.

topLayer

(readonly)

layer for popups, dialogs, and their backgrounds and barriers TODO: How should we handle the popup for navigation? Can we set this to private? https://github.com/phetsims/joist/issues/841

rootNode : Node

(readonly)

root node for the Display

credits : CreditsData

(readonly)

Type SimOptions

import type { SimOptions } from 'scenerystack/sim';
  • credits?: CreditsData
  • homeScreenWarningNode?: null | Node
    a {Node} placed onto the home screen (if available)
  • preferencesModel?: PreferencesModel | null
    The PreferencesModel defines the available features for the simulation that are controllable through the Preferences Dialog. Will not be null! This is a workaround to prevent creating a "default" PreferencesModel
  • webgl?: boolean
    Passed to SimDisplay, but a top level option for API ease.
  • detachInactiveScreenViews?: boolean
    When false (default), all ScreenViews will be children (but only one will be visible). When true, only the selected ScreenView will be a child. This is useful for performance reasons, e.g. when using WebGL or wish to reduce memory costs. Setting this to true MAY increase the amount of time needed to switch screens. See https://github.com/phetsims/faradays-electromagnetic-lab/issues/153
  • & PickOptional<PhetioObjectOptions, "phetioDesigned">

Source Code

See the source for Sim.ts in the joist repository.