From cada72746ac6512a7dc8c180d51d0e07bae88d41 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Fri, 4 Mar 2022 12:51:56 +0100 Subject: [PATCH] Improved sharing --- src/composables/game-state.ts | 6 ++- src/composables/sharing.ts | 81 +++++++++++++++++++++-------------- src/views/GameView.vue | 4 +- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/composables/game-state.ts b/src/composables/game-state.ts index 271b196..d7ec179 100644 --- a/src/composables/game-state.ts +++ b/src/composables/game-state.ts @@ -17,7 +17,7 @@ export const operations = reactive([getEmptyOperation()]) export const plaquettes = ref([]) export const result = ref(0) -// #region Difficulty-related constants +// #region Difficulty-related values export const gameDifficulty = ref(GameDifficultyType.Normal) @@ -29,6 +29,10 @@ export const startingNumberOfPlaquettes = computed(() => gameDifficulty.value === GameDifficultyType.Hard ? 6 : 5, ) +export const isHardMode = computed( + () => gameDifficulty.value === GameDifficultyType.Hard, +) + // #endregion Difficulty-related constants export const currentOperation = computed( diff --git a/src/composables/sharing.ts b/src/composables/sharing.ts index 1495adc..effa098 100644 --- a/src/composables/sharing.ts +++ b/src/composables/sharing.ts @@ -1,54 +1,71 @@ import { i18n } from '@/i18n' import { percentageDiff, setDailyPRNG, shuffle } from '@/utils' -import { numberOfGamesSinceStart, operations, result } from './game-state' +import { + isHardMode, + numberOfGamesSinceStart, + operations, + plaquettes, + 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) + setDailyPRNG() + const baseSymbols = shuffle(['๐ŸŸข', '๐Ÿ”ด', '๐ŸŸ ', '๐ŸŸก', '๐ŸŸฃ', '๐Ÿ”ต']) + const resultSymbols = shuffle(['๐ŸŸฉ', '๐ŸŸฅ', '๐ŸŸง', '๐ŸŸจ', '๐ŸŸช', '๐ŸŸฆ']) + + for (const item of plaquettes.value) { + item.symbol = item.original ? baseSymbols.shift() : resultSymbols.pop() + } + // ร— รท + - const endResult = operations[operations.length - 1].result?.value ?? 0 - const lines: string[] = [] for (const op of operations) { - if (op.left && !op.left.symbol) { - op.left.symbol = op.left.original - ? squareSymbols.pop() - : roundSymbols.pop() + // let s = '' + // switch (op.operator) { + // case '*': + // s = 'โœ–' + // break + // case '/': + // s = 'โž—' + // break + // case '-': + // s = 'โž–' + // break + // case '+': + // s = 'โž•' + // break + // } + let s = '' + switch (op.operator) { + case '*': + s = 'ร—' + break + case '/': + s = 'รท' + break + case '-': + s = '-' + break + case '+': + s = '+' + break } - 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() - } - } - for (const op of operations) { lines.push( - `${op.left?.symbol} ${op.operator} ${op.right?.symbol} = ${op.result?.value === endResult ? endResult : op.result?.symbol}`, + `${op.left?.symbol} ${s} ${op.right?.symbol} = ${ + op.result?.value === endResult ? endResult : op.result?.symbol + }`, ) } - return `N0mbers #${numberOfGamesSinceStart()} - + return `N0mbers #${numberOfGamesSinceStart()} - ${isHardMode ? 'Advanced' : 'Normal'} ${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/views/GameView.vue b/src/views/GameView.vue index 2397b5b..8787e66 100644 --- a/src/views/GameView.vue +++ b/src/views/GameView.vue @@ -104,6 +104,7 @@ import { gameIsRunning, gameState, isEndGame, + isHardMode, isResultPerfect, operations, plaquettes, @@ -133,9 +134,6 @@ const { t } = useI18n() // call `useI18n`, and spread `t` from `useI18n` return const poolType = ref<1 | 2 | 3>(1) const cmpPlaquettes = ref | null>(null) -const isHardMode = computed( - () => gameDifficulty.value === GameDifficultyType.Hard, -) const isPracticeMode = ref(false) const shownPlaquettes = computed(() => gameIsRunning.value ? plaquettes.value : [],