From 6f0f9c3aa11092933316c14b7208fc35ba2c35ed Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 5 Oct 2023 14:09:06 +1300 Subject: [PATCH] Set expectedBoardLength --- src/components/HandImporter.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/HandImporter.vue b/src/components/HandImporter.vue index f324e8f..8fc5eb9 100644 --- a/src/components/HandImporter.vue +++ b/src/components/HandImporter.vue @@ -39,6 +39,8 @@ type HandJSON = { const INVALID_BOARD_ERROR = `Invalid '.config.board'. Set board cards manually for an example.`; +const CONFIG_INPUT_KEYS = configKeys.filter(k => ['expectedBoardLength'].indexOf(k) === -1); + const config = useConfigStore(); const store = useStore(); @@ -60,7 +62,7 @@ watch( const generateImportText = async () => { const configObj = Object.fromEntries( Object.entries(config).filter( - ([key, _value]) => configKeys.indexOf(key) !== -1 + ([key, _value]) => CONFIG_INPUT_KEYS.indexOf(key) !== -1 ) ); @@ -93,7 +95,7 @@ const validateConfigPrimitives = (importConfig: any): Result => { error: `Expected '.config' to be an object but got ${typeof importConfig}`, }; - for (const key of configKeys.concat(Object.keys(importConfig))) { + for (const key of CONFIG_INPUT_KEYS.concat(Object.keys(importConfig))) { const newValue = importConfig[key]; const existingValue = (config as any)[key]; console.log({ key, existingValue, newValue }) @@ -131,6 +133,10 @@ const validateBoard = (board: any): Result => { } } + if (board.length > 5) { + return { success: false, error: 'Board cannot have more than 5 cards' }; + } + return { success: true }; }; @@ -177,6 +183,7 @@ const validateImportText = (): Result<{ json?: HandJSON }> => { } importJson.config.board = importJson.config.board.map(parseCardString); + importJson.config.expectedBoardLength = importJson.config.board.length; return { success: true, json: importJson as HandJSON }; };