Converted variables that track time to numbers

This commit is contained in:
thepaperpilot 2022-03-11 14:02:41 -06:00
parent b33de01a96
commit e56f34c13c
13 changed files with 44 additions and 44 deletions

View file

@ -9,7 +9,7 @@ import { createReset } from "features/reset";
import MainDisplay from "features/resources/MainDisplay.vue"; import MainDisplay from "features/resources/MainDisplay.vue";
import { createResource } from "features/resources/resource"; import { createResource } from "features/resources/resource";
import { createLayer } from "game/layers"; import { createLayer } from "game/layers";
import { DecimalSource } from "lib/break_eternity"; import { DecimalSource } from "util/bignum";
import { render } from "util/vue"; import { render } from "util/vue";
import { createLayerTreeNode, createResetButton } from "../common"; import { createLayerTreeNode, createResetButton } from "../common";

View file

@ -5,8 +5,7 @@ import { branchedResetPropagation, createTree, GenericTree } from "features/tree
import { globalBus } from "game/events"; import { globalBus } from "game/events";
import { createLayer, GenericLayer } from "game/layers"; import { createLayer, GenericLayer } from "game/layers";
import player, { PlayerData } from "game/player"; import player, { PlayerData } from "game/player";
import { DecimalSource } from "lib/break_eternity"; import Decimal, { DecimalSource, format, formatTime } from "util/bignum";
import Decimal, { format, formatTime } from "util/bignum";
import { render } from "util/vue"; import { render } from "util/vue";
import { computed, toRaw } from "vue"; import { computed, toRaw } from "vue";
import prestige from "./layers/prestige"; import prestige from "./layers/prestige";

View file

@ -9,7 +9,7 @@ import {
StyleValue, StyleValue,
Visibility Visibility
} from "features/feature"; } from "features/feature";
import { DecimalSource } from "lib/break_eternity"; import { DecimalSource } from "util/bignum";
import { import {
Computable, Computable,
GetComputableType, GetComputableType,

View file

@ -11,7 +11,6 @@ import {
} from "features/feature"; } from "features/feature";
import { globalBus } from "game/events"; import { globalBus } from "game/events";
import { State, Persistent, makePersistent, PersistentState } from "game/persistence"; import { State, Persistent, makePersistent, PersistentState } from "game/persistence";
import Decimal, { DecimalSource } from "lib/break_eternity";
import { isFunction } from "util/common"; import { isFunction } from "util/common";
import { import {
Computable, Computable,
@ -85,7 +84,7 @@ export interface NodeTypeOptions {
actionDistance?: NodeComputable<number>; actionDistance?: NodeComputable<number>;
onClick?: (node: BoardNode) => void; onClick?: (node: BoardNode) => void;
onDrop?: (node: BoardNode, otherNode: BoardNode) => void; onDrop?: (node: BoardNode, otherNode: BoardNode) => void;
update?: (node: BoardNode, diff: DecimalSource) => void; update?: (node: BoardNode, diff: number) => void;
} }
export interface BaseNodeType { export interface BaseNodeType {
@ -348,7 +347,7 @@ export function getUniqueNodeID(board: GenericBoard): number {
const listeners: Record<string, Unsubscribe | undefined> = {}; const listeners: Record<string, Unsubscribe | undefined> = {};
globalBus.on("addLayer", layer => { globalBus.on("addLayer", layer => {
const boards: GenericBoard[] = findFeatures(layer, BoardType) as GenericBoard[]; 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 => { boards.forEach(board => {
Object.values(board.types).forEach(type => Object.values(board.types).forEach(type =>
type.nodes.value.forEach(node => type.update?.(node, diff)) type.nodes.value.forEach(node => type.update?.(node, diff))

View file

@ -206,7 +206,7 @@ export function setupPassiveGeneration(
conversion: GenericConversion, conversion: GenericConversion,
rate: ProcessedComputable<DecimalSource> = 1 rate: ProcessedComputable<DecimalSource> = 1
): void { ): void {
layer.on("preUpdate", (diff: Decimal) => { layer.on("preUpdate", diff => {
const currRate = isRef(rate) ? rate.value : rate; const currRate = isRef(rate) ? rate.value : rate;
if (Decimal.neq(currRate, 0)) { if (Decimal.neq(currRate, 0)) {
conversion.gainResource.value = Decimal.add( conversion.gainResource.value = Decimal.add(

View file

@ -8,7 +8,7 @@ import {
PersistentRef, PersistentRef,
PersistentState PersistentState
} from "game/persistence"; } from "game/persistence";
import Decimal from "lib/break_eternity"; import Decimal from "util/bignum";
import { Computable, GetComputableType, processComputable } from "util/computed"; import { Computable, GetComputableType, processComputable } from "util/computed";
import { createLazyProxy } from "util/proxies"; import { createLazyProxy } from "util/proxies";
import { Unsubscribe } from "nanoevents"; import { Unsubscribe } from "nanoevents";
@ -72,7 +72,7 @@ export function createReset<T extends ResetOptions>(
const listeners: Record<string, Unsubscribe | undefined> = {}; const listeners: Record<string, Unsubscribe | undefined> = {};
export function trackResetTime(layer: GenericLayer, reset: GenericReset): PersistentRef<Decimal> { export function trackResetTime(layer: GenericLayer, reset: GenericReset): PersistentRef<Decimal> {
const resetTime = persistent<Decimal>(new Decimal(0)); const resetTime = persistent<Decimal>(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); resetTime.value = Decimal.add(resetTime.value, diff);
}); });
globalBus.on("reset", currentReset => { globalBus.on("reset", currentReset => {

View file

@ -14,8 +14,7 @@ import { displayResource, Resource } from "features/resources/resource";
import { Tooltip } from "features/tooltip"; import { Tooltip } from "features/tooltip";
import TreeComponent from "features/trees/Tree.vue"; import TreeComponent from "features/trees/Tree.vue";
import { persistent } from "game/persistence"; import { persistent } from "game/persistence";
import { DecimalSource, format } from "util/bignum"; import Decimal, { DecimalSource, format, formatWhole } from "util/bignum";
import Decimal, { formatWhole } from "util/break_eternity";
import { import {
Computable, Computable,
convertComputable, convertComputable,

View file

@ -31,7 +31,7 @@ import MarkNode from "components/MarkNode.vue";
import { jsx, StyleValue, Visibility } from "features/feature"; import { jsx, StyleValue, Visibility } from "features/feature";
import { displayResource, Resource } from "features/resources/resource"; import { displayResource, Resource } from "features/resources/resource";
import { GenericUpgrade } from "features/upgrades/upgrade"; 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 { coerceComponent, isCoercableComponent, processedPropType, unwrapRef } from "util/vue";
import { import {
Component, Component,

View file

@ -1,5 +1,5 @@
import projInfo from "data/projInfo.json"; import projInfo from "data/projInfo.json";
import Decimal, { DecimalSource } from "util/bignum"; import Decimal from "util/bignum";
import { createNanoEvents } from "nanoevents"; import { createNanoEvents } from "nanoevents";
import { App, Ref } from "vue"; import { App, Ref } from "vue";
import { GenericLayer } from "./layers"; import { GenericLayer } from "./layers";
@ -10,7 +10,7 @@ import state from "./state";
export interface GlobalEvents { export interface GlobalEvents {
addLayer: (layer: GenericLayer, saveData: Record<string, unknown>) => void; addLayer: (layer: GenericLayer, saveData: Record<string, unknown>) => void;
removeLayer: (layer: GenericLayer) => void; removeLayer: (layer: GenericLayer) => void;
update: (diff: Decimal, trueDiff: number) => void; update: (diff: number, trueDiff: number) => void;
loadSettings: (settings: Partial<Settings>) => void; loadSettings: (settings: Partial<Settings>) => void;
setupVue: (vue: App) => void; setupVue: (vue: App) => void;
} }
@ -25,7 +25,7 @@ let hasWon: null | Ref<boolean> = null;
function update() { function update() {
const now = Date.now(); const now = Date.now();
let diff: DecimalSource = (now - player.time) / 1e3; let diff = (now - player.time) / 1e3;
player.time = now; player.time = now;
const trueDiff = diff; const trueDiff = diff;
@ -43,7 +43,7 @@ function update() {
return; return;
} }
diff = new Decimal(diff).max(0); diff = Math.max(diff, 0);
if (player.devSpeed === 0) { if (player.devSpeed === 0) {
return; return;
@ -52,14 +52,14 @@ function update() {
// Add offline time if any // Add offline time if any
if (player.offlineTime != undefined) { if (player.offlineTime != undefined) {
if (Decimal.gt(player.offlineTime, projInfo.offlineLimit * 3600)) { 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) { if (Decimal.gt(player.offlineTime, 0) && player.devSpeed !== 0) {
const offlineDiff = Decimal.div(player.offlineTime, 10).max(diff); const offlineDiff = Math.max(player.offlineTime / 10, diff);
player.offlineTime = Decimal.sub(player.offlineTime, offlineDiff); player.offlineTime = player.offlineTime - offlineDiff;
diff = diff.add(offlineDiff); diff += offlineDiff;
} else if (player.devSpeed === 0) { } else if (player.devSpeed === 0) {
player.offlineTime = Decimal.add(player.offlineTime, diff); player.offlineTime += diff;
} }
if (!player.offlineProd || Decimal.lt(player.offlineTime, 0)) { if (!player.offlineProd || Decimal.lt(player.offlineTime, 0)) {
player.offlineTime = null; player.offlineTime = null;
@ -67,18 +67,26 @@ function update() {
} }
// Cap at max tick length // Cap at max tick length
diff = Decimal.min(diff, projInfo.maxTickLength); diff = Math.min(diff, projInfo.maxTickLength);
// Apply dev speed // Apply dev speed
if (player.devSpeed != undefined) { if (player.devSpeed != undefined) {
diff = diff.times(player.devSpeed); diff *= player.devSpeed;
}
if (!Number.isFinite(diff)) {
diff = 1e308;
} }
// Update // Update
if (diff.eq(0)) { if (Decimal.eq(diff, 0)) {
return; return;
} }
player.timePlayed = Decimal.add(player.timePlayed, diff);
player.timePlayed += diff;
if (!Number.isFinite(player.timePlayed)) {
player.timePlayed = 1e308;
}
globalBus.emit("update", diff, trueDiff); globalBus.emit("update", diff, trueDiff);
if (settings.unthrottled) { if (settings.unthrottled) {

View file

@ -8,7 +8,6 @@ import {
StyleValue StyleValue
} from "features/feature"; } from "features/feature";
import { Link } from "features/links"; import { Link } from "features/links";
import Decimal from "util/bignum";
import { import {
Computable, Computable,
GetComputableType, GetComputableType,
@ -25,11 +24,11 @@ import player from "./player";
export interface LayerEvents { export interface LayerEvents {
// Generation // Generation
preUpdate: (diff: Decimal) => void; preUpdate: (diff: number) => void;
// Actions (e.g. automation) // Actions (e.g. automation)
update: (diff: Decimal) => void; update: (diff: number) => void;
// Effects (e.g. milestones) // Effects (e.g. milestones)
postUpdate: (diff: Decimal) => void; postUpdate: (diff: number) => void;
} }
export const layers: Record<string, Readonly<GenericLayer> | undefined> = {}; export const layers: Record<string, Readonly<GenericLayer> | undefined> = {};

View file

@ -1,4 +1,4 @@
import Decimal, { DecimalSource } from "util/bignum"; import Decimal from "util/bignum";
import { isPlainObject } from "util/common"; import { isPlainObject } from "util/common";
import { ProxiedWithState, ProxyPath, ProxyState } from "util/proxies"; import { ProxiedWithState, ProxyPath, ProxyState } from "util/proxies";
import { reactive, unref } from "vue"; import { reactive, unref } from "vue";
@ -6,14 +6,14 @@ import transientState from "./state";
export interface PlayerData { export interface PlayerData {
id: string; id: string;
devSpeed: DecimalSource | null; devSpeed: number | null;
name: string; name: string;
tabs: Array<string>; tabs: Array<string>;
time: number; time: number;
autosave: boolean; autosave: boolean;
offlineProd: boolean; offlineProd: boolean;
offlineTime: DecimalSource | null; offlineTime: number | null;
timePlayed: DecimalSource; timePlayed: number;
keepGoing: boolean; keepGoing: boolean;
modID: string; modID: string;
modVersion: string; modVersion: string;
@ -31,7 +31,7 @@ const state = reactive<PlayerData>({
autosave: true, autosave: true,
offlineProd: true, offlineProd: true,
offlineTime: null, offlineTime: null,
timePlayed: new Decimal(0), timePlayed: 0,
keepGoing: false, keepGoing: false,
modID: "", modID: "",
modVersion: "", modVersion: "",

View file

@ -5,7 +5,7 @@ import { GenericLayer } from "./game/layers";
import { PlayerData } from "./game/player"; import { PlayerData } from "./game/player";
import { Settings } from "./game/settings"; import { Settings } from "./game/settings";
import { Transient } from "./game/state"; import { Transient } from "./game/state";
import Decimal, { DecimalSource } from "./lib/break_eternity"; import Decimal, { DecimalSource } from "./util/bignum";
import { load } from "./util/save"; import { load } from "./util/save";
document.title = projInfo.title; document.title = projInfo.title;

View file

@ -1,7 +1,6 @@
import projInfo from "data/projInfo.json"; import projInfo from "data/projInfo.json";
import player, { Player, PlayerData, stringifySave } from "game/player"; import player, { Player, PlayerData, stringifySave } from "game/player";
import settings, { loadSettings } from "game/settings"; import settings, { loadSettings } from "game/settings";
import Decimal from "./bignum";
import { ProxyState } from "./proxies"; import { ProxyState } from "./proxies";
export function setupInitialStore(player: Partial<PlayerData> = {}): Player { export function setupInitialStore(player: Partial<PlayerData> = {}): Player {
@ -13,8 +12,8 @@ export function setupInitialStore(player: Partial<PlayerData> = {}): Player {
time: Date.now(), time: Date.now(),
autosave: true, autosave: true,
offlineProd: true, offlineProd: true,
offlineTime: new Decimal(0), offlineTime: 0,
timePlayed: new Decimal(0), timePlayed: 0,
keepGoing: false, keepGoing: false,
modID: projInfo.id, modID: projInfo.id,
modVersion: projInfo.versionNumber, modVersion: projInfo.versionNumber,
@ -85,11 +84,8 @@ export async function loadSave(playerObj: Partial<PlayerData>): Promise<void> {
playerObj = setupInitialStore(playerObj); playerObj = setupInitialStore(playerObj);
if (playerObj.offlineProd && playerObj.time) { if (playerObj.offlineProd && playerObj.time) {
if (playerObj.offlineTime == undefined) playerObj.offlineTime = new Decimal(0); if (playerObj.offlineTime == undefined) playerObj.offlineTime = 0;
playerObj.offlineTime = Decimal.add( playerObj.offlineTime += (Date.now() - playerObj.time) / 1000;
playerObj.offlineTime,
(Date.now() - playerObj.time) / 1000
);
} }
playerObj.time = Date.now(); playerObj.time = Date.now();
if (playerObj.modVersion !== projInfo.versionNumber) { if (playerObj.modVersion !== projInfo.versionNumber) {