Skip to content

Commit

Permalink
Merge branch 'master' into cookies-v
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudonian authored Jan 14, 2025
2 parents ee804c7 + d8d045f commit d424651
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 108 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"eventemitter3": "^4.0.7",
"fast-mersenne-twister": "^1.0.3",
"i18next": "^22.4.9",
"localforage": "^1.10.0",
"lodash.clonedeepwith": "^4.5.0",
"lz-string": "^1.4.4",
"worker-timers": "^7.0.53",
Expand Down Expand Up @@ -40,7 +39,7 @@
"csslint:fix": "npx stylelint Synergism.css --fix",
"htmllint": "npx htmlhint index.html",
"build:esbuild": "npx esbuild src/Synergism.ts --bundle --minify --target=\"chrome58,firefox57,safari11,edge29\" --outfile=\"./dist/out.js\"",
"watch:esbuild": "npx esbuild src/Synergism.ts --bundle --minify --target=\"chrome58,firefox57,safari11,edge29\" --outfile=\"./dist/out.js\" --watch",
"watch:esbuild": "npx esbuild src/Synergism.ts --bundle --minify --target=\"chrome58,firefox57,safari11,edge29\" --outfile=\"./dist/out.js\" --watch --sourcemap",
"check:tsc": "npx -p typescript tsc",
"watch:tsc": "npx -p typescript tsc --watch",
"prepare": "husky install",
Expand Down
4 changes: 2 additions & 2 deletions src/Calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ export const timeWarp = async () => {

DOMCacheGetOrSet('offlineContainer').style.display = 'flex'
DOMCacheGetOrSet('offlineBlur').style.display = ''
await calculateOffline(timeUse)
calculateOffline(timeUse)
}

export const calculateOffline = async (forceTime = 0) => {
Expand Down Expand Up @@ -1565,7 +1565,7 @@ export const calculateOffline = async (forceTime = 0) => {
player.loadedNov13Vers = true
}

await saveSynergy()
saveSynergy()

updateTalismanInventory()
calculateObtainium()
Expand Down
8 changes: 6 additions & 2 deletions src/Corruptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import i18next from 'i18next'
import { DOMCacheGetOrSet } from './Cache/DOM'
import { DOMCacheGetOrSet, DOMCacheHas } from './Cache/DOM'
import { PCoinUpgradeEffects } from './PseudoCoinUpgrades'
import { format, player } from './Synergism'
import { IconSets } from './Themes'
Expand Down Expand Up @@ -141,6 +141,8 @@ export const corruptionDisplay = (index: number) => {
export const corruptionStatsUpdate = () => {
for (let i = 2; i <= 9; i++) {
// https://discord.com/channels/677271830838640680/706329553639047241/841749032841379901
if (!DOMCacheHas(`corrCurrent${i}`)) continue

const a = DOMCacheGetOrSet(`corrCurrent${i}`)
const b = DOMCacheGetOrSet(`corrNext${i}`)
a.textContent = format(player.usedCorruptions[i])
Expand Down Expand Up @@ -219,7 +221,6 @@ export const corruptionLoadoutTableCreate = () => {
const row = table.insertRow()
for (let j = 0; j <= corrCount; j++) {
const cell = row.insertCell()
cell.className = `test${j}`
if (j === 0) { // First column
if (i === 0) { // First row
cell.textContent = i18next.t('corruptions.loadoutTable.next')
Expand Down Expand Up @@ -272,6 +273,9 @@ export const corruptionLoadoutTableCreate = () => {
cell.appendChild(btn)
}
}

updateCorruptionLoadoutNames()
corruptionStatsUpdate()
}

export const corruptionLoadoutTableUpdate = (updateRow = 0) => {
Expand Down
4 changes: 2 additions & 2 deletions src/EventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ TODO: Fix this entire tab it's utter shit
DOMCacheGetOrSet('getBlueberries').addEventListener('click', () => exportBlueberryTree())
DOMCacheGetOrSet('refundBlueberries').addEventListener('click', () => resetBlueberryTree())
// Import blueberries
DOMCacheGetOrSet('importBlueberries').addEventListener('change', async (e) => importData(e, importBlueberryTree))
DOMCacheGetOrSet('importBlueberries').addEventListener('change', (e) => importData(e, importBlueberryTree))

// Toggle subtabs of Singularity tab
for (let index = 0; index < 4; index++) {
Expand All @@ -1098,7 +1098,7 @@ TODO: Fix this entire tab it's utter shit
DOMCacheGetOrSet('unsmith').addEventListener('click', () => clickSmith())

// Import button
DOMCacheGetOrSet('importfile').addEventListener('change', async (e) => importData(e, importSynergism))
DOMCacheGetOrSet('importfile').addEventListener('change', (e) => importData(e, importSynergism))

for (let i = 1; i <= 5; i++) {
DOMCacheGetOrSet(`switchTheme${i}`).addEventListener('click', () => toggleTheme(false, i, true))
Expand Down
32 changes: 10 additions & 22 deletions src/ImportExport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ClipboardJS from 'clipboard'
import i18next from 'i18next'
import localforage from 'localforage'
import LZString from 'lz-string'
import { achievementaward } from './Achievements'
import { DOMCacheGetOrSet } from './Cache/DOM'
Expand All @@ -15,7 +14,7 @@ import { playerJsonSchema } from './saves/PlayerJsonSchema'
import { shopData } from './Shop'
import { singularityData } from './singularity'
import { synergismStage } from './Statistics'
import { blankSave, format, player, reloadShit, saveCheck, saveSynergy } from './Synergism'
import { blankSave, format, player, reloadShit, saveSynergy } from './Synergism'
import { changeSubTab, changeTab, Tabs } from './Tabs'
import type { Player } from './types/Synergism'
import { Alert, Confirm, Prompt } from './UpdateHTML'
Expand Down Expand Up @@ -248,8 +247,7 @@ export const exportSynergism = async (
: 1
if (+player.singularityUpgrades.goldenQuarks3.getEffect().bonus > 0) {
player.goldenQuarks += Math.floor(
player.goldenQuarksTimer
/ (3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus)
player.goldenQuarksTimer / (3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus)
) * bonusGQMultiplier
player.goldenQuarksTimer = player.goldenQuarksTimer
% (3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus)
Expand All @@ -260,17 +258,13 @@ export const exportSynergism = async (
}
}

const saved = await saveSynergy()

if (!saved) {
if (!saveSynergy()) {
return
}

const save = (await localforage.getItem<Blob>('Synergysave2'))
?? localStorage.getItem('Synergysave2')
const saveString = typeof save === 'string' ? save : await save?.text()
const saveString = localStorage.getItem('Synergysave2')

if (saveString === undefined) {
if (!saveString) {
return Alert('How?')
}

Expand Down Expand Up @@ -308,12 +302,12 @@ export const resetGame = async (force = true) => {
changeSubTab(Tabs.Singularity, { page: 0 }) // set 'singularity main'
changeSubTab(Tabs.Settings, { page: 0 }) // set 'statistics main'
// Import Game
await importSynergism(btoa(JSON.stringify(hold.data)), true)
importSynergism(btoa(JSON.stringify(hold.data)), true)
}

export const importData = async (
e: Event,
importFunc: (save: string | null) => Promise<void> | Promise<undefined>
importFunc: (save: string | null) => void
) => {
const element = e.target as HTMLInputElement
const file = element.files![0]
Expand All @@ -338,7 +332,7 @@ export const importData = async (
return importFunc(save)
}

export const importSynergism = async (input: string | null, reset = false) => {
export const importSynergism = (input: string | null, reset = false) => {
if (typeof input !== 'string') {
return Alert(i18next.t('importexport.unableImport'))
}
Expand All @@ -358,13 +352,9 @@ export const importSynergism = async (input: string | null, reset = false) => {
return Alert(i18next.t('importexport.unableImport'))
}

saveCheck.canSave = false
const item = new Blob([saveString], { type: 'text/plain' })
localStorage.setItem('Synergysave2', saveString)
await localforage.setItem<Blob>('Synergysave2', item)

await reloadShit(reset)
saveCheck.canSave = true
reloadShit(reset)
return
} else {
return Alert(i18next.t('importexport.loadTestInLive'))
Expand Down Expand Up @@ -975,9 +965,7 @@ export const promocodes = async (input: string | null, amount?: number) => {
el.textContent = i18next.t('importexport.promocodes.invalid')
}

const saved = await saveSynergy() // should fix refresh bug where you can continuously enter promocodes

if (!saved) {
if (!saveSynergy()) {
return
}

Expand Down
7 changes: 2 additions & 5 deletions src/Login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="@types/cloudflare-turnstile" />

import i18next from 'i18next'
import localforage from 'localforage'
import { DOMCacheGetOrSet } from './Cache/DOM'
import { importSynergism } from './ImportExport'
import { QuarkHandler, setQuarkBonus } from './Quark'
Expand Down Expand Up @@ -259,9 +258,7 @@ async function logout () {
}

async function saveToCloud () {
const save = (await localforage.getItem<Blob>('Synergysave2')
.then((b) => b?.text())
.catch(() => null)) ?? localStorage.getItem('Synergysave2')
const save = localStorage.getItem('Synergysave2')

if (typeof save !== 'string') {
console.log('Yeah, no save here.')
Expand All @@ -286,7 +283,7 @@ async function getCloudSave () {
const response = await fetch('https://synergism.cc/api/v1/saves/get')
const save = await response.json() as CloudSave

await importSynergism(save?.save ?? null)
importSynergism(save?.save ?? null)
}

const hasCaptcha = new WeakSet<HTMLElement>()
Expand Down
5 changes: 3 additions & 2 deletions src/Reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ export const updateSingularityGlobalPerks = () => {
}
}

// TODO(@KhafraDev): find way to make this sync
export const singularity = async (setSingNumber = -1): Promise<void> => {
if (player.runelevels[6] === 0 && setSingNumber === -1) {
return Alert(
Expand Down Expand Up @@ -1356,7 +1357,7 @@ export const singularity = async (setSingNumber = -1): Promise<void> => {
const saveCode47 = player.codes.get(47) ?? false
const saveCode48 = player.codes.get(48) ?? false

await importSynergism(btoa(JSON.stringify(hold)), true)
importSynergism(btoa(JSON.stringify(hold)), true)
// Techically possible to import game during reset. But that will only "hurt" that imported save

// TODO: Do not enable data that has never used an event code
Expand All @@ -1376,7 +1377,7 @@ export const singularity = async (setSingNumber = -1): Promise<void> => {
player.promoCodeTiming.time = Date.now()

// Save again at the end of singularity reset
void saveSynergy()
saveSynergy()
}

const resetUpgrades = (i: number) => {
Expand Down
Loading

0 comments on commit d424651

Please sign in to comment.