diff --git a/src/data/layers/prestige.tsx b/src/data/layers/prestige.tsx index 69ad85f..0dfdaff 100644 --- a/src/data/layers/prestige.tsx +++ b/src/data/layers/prestige.tsx @@ -9,7 +9,7 @@ import { createReset } from "features/reset"; import MainDisplay from "features/resources/MainDisplay.vue"; import { createResource } from "features/resources/resource"; import { createLayer } from "game/layers"; -import { DecimalSource } from "lib/break_eternity"; +import { DecimalSource } from "util/bignum"; import { render } from "util/vue"; import { createLayerTreeNode, createResetButton } from "../common"; diff --git a/src/data/projEntry.tsx b/src/data/projEntry.tsx index c9a00b9..c004a87 100644 --- a/src/data/projEntry.tsx +++ b/src/data/projEntry.tsx @@ -5,8 +5,7 @@ import { branchedResetPropagation, createTree, GenericTree } from "features/tree import { globalBus } from "game/events"; import { createLayer, GenericLayer } from "game/layers"; import player, { PlayerData } from "game/player"; -import { DecimalSource } from "lib/break_eternity"; -import Decimal, { format, formatTime } from "util/bignum"; +import Decimal, { DecimalSource, format, formatTime } from "util/bignum"; import { render } from "util/vue"; import { computed, toRaw } from "vue"; import prestige from "./layers/prestige"; diff --git a/src/features/bars/bar.ts b/src/features/bars/bar.ts index 36c3084..6bdb3e6 100644 --- a/src/features/bars/bar.ts +++ b/src/features/bars/bar.ts @@ -9,7 +9,7 @@ import { StyleValue, Visibility } from "features/feature"; -import { DecimalSource } from "lib/break_eternity"; +import { DecimalSource } from "util/bignum"; import { Computable, GetComputableType, diff --git a/src/features/boards/board.ts b/src/features/boards/board.ts index 3afcc87..8435b45 100644 --- a/src/features/boards/board.ts +++ b/src/features/boards/board.ts @@ -11,7 +11,6 @@ import { } from "features/feature"; import { globalBus } from "game/events"; import { State, Persistent, makePersistent, PersistentState } from "game/persistence"; -import Decimal, { DecimalSource } from "lib/break_eternity"; import { isFunction } from "util/common"; import { Computable, @@ -85,7 +84,7 @@ export interface NodeTypeOptions { actionDistance?: NodeComputable; onClick?: (node: BoardNode) => void; onDrop?: (node: BoardNode, otherNode: BoardNode) => void; - update?: (node: BoardNode, diff: DecimalSource) => void; + update?: (node: BoardNode, diff: number) => void; } export interface BaseNodeType { @@ -348,7 +347,7 @@ export function getUniqueNodeID(board: GenericBoard): number { const listeners: Record = {}; globalBus.on("addLayer", layer => { const boards: GenericBoard[] = findFeatures(layer, BoardType) as GenericBoard[]; - listeners[layer.id] = layer.on("postUpdate", (diff: Decimal) => { + listeners[layer.id] = layer.on("postUpdate", diff => { boards.forEach(board => { Object.values(board.types).forEach(type => type.nodes.value.forEach(node => type.update?.(node, diff)) diff --git a/src/features/conversion.ts b/src/features/conversion.ts index ef0d0e7..ebe8914 100644 --- a/src/features/conversion.ts +++ b/src/features/conversion.ts @@ -206,7 +206,7 @@ export function setupPassiveGeneration( conversion: GenericConversion, rate: ProcessedComputable = 1 ): void { - layer.on("preUpdate", (diff: Decimal) => { + layer.on("preUpdate", diff => { const currRate = isRef(rate) ? rate.value : rate; if (Decimal.neq(currRate, 0)) { conversion.gainResource.value = Decimal.add( diff --git a/src/features/reset.ts b/src/features/reset.ts index 9576e4e..082c7ca 100644 --- a/src/features/reset.ts +++ b/src/features/reset.ts @@ -8,7 +8,7 @@ import { PersistentRef, PersistentState } from "game/persistence"; -import Decimal from "lib/break_eternity"; +import Decimal from "util/bignum"; import { Computable, GetComputableType, processComputable } from "util/computed"; import { createLazyProxy } from "util/proxies"; import { Unsubscribe } from "nanoevents"; @@ -72,7 +72,7 @@ export function createReset( const listeners: Record = {}; export function trackResetTime(layer: GenericLayer, reset: GenericReset): PersistentRef { const resetTime = persistent(new Decimal(0)); - listeners[layer.id] = layer.on("preUpdate", (diff: Decimal) => { + listeners[layer.id] = layer.on("preUpdate", diff => { resetTime.value = Decimal.add(resetTime.value, diff); }); globalBus.on("reset", currentReset => { diff --git a/src/features/trees/tree.ts b/src/features/trees/tree.ts index 1a3743b..cc3f69d 100644 --- a/src/features/trees/tree.ts +++ b/src/features/trees/tree.ts @@ -14,8 +14,7 @@ import { displayResource, Resource } from "features/resources/resource"; import { Tooltip } from "features/tooltip"; import TreeComponent from "features/trees/Tree.vue"; import { persistent } from "game/persistence"; -import { DecimalSource, format } from "util/bignum"; -import Decimal, { formatWhole } from "util/break_eternity"; +import Decimal, { DecimalSource, format, formatWhole } from "util/bignum"; import { Computable, convertComputable, diff --git a/src/features/upgrades/Upgrade.vue b/src/features/upgrades/Upgrade.vue index acfdd38..f7dde0f 100644 --- a/src/features/upgrades/Upgrade.vue +++ b/src/features/upgrades/Upgrade.vue @@ -31,7 +31,7 @@ import MarkNode from "components/MarkNode.vue"; import { jsx, StyleValue, Visibility } from "features/feature"; import { displayResource, Resource } from "features/resources/resource"; import { GenericUpgrade } from "features/upgrades/upgrade"; -import { DecimalSource } from "lib/break_eternity"; +import { DecimalSource } from "util/bignum"; import { coerceComponent, isCoercableComponent, processedPropType, unwrapRef } from "util/vue"; import { Component, diff --git a/src/game/events.ts b/src/game/events.ts index 1b3fa1b..2a3c40e 100644 --- a/src/game/events.ts +++ b/src/game/events.ts @@ -1,5 +1,5 @@ import projInfo from "data/projInfo.json"; -import Decimal, { DecimalSource } from "util/bignum"; +import Decimal from "util/bignum"; import { createNanoEvents } from "nanoevents"; import { App, Ref } from "vue"; import { GenericLayer } from "./layers"; @@ -10,7 +10,7 @@ import state from "./state"; export interface GlobalEvents { addLayer: (layer: GenericLayer, saveData: Record) => void; removeLayer: (layer: GenericLayer) => void; - update: (diff: Decimal, trueDiff: number) => void; + update: (diff: number, trueDiff: number) => void; loadSettings: (settings: Partial) => void; setupVue: (vue: App) => void; } @@ -25,7 +25,7 @@ let hasWon: null | Ref = null; function update() { const now = Date.now(); - let diff: DecimalSource = (now - player.time) / 1e3; + let diff = (now - player.time) / 1e3; player.time = now; const trueDiff = diff; @@ -43,7 +43,7 @@ function update() { return; } - diff = new Decimal(diff).max(0); + diff = Math.max(diff, 0); if (player.devSpeed === 0) { return; @@ -52,14 +52,14 @@ function update() { // Add offline time if any if (player.offlineTime != undefined) { if (Decimal.gt(player.offlineTime, projInfo.offlineLimit * 3600)) { - player.offlineTime = new Decimal(projInfo.offlineLimit * 3600); + player.offlineTime = projInfo.offlineLimit * 3600; } if (Decimal.gt(player.offlineTime, 0) && player.devSpeed !== 0) { - const offlineDiff = Decimal.div(player.offlineTime, 10).max(diff); - player.offlineTime = Decimal.sub(player.offlineTime, offlineDiff); - diff = diff.add(offlineDiff); + const offlineDiff = Math.max(player.offlineTime / 10, diff); + player.offlineTime = player.offlineTime - offlineDiff; + diff += offlineDiff; } else if (player.devSpeed === 0) { - player.offlineTime = Decimal.add(player.offlineTime, diff); + player.offlineTime += diff; } if (!player.offlineProd || Decimal.lt(player.offlineTime, 0)) { player.offlineTime = null; @@ -67,18 +67,26 @@ function update() { } // Cap at max tick length - diff = Decimal.min(diff, projInfo.maxTickLength); + diff = Math.min(diff, projInfo.maxTickLength); // Apply dev speed if (player.devSpeed != undefined) { - diff = diff.times(player.devSpeed); + diff *= player.devSpeed; + } + + if (!Number.isFinite(diff)) { + diff = 1e308; } // Update - if (diff.eq(0)) { + if (Decimal.eq(diff, 0)) { return; } - player.timePlayed = Decimal.add(player.timePlayed, diff); + + player.timePlayed += diff; + if (!Number.isFinite(player.timePlayed)) { + player.timePlayed = 1e308; + } globalBus.emit("update", diff, trueDiff); if (settings.unthrottled) { diff --git a/src/game/layers.tsx b/src/game/layers.tsx index 57a4ba8..0698c0a 100644 --- a/src/game/layers.tsx +++ b/src/game/layers.tsx @@ -8,7 +8,6 @@ import { StyleValue } from "features/feature"; import { Link } from "features/links"; -import Decimal from "util/bignum"; import { Computable, GetComputableType, @@ -25,11 +24,11 @@ import player from "./player"; export interface LayerEvents { // Generation - preUpdate: (diff: Decimal) => void; + preUpdate: (diff: number) => void; // Actions (e.g. automation) - update: (diff: Decimal) => void; + update: (diff: number) => void; // Effects (e.g. milestones) - postUpdate: (diff: Decimal) => void; + postUpdate: (diff: number) => void; } export const layers: Record | undefined> = {}; diff --git a/src/game/player.ts b/src/game/player.ts index 13e67e2..7431c84 100644 --- a/src/game/player.ts +++ b/src/game/player.ts @@ -1,4 +1,4 @@ -import Decimal, { DecimalSource } from "util/bignum"; +import Decimal from "util/bignum"; import { isPlainObject } from "util/common"; import { ProxiedWithState, ProxyPath, ProxyState } from "util/proxies"; import { reactive, unref } from "vue"; @@ -6,14 +6,14 @@ import transientState from "./state"; export interface PlayerData { id: string; - devSpeed: DecimalSource | null; + devSpeed: number | null; name: string; tabs: Array; time: number; autosave: boolean; offlineProd: boolean; - offlineTime: DecimalSource | null; - timePlayed: DecimalSource; + offlineTime: number | null; + timePlayed: number; keepGoing: boolean; modID: string; modVersion: string; @@ -31,7 +31,7 @@ const state = reactive({ autosave: true, offlineProd: true, offlineTime: null, - timePlayed: new Decimal(0), + timePlayed: 0, keepGoing: false, modID: "", modVersion: "", diff --git a/src/main.ts b/src/main.ts index 5e8c305..5850628 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,7 @@ import { GenericLayer } from "./game/layers"; import { PlayerData } from "./game/player"; import { Settings } from "./game/settings"; import { Transient } from "./game/state"; -import Decimal, { DecimalSource } from "./lib/break_eternity"; +import Decimal, { DecimalSource } from "./util/bignum"; import { load } from "./util/save"; document.title = projInfo.title; diff --git a/src/util/save.ts b/src/util/save.ts index 0e7c33d..ea1305c 100644 --- a/src/util/save.ts +++ b/src/util/save.ts @@ -1,7 +1,6 @@ import projInfo from "data/projInfo.json"; import player, { Player, PlayerData, stringifySave } from "game/player"; import settings, { loadSettings } from "game/settings"; -import Decimal from "./bignum"; import { ProxyState } from "./proxies"; export function setupInitialStore(player: Partial = {}): Player { @@ -13,8 +12,8 @@ export function setupInitialStore(player: Partial = {}): Player { time: Date.now(), autosave: true, offlineProd: true, - offlineTime: new Decimal(0), - timePlayed: new Decimal(0), + offlineTime: 0, + timePlayed: 0, keepGoing: false, modID: projInfo.id, modVersion: projInfo.versionNumber, @@ -85,11 +84,8 @@ export async function loadSave(playerObj: Partial): Promise { playerObj = setupInitialStore(playerObj); if (playerObj.offlineProd && playerObj.time) { - if (playerObj.offlineTime == undefined) playerObj.offlineTime = new Decimal(0); - playerObj.offlineTime = Decimal.add( - playerObj.offlineTime, - (Date.now() - playerObj.time) / 1000 - ); + if (playerObj.offlineTime == undefined) playerObj.offlineTime = 0; + playerObj.offlineTime += (Date.now() - playerObj.time) / 1000; } playerObj.time = Date.now(); if (playerObj.modVersion !== projInfo.versionNumber) {