Cleaned up sharing

This commit is contained in:
Simon Cambier 2022-03-21 22:15:58 +01:00
parent fe831a6004
commit bbb7460723

View File

@ -1,43 +1,26 @@
import { i18n } from '@/i18n' import { i18n } from '@/i18n'
import { percentageDiff, setDailyPRNG, shuffle } from '@/utils'
import { import {
isHardMode, isHardMode,
numberOfGamesSinceStart, numberOfGamesSinceStart,
operations, operations,
plaquettes,
result, result,
} from './game-state' } from './game-state'
import { showToast } from './toast-manager' import { showToast } from './toast-manager'
function getSharingText(): string { function getSharingText(): string {
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 endResult = operations[operations.length - 1].result?.value ?? 0
const success = result.value === endResult
const allSymbols = ['🄰', '🄱', '🄲', '🄳', '🄴', '🄵', '🄶', '🄷', '🄸', '🄹']
const squares = ['🟦', '🟩', '🟨', '🟧', '🟥']
const lines: string[] = [] const lines: string[] = []
for (const op of operations) { for (const op of operations) {
// let s = '' op.left!.symbol = op.left!.symbol ?? allSymbols.shift()
// switch (op.operator) { op.right!.symbol = op.right!.symbol ?? allSymbols.shift()
// case '*': op.result!.symbol = op.result!.symbol ?? allSymbols.shift()
// s = '✖'
// break
// case '/':
// s = '➗'
// break
// case '-':
// s = ''
// break
// case '+':
// s = ''
// break
// }
let s = '' let s = ''
switch (op.operator) { switch (op.operator) {
case '*': case '*':
@ -47,21 +30,21 @@ function getSharingText(): string {
s = '÷' s = '÷'
break break
case '-': case '-':
s = '-' s = ''
break break
case '+': case '+':
s = '+' s = '+'
break break
} }
lines.push( lines.push(
`${op.left?.symbol} ${s} ${op.right?.symbol} = ${ `${squares.shift()} ${op.left?.symbol} ${s} ${op.right?.symbol} = ${
op.result?.value === endResult ? endResult : op.result?.symbol op.result?.value === endResult ? endResult : op.result?.symbol
}`, }`,
) )
} }
return `N0mbers #${numberOfGamesSinceStart()} - ${isHardMode.value ? 'Advanced' : 'Normal'} return `N0mbers #${numberOfGamesSinceStart()} - ${isHardMode.value ? 'Advanced' : 'Normal'}
${lines.join('\n')} ${result.value === endResult ? '✔' : '❌'} ${lines.join('\n')} ${success ? '✔' : '❌'}
https://n0mbers.scambier.xyz` https://n0mbers.scambier.xyz`
} }