import { createAction, Dispatch } from '@reduxjs/toolkit' import { Component, GameSystemDependencies } from '..' // TODO; what is the game object in terms of engine? export type GameObject = {[key: string]:Component} export interface GameAddComponentAction{ gameID: number, componentID: number, component: T } export const gameTickAction = createAction('game/tick') export const gameNoopAction = createAction('game/noop') export const gameAddObjectAction = createAction('game/addObject') export const gameAddComponentAction = createAction('game/addComponent') export const gameRemoveComponentAction = createAction('game/removeComponent') export const gameAddObject = (object:GameObject) => async (dispatch: Dispatch, getState: ()=>GameSystemDependencies) => { await dispatch(gameAddObjectAction()) const { gameID } = getState().game await Promise.all(Object.entries(object).map(async ([, component]) => { const { componentID } = getState().game return dispatch(gameAddComponentAction({ component, gameID, componentID, })) })) }