@@ -627,13 +627,14 @@ export class JsPsych {
627
627
} ;
628
628
629
629
let trial_complete ;
630
+ let trial_sim_opts ;
631
+ let trial_sim_opts_merged ;
630
632
if ( ! this . simulation_mode ) {
631
633
trial_complete = trial . type . trial ( this . DOM_target , trial , load_callback ) ;
632
634
}
633
635
if ( this . simulation_mode ) {
634
636
// check if the trial supports simulation
635
637
if ( trial . type . simulate ) {
636
- let trial_sim_opts ;
637
638
if ( ! trial . simulation_options ) {
638
639
trial_sim_opts = this . simulation_options . default ;
639
640
}
@@ -656,16 +657,23 @@ export class JsPsych {
656
657
trial_sim_opts = trial . simulation_options ;
657
658
}
658
659
}
659
- trial_sim_opts = this . utils . deepCopy ( trial_sim_opts ) ;
660
- trial_sim_opts = this . replaceFunctionsWithValues ( trial_sim_opts , null ) ;
660
+ // merge in default options that aren't overriden by the trial's simulation_options
661
+ // including nested parameters in the simulation_options
662
+ trial_sim_opts_merged = this . utils . deepMerge (
663
+ this . simulation_options . default ,
664
+ trial_sim_opts
665
+ ) ;
661
666
662
- if ( trial_sim_opts ?. simulate === false ) {
667
+ trial_sim_opts_merged = this . utils . deepCopy ( trial_sim_opts_merged ) ;
668
+ trial_sim_opts_merged = this . replaceFunctionsWithValues ( trial_sim_opts_merged , null ) ;
669
+
670
+ if ( trial_sim_opts_merged ?. simulate === false ) {
663
671
trial_complete = trial . type . trial ( this . DOM_target , trial , load_callback ) ;
664
672
} else {
665
673
trial_complete = trial . type . simulate (
666
674
trial ,
667
- trial_sim_opts ?. mode || this . simulation_mode ,
668
- trial_sim_opts ,
675
+ trial_sim_opts_merged ?. mode || this . simulation_mode ,
676
+ trial_sim_opts_merged ,
669
677
load_callback
670
678
) ;
671
679
}
@@ -678,8 +686,13 @@ export class JsPsych {
678
686
// see if trial_complete is a Promise by looking for .then() function
679
687
const is_promise = trial_complete && typeof trial_complete . then == "function" ;
680
688
681
- // in simulation mode we let the simulate function call the load_callback always.
682
- if ( ! is_promise && ! this . simulation_mode ) {
689
+ // in simulation mode we let the simulate function call the load_callback always,
690
+ // so we don't need to call it here. however, if we are in simulation mode but not simulating
691
+ // this particular trial we need to call it.
692
+ if (
693
+ ! is_promise &&
694
+ ( ! this . simulation_mode || ( this . simulation_mode && trial_sim_opts_merged ?. simulate === false ) )
695
+ ) {
683
696
load_callback ( ) ;
684
697
}
685
698
0 commit comments