@@ -17,13 +17,13 @@ const DEFAULT_PLUGINS = [PluginImmer];
1717 * Applies the provided plugins to ctx during game setup.
1818 *
1919 * @param {object } ctx - The ctx object.
20- * @param {Array } plugins - Array of plugins .
20+ * @param {object } game - The game object .
2121 */
22- export const SetupCtx = ( ctx , plugins ) => {
23- [ ...DEFAULT_PLUGINS , ...plugins ]
22+ export const SetupCtx = ( ctx , game ) => {
23+ [ ...DEFAULT_PLUGINS , ...game . plugins ]
2424 . filter ( plugin => plugin . setupCtx !== undefined )
2525 . forEach ( plugin => {
26- ctx = plugin . setupCtx ( ctx ) ;
26+ ctx = plugin . setupCtx ( ctx , game ) ;
2727 } ) ;
2828 return ctx ;
2929} ;
@@ -33,13 +33,13 @@ export const SetupCtx = (ctx, plugins) => {
3333 *
3434 * @param {object } G - The G object.
3535 * @param {object } ctx - The ctx object.
36- * @param {Array } plugins - Array of plugins .
36+ * @param {object } game - The game object .
3737 */
38- export const SetupG = ( G , ctx , plugins ) => {
39- [ ...DEFAULT_PLUGINS , ...plugins ]
38+ export const SetupG = ( G , ctx , game ) => {
39+ [ ...DEFAULT_PLUGINS , ...game . plugins ]
4040 . filter ( plugin => plugin . setupG !== undefined )
4141 . forEach ( plugin => {
42- G = plugin . setupG ( G , ctx ) ;
42+ G = plugin . setupG ( G , ctx , game ) ;
4343 } ) ;
4444 return G ;
4545} ;
@@ -48,13 +48,13 @@ export const SetupG = (G, ctx, plugins) => {
4848 * Applies the provided plugins to ctx before processing a move / event.
4949 *
5050 * @param {object } ctx - The ctx object.
51- * @param {Array } plugins - Array of plugins .
51+ * @param {object } game - The game object .
5252 */
53- export const AddToCtx = ( ctx , plugins ) => {
54- [ ...DEFAULT_PLUGINS , ...plugins ]
53+ export const AddToCtx = ( ctx , game ) => {
54+ [ ...DEFAULT_PLUGINS , ...game . plugins ]
5555 . filter ( plugin => plugin . addToCtx !== undefined )
5656 . forEach ( plugin => {
57- ctx = plugin . addToCtx ( ctx ) ;
57+ ctx = plugin . addToCtx ( ctx , game ) ;
5858 } ) ;
5959 return ctx ;
6060} ;
@@ -63,13 +63,13 @@ export const AddToCtx = (ctx, plugins) => {
6363 * Removes the provided plugins to ctx after processing a move / event.
6464 *
6565 * @param {object } ctx - The ctx object.
66- * @param {Array } plugins - Array of plugins .
66+ * @param {object } game - The game object .
6767 */
68- export const RemoveFromCtx = ( ctx , plugins ) => {
69- [ ...DEFAULT_PLUGINS , ...plugins ]
68+ export const RemoveFromCtx = ( ctx , game ) => {
69+ [ ...DEFAULT_PLUGINS , ...game . plugins ]
7070 . filter ( plugin => plugin . removeFromCtx !== undefined )
7171 . forEach ( plugin => {
72- ctx = plugin . removeFromCtx ( ctx ) ;
72+ ctx = plugin . removeFromCtx ( ctx , game ) ;
7373 } ) ;
7474 return ctx ;
7575} ;
@@ -78,13 +78,13 @@ export const RemoveFromCtx = (ctx, plugins) => {
7878 * Applies the provided plugins to G before processing a move / event.
7979 *
8080 * @param {object } G - The G object.
81- * @param {Array } plugins - Array of plugins .
81+ * @param {object } game - The game object .
8282 */
83- export const AddToG = ( G , plugins ) => {
84- [ ...DEFAULT_PLUGINS , ...plugins ]
83+ export const AddToG = ( G , game ) => {
84+ [ ...DEFAULT_PLUGINS , ...game . plugins ]
8585 . filter ( plugin => plugin . addToG !== undefined )
8686 . forEach ( plugin => {
87- G = plugin . addToG ( G ) ;
87+ G = plugin . addToG ( G , game ) ;
8888 } ) ;
8989 return G ;
9090} ;
@@ -93,13 +93,13 @@ export const AddToG = (G, plugins) => {
9393 * Removes the provided plugins to G after processing a move / event.
9494 *
9595 * @param {object } G - The G object.
96- * @param {Array } plugins - Array of plugins .
96+ * @param {object } game - The game object .
9797 */
98- export const RemoveFromG = ( G , plugins ) => {
99- [ ...DEFAULT_PLUGINS , ...plugins ]
98+ export const RemoveFromG = ( G , game ) => {
99+ [ ...DEFAULT_PLUGINS , ...game . plugins ]
100100 . filter ( plugin => plugin . removeFromG !== undefined )
101101 . forEach ( plugin => {
102- G = plugin . removeFromG ( G ) ;
102+ G = plugin . removeFromG ( G , game ) ;
103103 } ) ;
104104 return G ;
105105} ;
@@ -108,20 +108,20 @@ export const RemoveFromG = (G, plugins) => {
108108 * Applies the provided plugins to the given move / flow function.
109109 *
110110 * @param {function } fn - The move function or trigger to apply the plugins to.
111- * @param {Array } plugins - Array of plugins .
111+ * @param {object } game - The game object .
112112 */
113- export const FnWrap = ( fn , plugins ) => {
113+ export const FnWrap = ( fn , game ) => {
114114 const reducer = ( acc , { fnWrap } ) => fnWrap ( acc ) ;
115- const g = [ ...DEFAULT_PLUGINS , ...plugins ]
115+ const g = [ ...DEFAULT_PLUGINS , ...game . plugins ]
116116 . filter ( plugin => plugin . fnWrap !== undefined )
117117 . reduce ( reducer , fn ) ;
118118
119119 return ( G , ctx , ...args ) => {
120- G = AddToG ( G , plugins ) ;
121- ctx = AddToCtx ( ctx , plugins ) ;
120+ G = AddToG ( G , game ) ;
121+ ctx = AddToCtx ( ctx , game ) ;
122122 G = g ( G , ctx , ...args ) ;
123- ctx = RemoveFromCtx ( ctx , plugins ) ;
124- ctx = RemoveFromG ( G , plugins ) ;
123+ ctx = RemoveFromCtx ( ctx , game ) ;
124+ ctx = RemoveFromG ( G , game ) ;
125125 return G ;
126126 } ;
127127} ;
0 commit comments