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