@@ -21,9 +21,10 @@ const DEFAULT_PLUGINS = [PluginImmer];
2121 */
2222export const SetupCtx = ( ctx , game ) => {
2323 [ ...DEFAULT_PLUGINS , ...game . plugins ]
24- . filter ( plugin => plugin . setupCtx !== undefined )
24+ . filter ( plugin => plugin . ctx !== undefined )
25+ . filter ( plugin => plugin . ctx . setup !== undefined )
2526 . forEach ( plugin => {
26- ctx = plugin . setupCtx ( ctx , game ) ;
27+ ctx = plugin . ctx . setup ( ctx , game ) ;
2728 } ) ;
2829 return ctx ;
2930} ;
@@ -37,9 +38,10 @@ export const SetupCtx = (ctx, game) => {
3738 */
3839export const SetupG = ( G , ctx , game ) => {
3940 [ ...DEFAULT_PLUGINS , ...game . plugins ]
40- . filter ( plugin => plugin . setupG !== undefined )
41+ . filter ( plugin => plugin . G !== undefined )
42+ . filter ( plugin => plugin . G . setup !== undefined )
4143 . forEach ( plugin => {
42- G = plugin . setupG ( G , ctx , game ) ;
44+ G = plugin . G . setup ( G , ctx , game ) ;
4345 } ) ;
4446 return G ;
4547} ;
@@ -50,26 +52,28 @@ export const SetupG = (G, ctx, game) => {
5052 * @param {object } ctx - The ctx object.
5153 * @param {object } game - The game object.
5254 */
53- export const AddToCtx = ( ctx , game ) => {
55+ export const CtxPreMove = ( ctx , game ) => {
5456 [ ...DEFAULT_PLUGINS , ...game . plugins ]
55- . filter ( plugin => plugin . addToCtx !== undefined )
57+ . filter ( plugin => plugin . ctx !== undefined )
58+ . filter ( plugin => plugin . ctx . preMove !== undefined )
5659 . forEach ( plugin => {
57- ctx = plugin . addToCtx ( ctx , game ) ;
60+ ctx = plugin . ctx . preMove ( ctx , game ) ;
5861 } ) ;
5962 return ctx ;
6063} ;
6164
6265/**
63- * Removes the provided plugins to ctx after processing a move / event.
66+ * Postprocesses ctx after a move / event.
6467 *
6568 * @param {object } ctx - The ctx object.
6669 * @param {object } game - The game object.
6770 */
68- export const RemoveFromCtx = ( ctx , game ) => {
71+ export const CtxPostMove = ( ctx , game ) => {
6972 [ ...DEFAULT_PLUGINS , ...game . plugins ]
70- . filter ( plugin => plugin . removeFromCtx !== undefined )
73+ . filter ( plugin => plugin . ctx !== undefined )
74+ . filter ( plugin => plugin . ctx . postMove !== undefined )
7175 . forEach ( plugin => {
72- ctx = plugin . removeFromCtx ( ctx , game ) ;
76+ ctx = plugin . ctx . postMove ( ctx , game ) ;
7377 } ) ;
7478 return ctx ;
7579} ;
@@ -80,26 +84,28 @@ export const RemoveFromCtx = (ctx, game) => {
8084 * @param {object } G - The G object.
8185 * @param {object } game - The game object.
8286 */
83- export const AddToG = ( G , game ) => {
87+ export const GPreMove = ( G , game ) => {
8488 [ ...DEFAULT_PLUGINS , ...game . plugins ]
85- . filter ( plugin => plugin . addToG !== undefined )
89+ . filter ( plugin => plugin . G !== undefined )
90+ . filter ( plugin => plugin . G . preMove !== undefined )
8691 . forEach ( plugin => {
87- G = plugin . addToG ( G , game ) ;
92+ G = plugin . G . preMove ( G , game ) ;
8893 } ) ;
8994 return G ;
9095} ;
9196
9297/**
93- * Removes the provided plugins to G after processing a move / event.
98+ * Postprocesses G after a move / event.
9499 *
95100 * @param {object } G - The G object.
96101 * @param {object } game - The game object.
97102 */
98- export const RemoveFromG = ( G , game ) => {
103+ export const GPostMove = ( G , game ) => {
99104 [ ...DEFAULT_PLUGINS , ...game . plugins ]
100- . filter ( plugin => plugin . removeFromG !== undefined )
105+ . filter ( plugin => plugin . G !== undefined )
106+ . filter ( plugin => plugin . G . postMove !== undefined )
101107 . forEach ( plugin => {
102- G = plugin . removeFromG ( G , game ) ;
108+ G = plugin . G . postMove ( G , game ) ;
103109 } ) ;
104110 return G ;
105111} ;
@@ -111,17 +117,17 @@ export const RemoveFromG = (G, game) => {
111117 * @param {object } game - The game object.
112118 */
113119export const FnWrap = ( fn , game ) => {
114- const reducer = ( acc , { fnWrap } ) => fnWrap ( acc ) ;
120+ const reducer = ( acc , { fnWrap } ) => fnWrap ( acc , game ) ;
115121 const g = [ ...DEFAULT_PLUGINS , ...game . plugins ]
116122 . filter ( plugin => plugin . fnWrap !== undefined )
117123 . reduce ( reducer , fn ) ;
118124
119125 return ( G , ctx , ...args ) => {
120- G = AddToG ( G , game ) ;
121- ctx = AddToCtx ( ctx , game ) ;
126+ G = GPreMove ( G , game ) ;
127+ ctx = CtxPreMove ( ctx , game ) ;
122128 G = g ( G , ctx , ...args ) ;
123- ctx = RemoveFromCtx ( ctx , game ) ;
124- ctx = RemoveFromG ( G , game ) ;
129+ ctx = CtxPostMove ( ctx , game ) ;
130+ ctx = GPostMove ( G , game ) ;
125131 return G ;
126132 } ;
127133} ;
0 commit comments