diff --git a/src/utils/hooks/use-alternative.hook.ts b/src/utils/hooks/use-alternative.hook.ts index 97b5c34..78e1d4d 100644 --- a/src/utils/hooks/use-alternative.hook.ts +++ b/src/utils/hooks/use-alternative.hook.ts @@ -5,17 +5,18 @@ import { AsyncPlugin } from "@plugins"; /** * This hook allows you to client-side prediction command * Command will be executed in alternative game - * @param command - Command to execute in alternative world + * @param command - Command(s) to execute in alternative world * @param core - Game reference if hydration disabled * @returns { Promise } - Alternative isolated game (not affect real) */ -export async function useAlternative(command: ICommand, core?: Game): Promise { +export async function useAlternative(command: ICommand | ICommand[], core?: Game): Promise { const game = useAlternative.prototype.game as Game || core const asyncPlugin = new AsyncPlugin() const alternative = Game.fromSnapshot(game.save(), alternative => alternative.registerPlugin(asyncPlugin)) - await asyncPlugin.asyncExecute(command) + if (!Array.isArray(command)) await asyncPlugin.asyncExecute(command) + else for (const cmd of command) await asyncPlugin.asyncExecute(cmd) return alternative } \ No newline at end of file