Made resetTime more useful and various setup functions use BaseLayer
This commit is contained in:
parent
5b62080786
commit
d123ed3feb
21 changed files with 37 additions and 42 deletions
|
@ -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<CoercableComponent>;
|
||||
canClick?: Computable<boolean>;
|
||||
minimumGain?: Computable<DecimalSource>;
|
||||
resetTime?: Persistent<DecimalSource>;
|
||||
}
|
||||
|
||||
export type ResetButton<T extends ResetButtonOptions> = Replace<
|
||||
|
@ -136,6 +137,9 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
|
|||
}
|
||||
resetButton.conversion.convert();
|
||||
resetButton.tree.reset(resetButton.treeNode);
|
||||
if (resetButton.resetTime) {
|
||||
resetButton.resetTime.value = resetButton.resetTime[DefaultValue];
|
||||
}
|
||||
onClick?.();
|
||||
};
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ export type GenericAchievement = Replace<
|
|||
>;
|
||||
|
||||
export function createAchievement<T extends AchievementOptions>(
|
||||
optionsFunc?: OptionsFunc<T, Achievement<T>, BaseAchievement>
|
||||
optionsFunc?: OptionsFunc<T, BaseAchievement>
|
||||
): Achievement<T> {
|
||||
const earned = persistent<boolean>(false);
|
||||
return createLazyProxy(() => {
|
||||
|
|
|
@ -73,9 +73,7 @@ export type GenericBar = Replace<
|
|||
}
|
||||
>;
|
||||
|
||||
export function createBar<T extends BarOptions>(
|
||||
optionsFunc: OptionsFunc<T, Bar<T>, BaseBar>
|
||||
): Bar<T> {
|
||||
export function createBar<T extends BarOptions>(optionsFunc: OptionsFunc<T, BaseBar>): Bar<T> {
|
||||
return createLazyProxy(() => {
|
||||
const bar = optionsFunc();
|
||||
bar.id = getUniqueID("bar-");
|
||||
|
|
|
@ -198,7 +198,7 @@ export type GenericBoard = Replace<
|
|||
>;
|
||||
|
||||
export function createBoard<T extends BoardOptions>(
|
||||
optionsFunc: OptionsFunc<T, Board<T>, BaseBoard>
|
||||
optionsFunc: OptionsFunc<T, BaseBoard>
|
||||
): Board<T> {
|
||||
return createLazyProxy(
|
||||
persistent => {
|
||||
|
|
|
@ -88,7 +88,7 @@ export type GenericBuyable = Replace<
|
|||
>;
|
||||
|
||||
export function createBuyable<T extends BuyableOptions>(
|
||||
optionsFunc: OptionsFunc<T, Buyable<T>, BaseBuyable>
|
||||
optionsFunc: OptionsFunc<T, BaseBuyable>
|
||||
): Buyable<T> {
|
||||
const amount = persistent<DecimalSource>(0);
|
||||
return createLazyProxy(() => {
|
||||
|
|
|
@ -97,7 +97,7 @@ export type GenericChallenge = Replace<
|
|||
>;
|
||||
|
||||
export function createChallenge<T extends ChallengeOptions>(
|
||||
optionsFunc: OptionsFunc<T, Challenge<T>, BaseChallenge>
|
||||
optionsFunc: OptionsFunc<T, BaseChallenge>
|
||||
): Challenge<T> {
|
||||
const completions = persistent(0);
|
||||
const active = persistent(false);
|
||||
|
|
|
@ -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<T extends ClickableOptions>(
|
||||
optionsFunc?: OptionsFunc<T, Clickable<T>, BaseClickable>
|
||||
optionsFunc?: OptionsFunc<T, BaseClickable>
|
||||
): Clickable<T> {
|
||||
return createLazyProxy(() => {
|
||||
const clickable = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
|
||||
|
@ -136,7 +136,7 @@ export function createClickable<T extends ClickableOptions>(
|
|||
}
|
||||
|
||||
export function setupAutoClick(
|
||||
layer: GenericLayer,
|
||||
layer: BaseLayer,
|
||||
clickable: GenericClickable,
|
||||
autoActive: Computable<boolean> = true
|
||||
): Unsubscribe {
|
||||
|
|
|
@ -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<T extends ConversionOptions>(
|
||||
optionsFunc: OptionsFunc<T, Conversion<T>, BaseConversion>
|
||||
optionsFunc: OptionsFunc<T, BaseConversion>
|
||||
): Conversion<T> {
|
||||
return createLazyProxy(() => {
|
||||
const conversion = optionsFunc();
|
||||
|
@ -362,7 +362,7 @@ export function createPolynomialScaling(
|
|||
* @param optionsFunc Conversion options.
|
||||
*/
|
||||
export function createCumulativeConversion<S extends ConversionOptions>(
|
||||
optionsFunc: OptionsFunc<S, Conversion<S>>
|
||||
optionsFunc: OptionsFunc<S, BaseConversion>
|
||||
): Conversion<S> {
|
||||
return createConversion(optionsFunc);
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ export function createCumulativeConversion<S extends ConversionOptions>(
|
|||
* @param optionsFunc Converison options.
|
||||
*/
|
||||
export function createIndependentConversion<S extends ConversionOptions>(
|
||||
optionsFunc: OptionsFunc<S, Conversion<S>>
|
||||
optionsFunc: OptionsFunc<S, BaseConversion>
|
||||
): Conversion<S> {
|
||||
return createConversion(() => {
|
||||
const conversion: S = optionsFunc();
|
||||
|
@ -428,12 +428,12 @@ export function createIndependentConversion<S extends ConversionOptions>(
|
|||
* 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<DecimalSource> = 1
|
||||
): void {
|
||||
|
|
|
@ -41,7 +41,7 @@ export type Replace<T, S> = S & Omit<T, keyof S>;
|
|||
* with "this" bound to what the type will eventually be processed into.
|
||||
* Intended for making lazily evaluated objects.
|
||||
*/
|
||||
export type OptionsFunc<T, S = T, R = Record<string, unknown>> = () => T & ThisType<S> & Partial<R>;
|
||||
export type OptionsFunc<T, R = Record<string, unknown>> = () => T & Partial<R>;
|
||||
|
||||
let id = 0;
|
||||
/**
|
||||
|
|
|
@ -242,9 +242,7 @@ export type GenericGrid = Replace<
|
|||
}
|
||||
>;
|
||||
|
||||
export function createGrid<T extends GridOptions>(
|
||||
optionsFunc: OptionsFunc<T, Grid<T>, BaseGrid>
|
||||
): Grid<T> {
|
||||
export function createGrid<T extends GridOptions>(optionsFunc: OptionsFunc<T, BaseGrid>): Grid<T> {
|
||||
const cellState = persistent<Record<string | number, State>>({});
|
||||
return createLazyProxy(() => {
|
||||
const grid = optionsFunc();
|
||||
|
|
|
@ -43,7 +43,7 @@ export type GenericHotkey = Replace<
|
|||
>;
|
||||
|
||||
export function createHotkey<T extends HotkeyOptions>(
|
||||
optionsFunc: OptionsFunc<T, Hotkey<T>, BaseHotkey>
|
||||
optionsFunc: OptionsFunc<T, BaseHotkey>
|
||||
): Hotkey<T> {
|
||||
return createLazyProxy(() => {
|
||||
const hotkey = optionsFunc();
|
||||
|
|
|
@ -64,7 +64,7 @@ export type GenericInfobox = Replace<
|
|||
>;
|
||||
|
||||
export function createInfobox<T extends InfoboxOptions>(
|
||||
optionsFunc: OptionsFunc<T, Infobox<T>, BaseInfobox>
|
||||
optionsFunc: OptionsFunc<T, BaseInfobox>
|
||||
): Infobox<T> {
|
||||
const collapsed = persistent<boolean>(false);
|
||||
return createLazyProxy(() => {
|
||||
|
|
|
@ -44,7 +44,7 @@ export type GenericLinks = Replace<
|
|||
>;
|
||||
|
||||
export function createLinks<T extends LinksOptions>(
|
||||
optionsFunc: OptionsFunc<T, Links<T>, BaseLinks>
|
||||
optionsFunc: OptionsFunc<T, BaseLinks>
|
||||
): Links<T> {
|
||||
return createLazyProxy(() => {
|
||||
const links = optionsFunc();
|
||||
|
|
|
@ -84,7 +84,7 @@ export type GenericMilestone = Replace<
|
|||
>;
|
||||
|
||||
export function createMilestone<T extends MilestoneOptions>(
|
||||
optionsFunc?: OptionsFunc<T, Milestone<T>, BaseMilestone>
|
||||
optionsFunc?: OptionsFunc<T, BaseMilestone>
|
||||
): Milestone<T> {
|
||||
const earned = persistent<boolean>(false);
|
||||
return createLazyProxy(() => {
|
||||
|
|
|
@ -42,7 +42,7 @@ export type Particles<T extends ParticlesOptions> = Replace<
|
|||
export type GenericParticles = Particles<ParticlesOptions>;
|
||||
|
||||
export function createParticles<T extends ParticlesOptions>(
|
||||
optionsFunc?: OptionsFunc<T, Particles<T>, BaseParticles>
|
||||
optionsFunc?: OptionsFunc<T, BaseParticles>
|
||||
): Particles<T> {
|
||||
return createLazyProxy(() => {
|
||||
const particles = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
|
||||
|
|
|
@ -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<T extends ResetOptions> = Replace<
|
|||
export type GenericReset = Reset<ResetOptions>;
|
||||
|
||||
export function createReset<T extends ResetOptions>(
|
||||
optionsFunc: OptionsFunc<T, Reset<T>, BaseReset>
|
||||
optionsFunc: OptionsFunc<T, BaseReset>
|
||||
): Reset<T> {
|
||||
return createLazyProxy(() => {
|
||||
const reset = optionsFunc();
|
||||
|
@ -64,7 +64,7 @@ export function createReset<T extends ResetOptions>(
|
|||
}
|
||||
|
||||
const listeners: Record<string, Unsubscribe | undefined> = {};
|
||||
export function trackResetTime(layer: GenericLayer, reset: GenericReset): Persistent<Decimal> {
|
||||
export function trackResetTime(layer: BaseLayer, reset: GenericReset): Persistent<Decimal> {
|
||||
const resetTime = persistent<Decimal>(new Decimal(0));
|
||||
listeners[layer.id] = layer.on("preUpdate", diff => {
|
||||
resetTime.value = Decimal.add(resetTime.value, diff);
|
||||
|
|
|
@ -37,9 +37,7 @@ export type Tab<T extends TabOptions> = Replace<
|
|||
|
||||
export type GenericTab = Tab<TabOptions>;
|
||||
|
||||
export function createTab<T extends TabOptions>(
|
||||
optionsFunc: OptionsFunc<T, Tab<T>, BaseTab>
|
||||
): Tab<T> {
|
||||
export function createTab<T extends TabOptions>(optionsFunc: OptionsFunc<T, BaseTab>): Tab<T> {
|
||||
return createLazyProxy(() => {
|
||||
const tab = optionsFunc();
|
||||
tab.id = getUniqueID("tab-");
|
||||
|
|
|
@ -92,7 +92,7 @@ export type GenericTabFamily = Replace<
|
|||
|
||||
export function createTabFamily<T extends TabFamilyOptions>(
|
||||
tabs: Record<string, () => TabButtonOptions>,
|
||||
optionsFunc?: OptionsFunc<T, TabFamily<T>, BaseTabFamily>
|
||||
optionsFunc?: OptionsFunc<T, BaseTabFamily>
|
||||
): TabFamily<T> {
|
||||
if (Object.keys(tabs).length === 0) {
|
||||
console.warn("Cannot create tab family with 0 tabs");
|
||||
|
|
|
@ -73,7 +73,7 @@ export type GenericTreeNode = Replace<
|
|||
>;
|
||||
|
||||
export function createTreeNode<T extends TreeNodeOptions>(
|
||||
optionsFunc?: OptionsFunc<T, TreeNode<T>, BaseTreeNode>
|
||||
optionsFunc?: OptionsFunc<T, BaseTreeNode>
|
||||
): TreeNode<T> {
|
||||
return createLazyProxy(() => {
|
||||
const treeNode = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
|
||||
|
@ -186,9 +186,7 @@ export type GenericTree = Replace<
|
|||
}
|
||||
>;
|
||||
|
||||
export function createTree<T extends TreeOptions>(
|
||||
optionsFunc: OptionsFunc<T, Tree<T>, BaseTree>
|
||||
): Tree<T> {
|
||||
export function createTree<T extends TreeOptions>(optionsFunc: OptionsFunc<T, BaseTree>): Tree<T> {
|
||||
return createLazyProxy(() => {
|
||||
const tree = optionsFunc();
|
||||
tree.id = getUniqueID("tree-");
|
||||
|
|
|
@ -79,7 +79,7 @@ export type GenericUpgrade = Replace<
|
|||
>;
|
||||
|
||||
export function createUpgrade<T extends UpgradeOptions>(
|
||||
optionsFunc: OptionsFunc<T, Upgrade<T>, BaseUpgrade>
|
||||
optionsFunc: OptionsFunc<T, BaseUpgrade>
|
||||
): Upgrade<T> {
|
||||
const bought = persistent<boolean>(false);
|
||||
return createLazyProxy(() => {
|
||||
|
|
|
@ -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<string, Set<Persistent>> = {};
|
|||
export const addingLayers: string[] = [];
|
||||
export function createLayer<T extends LayerOptions>(
|
||||
id: string,
|
||||
optionsFunc: OptionsFunc<T, BaseLayer, BaseLayer>
|
||||
optionsFunc: (this: BaseLayer) => T & Partial<BaseLayer>
|
||||
): Layer<T> {
|
||||
return createLazyProxy(() => {
|
||||
const layer = {} as T & Partial<BaseLayer>;
|
||||
|
@ -119,7 +118,7 @@ export function createLayer<T extends LayerOptions>(
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue