Improved sharing
This commit is contained in:
parent
5ef3abb66e
commit
cada72746a
|
@ -17,7 +17,7 @@ export const operations = reactive<Operation[]>([getEmptyOperation()])
|
||||||
export const plaquettes = ref<Plaquette[]>([])
|
export const plaquettes = ref<Plaquette[]>([])
|
||||||
export const result = ref(0)
|
export const result = ref(0)
|
||||||
|
|
||||||
// #region Difficulty-related constants
|
// #region Difficulty-related values
|
||||||
|
|
||||||
export const gameDifficulty = ref(GameDifficultyType.Normal)
|
export const gameDifficulty = ref(GameDifficultyType.Normal)
|
||||||
|
|
||||||
|
@ -29,6 +29,10 @@ export const startingNumberOfPlaquettes = computed(() =>
|
||||||
gameDifficulty.value === GameDifficultyType.Hard ? 6 : 5,
|
gameDifficulty.value === GameDifficultyType.Hard ? 6 : 5,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const isHardMode = computed(
|
||||||
|
() => gameDifficulty.value === GameDifficultyType.Hard,
|
||||||
|
)
|
||||||
|
|
||||||
// #endregion Difficulty-related constants
|
// #endregion Difficulty-related constants
|
||||||
|
|
||||||
export const currentOperation = computed(
|
export const currentOperation = computed(
|
||||||
|
|
|
@ -1,54 +1,71 @@
|
||||||
import { i18n } from '@/i18n'
|
import { i18n } from '@/i18n'
|
||||||
import { percentageDiff, setDailyPRNG, shuffle } from '@/utils'
|
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'
|
import { showToast } from './toast-manager'
|
||||||
|
|
||||||
const squareSymbols = ['🟦', '🟨', '🟫', '🟧', '🟥', '🟩', '🟪']
|
|
||||||
const roundSymbols = ['🔵', '🟡', '🟤', '🟠', '🔴', '🟢', '🟣']
|
|
||||||
|
|
||||||
export function shuffleSymbols(): void {
|
|
||||||
setDailyPRNG()
|
|
||||||
shuffle(squareSymbols)
|
|
||||||
shuffle(roundSymbols)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSharingText(): string {
|
function getSharingText(): string {
|
||||||
console.log(squareSymbols)
|
setDailyPRNG()
|
||||||
console.log(roundSymbols)
|
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 lines: string[] = []
|
const lines: string[] = []
|
||||||
for (const op of operations) {
|
for (const op of operations) {
|
||||||
if (op.left && !op.left.symbol) {
|
// let s = ''
|
||||||
op.left.symbol = op.left.original
|
// switch (op.operator) {
|
||||||
? squareSymbols.pop()
|
// case '*':
|
||||||
: roundSymbols.pop()
|
// 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(
|
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 ? '✔' : '❌'}
|
${lines.join('\n')} ${result.value === endResult ? '✔' : '❌'}
|
||||||
|
|
||||||
https://n0mbers.scambier.xyz`
|
https://n0mbers.scambier.xyz`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toClipboard(): void {
|
export function toClipboard(): void {
|
||||||
navigator.clipboard.writeText(getSharingText())
|
navigator.clipboard.writeText(getSharingText())
|
||||||
showToast(i18n.global.t('copiedInClipboard'), 3000)
|
showToast(i18n.global.t('copiedInClipboard'), 3000)
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ import {
|
||||||
gameIsRunning,
|
gameIsRunning,
|
||||||
gameState,
|
gameState,
|
||||||
isEndGame,
|
isEndGame,
|
||||||
|
isHardMode,
|
||||||
isResultPerfect,
|
isResultPerfect,
|
||||||
operations,
|
operations,
|
||||||
plaquettes,
|
plaquettes,
|
||||||
|
@ -133,9 +134,6 @@ const { t } = useI18n() // call `useI18n`, and spread `t` from `useI18n` return
|
||||||
const poolType = ref<1 | 2 | 3>(1)
|
const poolType = ref<1 | 2 | 3>(1)
|
||||||
const cmpPlaquettes = ref<InstanceType<typeof PlaquettesList> | null>(null)
|
const cmpPlaquettes = ref<InstanceType<typeof PlaquettesList> | null>(null)
|
||||||
|
|
||||||
const isHardMode = computed(
|
|
||||||
() => gameDifficulty.value === GameDifficultyType.Hard,
|
|
||||||
)
|
|
||||||
const isPracticeMode = ref(false)
|
const isPracticeMode = ref(false)
|
||||||
const shownPlaquettes = computed(() =>
|
const shownPlaquettes = computed(() =>
|
||||||
gameIsRunning.value ? plaquettes.value : [],
|
gameIsRunning.value ? plaquettes.value : [],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user