@@ -27,8 +27,8 @@ public class GameStateManagerBuilder
2727
2828 private AssetCollection GameAssets { get ; } = new ( ) ;
2929
30- private Action < ContainerBuilder , IConfiguration , ServiceWatcher > ? AddServicesCallback { get ; set ; }
31- private Action < IConfigurationBuilder > ? ConfigurationCallback { get ; set ; }
30+ private List < Action < ContainerBuilder , IConfiguration , ServiceWatcher > > AddServicesCallbacks { get ; } = [ ] ;
31+ private List < Action < IConfigurationBuilder > > ConfigurationCallbacks { get ; } = [ ] ;
3232 private string WindowTitle { get ; set ; } = "PlayPlayMini Game" ;
3333 private ( int Width , int Height , int Zoom ) WindowSize { get ; set ; } = ( 1920 / 3 , 1080 / 3 , 2 ) ;
3434 private bool FixedTimeStep { get ; set ; }
@@ -108,30 +108,21 @@ public GameStateManagerBuilder AddAssets(IList<IAsset> assets)
108108
109109 public GameStateManagerBuilder AddServices ( Action < ContainerBuilder , IConfiguration , ServiceWatcher > callback )
110110 {
111- if ( AddServicesCallback is not null )
112- throw new ArgumentException ( "AddServices may only be called once!" ) ;
113-
114- AddServicesCallback = callback ;
111+ AddServicesCallbacks . Add ( callback ) ;
115112
116113 return this ;
117114 }
118115
119116 public GameStateManagerBuilder AddServices ( Action < ContainerBuilder , IConfiguration > callback )
120117 {
121- if ( AddServicesCallback is not null )
122- throw new ArgumentException ( "AddServices may only be called once!" ) ;
123-
124- AddServicesCallback = ( s , c , _ ) => callback ( s , c ) ;
118+ AddServicesCallbacks . Add ( ( s , c , _ ) => callback ( s , c ) ) ;
125119
126120 return this ;
127121 }
128122
129123 public GameStateManagerBuilder AddConfiguration ( Action < IConfigurationBuilder > callback )
130124 {
131- if ( ConfigurationCallback is not null )
132- throw new ArgumentException ( "AddConfiguration may only be called once!" ) ;
133-
134- ConfigurationCallback = callback ;
125+ ConfigurationCallbacks . Add ( callback ) ;
135126
136127 return this ;
137128 }
@@ -154,7 +145,8 @@ public void Run()
154145 . AddJsonFile ( Path . Combine ( "Content" , "appsettings.json" ) , optional : true , reloadOnChange : false ) // TODO: does this work on Android?
155146 ;
156147
157- ConfigurationCallback ? . Invoke ( configBuilder ) ;
148+ foreach ( var callback in ConfigurationCallbacks )
149+ callback ( configBuilder ) ;
158150
159151 var configuration = configBuilder . Build ( ) ;
160152
@@ -215,7 +207,8 @@ public void Run()
215207 . As ( typeof ( ILogger < > ) )
216208 . SingleInstance ( ) ;
217209
218- AddServicesCallback ? . Invoke ( builder , configuration , serviceWatcher ) ;
210+ foreach ( var callback in AddServicesCallbacks )
211+ callback ( builder , configuration , serviceWatcher ) ;
219212
220213 if ( InitialGameState is null )
221214 throw new ArgumentException ( "No initial game state set! You must call GameStateManagerBuilder's SetInitialGameState method before calling its Run method." ) ;
0 commit comments