From 5ef3abb66edbb3f8877bd874d24f33666ff690a3 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Thu, 3 Mar 2022 12:55:50 +0100 Subject: [PATCH] Improved sharing --- src/components/AppHeader.vue | 2 +- src/components/SideMenu.vue | 11 +------ src/composables/sharing.ts | 58 +++++++++++++++++++++++------------- src/globals.ts | 4 +-- src/locales/en.json | 2 +- src/locales/fr.json | 2 +- src/types.ts | 6 ++++ src/views/GameView.vue | 11 +++---- src/views/HomeView.vue | 5 +--- 9 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue index cb6610a..f6dd544 100644 --- a/src/components/AppHeader.vue +++ b/src/components/AppHeader.vue @@ -8,7 +8,7 @@

- N0mbersbeta + N0mbersalpha

-
+
-
- Features to come: -
    -
  • Keyboard input
  • -
  • Random number
  • -
  • Less bugs
  • -
-
-
Build {{ buildDate }}
diff --git a/src/composables/sharing.ts b/src/composables/sharing.ts index 428f160..1495adc 100644 --- a/src/composables/sharing.ts +++ b/src/composables/sharing.ts @@ -1,38 +1,54 @@ import { i18n } from '@/i18n' -import { percentageDiff } from '@/utils' +import { percentageDiff, setDailyPRNG, shuffle } from '@/utils' import { numberOfGamesSinceStart, operations, result } from './game-state' import { showToast } from './toast-manager' +const squareSymbols = ['🟦', '🟨', '🟫', '🟧', '🟥', '🟩', '🟪'] +const roundSymbols = ['🔵', '🟡', '🟤', '🟠', '🔴', '🟢', '🟣'] + +export function shuffleSymbols(): void { + setDailyPRNG() + shuffle(squareSymbols) + shuffle(roundSymbols) +} + function getSharingText(): string { + console.log(squareSymbols) + console.log(roundSymbols) // × ÷ + - - const emojis: string[] = [] + const endResult = operations[operations.length - 1].result?.value ?? 0 + + const lines: string[] = [] for (const op of operations) { - switch (op.operator) { - case '+': - emojis.push('+') - break - case '-': - emojis.push('-') - break - case '*': - emojis.push('×') - break - case '/': - emojis.push('÷') - break + if (op.left && !op.left.symbol) { + op.left.symbol = op.left.original + ? squareSymbols.pop() + : roundSymbols.pop() + } + if (op.right && !op.right.symbol) { + op.right.symbol = op.right.original + ? squareSymbols.pop() + : roundSymbols.pop() + } + if (op.result && !op.result.symbol) { + op.result.symbol = roundSymbols.pop() } } - const endResult = operations[operations.length - 1].result?.value ?? 0 + for (const op of operations) { + lines.push( + `${op.left?.symbol} ${op.operator} ${op.right?.symbol} = ${op.result?.value === endResult ? endResult : op.result?.symbol}`, + ) + } + return `N0mbers #${numberOfGamesSinceStart()} -=========== -${emojis.join(' ')} = ${endResult} -Score: ${100 - percentageDiff(result.value, endResult) * 100}% -=========== + +${lines.join('\n')} ${result.value === endResult ? '✔' : '❌'} + https://n0mbers.scambier.xyz` } export function toClipboard(): void { navigator.clipboard.writeText(getSharingText()) showToast(i18n.global.t('copiedInClipboard'), 3000) -} +} \ No newline at end of file diff --git a/src/globals.ts b/src/globals.ts index 8aaadc6..a10f702 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -8,8 +8,8 @@ export const LSK_STATS = 'n0_stats' export const operators = ['+', '-', '*', '/'] as const export const pools = { - 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25], - 2: [2, 2, 3, 3, 5, 5, 7, 11, 13, 17, 19, 23], + 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 75, 100], + 2: [2, 2, 3, 3, 5, 5, 7, 7, 11, 13, 17, 19, 23], 3: [5, 5, 5, 5, 5, 2, 2, 2, 2, 2], } as const diff --git a/src/locales/en.json b/src/locales/en.json index ac3e8da..4f848bb 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -12,7 +12,7 @@ "dailyDescription": "The daily challenge changes every day at midnight (CET), and is common to all players.", "share": "Share", "finishDailyToPlayRandom": "Finish the daily challenge to unlock.", - "gameDescription": "Combine the numbers to reach the result.", + "gameDescription": "Combine the required numbers to reach the result.
Game under development, some features are missing or changing.", "randomDescription": "A challenge at random, just for fun.", "copiedInClipboard": "Copied in clipboard", "soon": "Soon", diff --git a/src/locales/fr.json b/src/locales/fr.json index 50cfa87..32b84ef 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -9,7 +9,7 @@ "impossible": "☠", "dailyGame": "Défi quotidien", "randomGame": "Nombre au hasard", - "gameDescription": "Combinez les nombres imposés afin d'atteindre le résultat.", + "gameDescription": "Combinez les nombres imposés afin d'atteindre le résultat.
Jeu en cours de développement, certaines fonctionnalités sont manquantes ou changeantes.", "dailyDescription": "Le défi quotidien change chaque jour à minuit (CET), et est commun à tous les joueurs.", "randomDescription": "Une partie au hasard, pour le plaisir.", "share": "Partager", diff --git a/src/types.ts b/src/types.ts index 2b8f6cd..d4c32da 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,12 @@ export type OperatorType = '+' | '-' | '*' | '/' export type Plaquette = { value: number free: boolean + + /** If the plaquette is one of the pre-selected */ + original: boolean + + /** For sharing */ + symbol?: string } export type Operation = { diff --git a/src/views/GameView.vue b/src/views/GameView.vue index a4822b0..2397b5b 100644 --- a/src/views/GameView.vue +++ b/src/views/GameView.vue @@ -40,7 +40,7 @@
- + @@ -64,7 +64,7 @@ v-html="t('endGame.failureLabel')" />