diff --git a/src/data/common.tsx b/src/data/common.tsx index 9840520..b470b30 100644 --- a/src/data/common.tsx +++ b/src/data/common.tsx @@ -22,7 +22,7 @@ import { TreeNodeOptions } from "features/trees/tree"; import { Modifier } from "game/modifiers"; -import { Persistent, persistent } from "game/persistence"; +import { DefaultValue, Persistent, persistent } from "game/persistence"; import player from "game/player"; import Decimal, { DecimalSource, format } from "util/bignum"; import { WithRequired } from "util/common"; @@ -47,6 +47,7 @@ export interface ResetButtonOptions extends ClickableOptions { display?: Computable; canClick?: Computable; minimumGain?: Computable; + resetTime?: Persistent; } export type ResetButton = Replace< @@ -136,6 +137,9 @@ export function createResetButton; export function createAchievement( - optionsFunc?: OptionsFunc, BaseAchievement> + optionsFunc?: OptionsFunc ): Achievement { const earned = persistent(false); return createLazyProxy(() => { diff --git a/src/features/bars/bar.ts b/src/features/bars/bar.ts index ed9bac0..a26f55b 100644 --- a/src/features/bars/bar.ts +++ b/src/features/bars/bar.ts @@ -73,9 +73,7 @@ export type GenericBar = Replace< } >; -export function createBar( - optionsFunc: OptionsFunc, BaseBar> -): Bar { +export function createBar(optionsFunc: OptionsFunc): Bar { return createLazyProxy(() => { const bar = optionsFunc(); bar.id = getUniqueID("bar-"); diff --git a/src/features/boards/board.ts b/src/features/boards/board.ts index 8eefca0..d45f9fa 100644 --- a/src/features/boards/board.ts +++ b/src/features/boards/board.ts @@ -198,7 +198,7 @@ export type GenericBoard = Replace< >; export function createBoard( - optionsFunc: OptionsFunc, BaseBoard> + optionsFunc: OptionsFunc ): Board { return createLazyProxy( persistent => { diff --git a/src/features/buyable.tsx b/src/features/buyable.tsx index 1adcce5..af3265a 100644 --- a/src/features/buyable.tsx +++ b/src/features/buyable.tsx @@ -88,7 +88,7 @@ export type GenericBuyable = Replace< >; export function createBuyable( - optionsFunc: OptionsFunc, BaseBuyable> + optionsFunc: OptionsFunc ): Buyable { const amount = persistent(0); return createLazyProxy(() => { diff --git a/src/features/challenges/challenge.tsx b/src/features/challenges/challenge.tsx index 9cc6e40..0dc2509 100644 --- a/src/features/challenges/challenge.tsx +++ b/src/features/challenges/challenge.tsx @@ -97,7 +97,7 @@ export type GenericChallenge = Replace< >; export function createChallenge( - optionsFunc: OptionsFunc, BaseChallenge> + optionsFunc: OptionsFunc ): Challenge { const completions = persistent(0); const active = persistent(false); diff --git a/src/features/clickables/clickable.ts b/src/features/clickables/clickable.ts index 37b898e..72c180d 100644 --- a/src/features/clickables/clickable.ts +++ b/src/features/clickables/clickable.ts @@ -10,7 +10,7 @@ import { StyleValue, Visibility } from "features/feature"; -import { GenericLayer } from "game/layers"; +import { BaseLayer } from "game/layers"; import { Unsubscribe } from "nanoevents"; import { Computable, @@ -70,7 +70,7 @@ export type GenericClickable = Replace< >; export function createClickable( - optionsFunc?: OptionsFunc, BaseClickable> + optionsFunc?: OptionsFunc ): Clickable { return createLazyProxy(() => { const clickable = optionsFunc?.() ?? ({} as ReturnType>); @@ -136,7 +136,7 @@ export function createClickable( } export function setupAutoClick( - layer: GenericLayer, + layer: BaseLayer, clickable: GenericClickable, autoActive: Computable = true ): Unsubscribe { diff --git a/src/features/conversion.ts b/src/features/conversion.ts index f76de41..e8bfed9 100644 --- a/src/features/conversion.ts +++ b/src/features/conversion.ts @@ -1,4 +1,4 @@ -import { GenericLayer } from "game/layers"; +import { BaseLayer } from "game/layers"; import { Modifier } from "game/modifiers"; import Decimal, { DecimalSource } from "util/bignum"; import { WithRequired } from "util/common"; @@ -129,7 +129,7 @@ export type GenericConversion = Replace< * @see {@link createIndependentConversion}. */ export function createConversion( - optionsFunc: OptionsFunc, BaseConversion> + optionsFunc: OptionsFunc ): Conversion { return createLazyProxy(() => { const conversion = optionsFunc(); @@ -362,7 +362,7 @@ export function createPolynomialScaling( * @param optionsFunc Conversion options. */ export function createCumulativeConversion( - optionsFunc: OptionsFunc> + optionsFunc: OptionsFunc ): Conversion { return createConversion(optionsFunc); } @@ -373,7 +373,7 @@ export function createCumulativeConversion( * @param optionsFunc Converison options. */ export function createIndependentConversion( - optionsFunc: OptionsFunc> + optionsFunc: OptionsFunc ): Conversion { return createConversion(() => { const conversion: S = optionsFunc(); @@ -428,12 +428,12 @@ export function createIndependentConversion( * This will automatically increase the value of conversion.gainResource without lowering the value of the input resource. * It will by default perform 100% of a conversion's currentGain per second. * If you use a ref for the rate you can set it's value to 0 when passive generation should be disabled. - * @param layer The layer this passive generation will be associated with. + * @param layer The layer this passive generation will be associated with. Typically `this` when calling this function from inside a layer's options function. * @param conversion The conversion that will determine how much generation there is. * @param rate A multiplier to multiply against the conversion's currentGain. */ export function setupPassiveGeneration( - layer: GenericLayer, + layer: BaseLayer, conversion: GenericConversion, rate: Computable = 1 ): void { diff --git a/src/features/feature.ts b/src/features/feature.ts index 2a99351..2bc3ae6 100644 --- a/src/features/feature.ts +++ b/src/features/feature.ts @@ -41,7 +41,7 @@ export type Replace = S & Omit; * with "this" bound to what the type will eventually be processed into. * Intended for making lazily evaluated objects. */ -export type OptionsFunc> = () => T & ThisType & Partial; +export type OptionsFunc> = () => T & Partial; let id = 0; /** diff --git a/src/features/grids/grid.ts b/src/features/grids/grid.ts index 114b0d0..cc1b805 100644 --- a/src/features/grids/grid.ts +++ b/src/features/grids/grid.ts @@ -242,9 +242,7 @@ export type GenericGrid = Replace< } >; -export function createGrid( - optionsFunc: OptionsFunc, BaseGrid> -): Grid { +export function createGrid(optionsFunc: OptionsFunc): Grid { const cellState = persistent>({}); return createLazyProxy(() => { const grid = optionsFunc(); diff --git a/src/features/hotkey.tsx b/src/features/hotkey.tsx index 5714512..5012b68 100644 --- a/src/features/hotkey.tsx +++ b/src/features/hotkey.tsx @@ -43,7 +43,7 @@ export type GenericHotkey = Replace< >; export function createHotkey( - optionsFunc: OptionsFunc, BaseHotkey> + optionsFunc: OptionsFunc ): Hotkey { return createLazyProxy(() => { const hotkey = optionsFunc(); diff --git a/src/features/infoboxes/infobox.ts b/src/features/infoboxes/infobox.ts index 5f4087e..20f4526 100644 --- a/src/features/infoboxes/infobox.ts +++ b/src/features/infoboxes/infobox.ts @@ -64,7 +64,7 @@ export type GenericInfobox = Replace< >; export function createInfobox( - optionsFunc: OptionsFunc, BaseInfobox> + optionsFunc: OptionsFunc ): Infobox { const collapsed = persistent(false); return createLazyProxy(() => { diff --git a/src/features/links/links.ts b/src/features/links/links.ts index ea100f4..eb8ba84 100644 --- a/src/features/links/links.ts +++ b/src/features/links/links.ts @@ -44,7 +44,7 @@ export type GenericLinks = Replace< >; export function createLinks( - optionsFunc: OptionsFunc, BaseLinks> + optionsFunc: OptionsFunc ): Links { return createLazyProxy(() => { const links = optionsFunc(); diff --git a/src/features/milestones/milestone.tsx b/src/features/milestones/milestone.tsx index 879a253..461b004 100644 --- a/src/features/milestones/milestone.tsx +++ b/src/features/milestones/milestone.tsx @@ -84,7 +84,7 @@ export type GenericMilestone = Replace< >; export function createMilestone( - optionsFunc?: OptionsFunc, BaseMilestone> + optionsFunc?: OptionsFunc ): Milestone { const earned = persistent(false); return createLazyProxy(() => { diff --git a/src/features/particles/particles.tsx b/src/features/particles/particles.tsx index 345191b..2bb2ae3 100644 --- a/src/features/particles/particles.tsx +++ b/src/features/particles/particles.tsx @@ -42,7 +42,7 @@ export type Particles = Replace< export type GenericParticles = Particles; export function createParticles( - optionsFunc?: OptionsFunc, BaseParticles> + optionsFunc?: OptionsFunc ): Particles { return createLazyProxy(() => { const particles = optionsFunc?.() ?? ({} as ReturnType>); diff --git a/src/features/reset.ts b/src/features/reset.ts index af0659a..cbc981d 100644 --- a/src/features/reset.ts +++ b/src/features/reset.ts @@ -1,6 +1,6 @@ import { OptionsFunc, getUniqueID, Replace } from "features/feature"; import { globalBus } from "game/events"; -import { GenericLayer } from "game/layers"; +import { BaseLayer } from "game/layers"; import { DefaultValue, Persistent, persistent, PersistentState } from "game/persistence"; import Decimal from "util/bignum"; import { Computable, GetComputableType, processComputable } from "util/computed"; @@ -31,7 +31,7 @@ export type Reset = Replace< export type GenericReset = Reset; export function createReset( - optionsFunc: OptionsFunc, BaseReset> + optionsFunc: OptionsFunc ): Reset { return createLazyProxy(() => { const reset = optionsFunc(); @@ -64,7 +64,7 @@ export function createReset( } const listeners: Record = {}; -export function trackResetTime(layer: GenericLayer, reset: GenericReset): Persistent { +export function trackResetTime(layer: BaseLayer, reset: GenericReset): Persistent { const resetTime = persistent(new Decimal(0)); listeners[layer.id] = layer.on("preUpdate", diff => { resetTime.value = Decimal.add(resetTime.value, diff); diff --git a/src/features/tabs/tab.ts b/src/features/tabs/tab.ts index 0993a85..98bd586 100644 --- a/src/features/tabs/tab.ts +++ b/src/features/tabs/tab.ts @@ -37,9 +37,7 @@ export type Tab = Replace< export type GenericTab = Tab; -export function createTab( - optionsFunc: OptionsFunc, BaseTab> -): Tab { +export function createTab(optionsFunc: OptionsFunc): Tab { return createLazyProxy(() => { const tab = optionsFunc(); tab.id = getUniqueID("tab-"); diff --git a/src/features/tabs/tabFamily.ts b/src/features/tabs/tabFamily.ts index 2a4f332..7025c46 100644 --- a/src/features/tabs/tabFamily.ts +++ b/src/features/tabs/tabFamily.ts @@ -92,7 +92,7 @@ export type GenericTabFamily = Replace< export function createTabFamily( tabs: Record TabButtonOptions>, - optionsFunc?: OptionsFunc, BaseTabFamily> + optionsFunc?: OptionsFunc ): TabFamily { if (Object.keys(tabs).length === 0) { console.warn("Cannot create tab family with 0 tabs"); diff --git a/src/features/trees/tree.ts b/src/features/trees/tree.ts index 459a392..b52170a 100644 --- a/src/features/trees/tree.ts +++ b/src/features/trees/tree.ts @@ -73,7 +73,7 @@ export type GenericTreeNode = Replace< >; export function createTreeNode( - optionsFunc?: OptionsFunc, BaseTreeNode> + optionsFunc?: OptionsFunc ): TreeNode { return createLazyProxy(() => { const treeNode = optionsFunc?.() ?? ({} as ReturnType>); @@ -186,9 +186,7 @@ export type GenericTree = Replace< } >; -export function createTree( - optionsFunc: OptionsFunc, BaseTree> -): Tree { +export function createTree(optionsFunc: OptionsFunc): Tree { return createLazyProxy(() => { const tree = optionsFunc(); tree.id = getUniqueID("tree-"); diff --git a/src/features/upgrades/upgrade.ts b/src/features/upgrades/upgrade.ts index a27ec65..4c214bc 100644 --- a/src/features/upgrades/upgrade.ts +++ b/src/features/upgrades/upgrade.ts @@ -79,7 +79,7 @@ export type GenericUpgrade = Replace< >; export function createUpgrade( - optionsFunc: OptionsFunc, BaseUpgrade> + optionsFunc: OptionsFunc ): Upgrade { const bought = persistent(false); return createLazyProxy(() => { diff --git a/src/game/layers.tsx b/src/game/layers.tsx index 605eb69..dd71801 100644 --- a/src/game/layers.tsx +++ b/src/game/layers.tsx @@ -1,13 +1,13 @@ import Modal from "components/Modal.vue"; import { CoercableComponent, - OptionsFunc, jsx, JSXFunction, Replace, setDefault, StyleValue } from "features/feature"; +import { createNanoEvents, Emitter } from "nanoevents"; import { Computable, GetComputableType, @@ -16,7 +16,6 @@ import { ProcessedComputable } from "util/computed"; import { createLazyProxy } from "util/proxies"; -import { createNanoEvents, Emitter } from "nanoevents"; import { InjectionKey, Ref, ref, shallowReactive, unref } from "vue"; import { globalBus } from "./events"; import { Persistent, persistent } from "./persistence"; @@ -106,7 +105,7 @@ export const persistentRefs: Record> = {}; export const addingLayers: string[] = []; export function createLayer( id: string, - optionsFunc: OptionsFunc + optionsFunc: (this: BaseLayer) => T & Partial ): Layer { return createLazyProxy(() => { const layer = {} as T & Partial; @@ -119,7 +118,7 @@ export function createLayer( addingLayers.push(id); persistentRefs[id] = new Set(); layer.minimized = persistent(false); - Object.assign(layer, optionsFunc.call(layer)); + Object.assign(layer, optionsFunc.call(layer as BaseLayer)); if ( addingLayers[addingLayers.length - 1] == null || addingLayers[addingLayers.length - 1] !== id