forked from profectus/Profectus
Ran prettier
This commit is contained in:
parent
c9ca85978d
commit
98f18fef43
11 changed files with 139 additions and 55 deletions
|
@ -142,7 +142,10 @@ export function createAchievement<T extends AchievementOptions>(
|
|||
...decorators: GenericDecorator[]
|
||||
): Achievement<T> {
|
||||
const earned = persistent<boolean>(false, false);
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy(feature => {
|
||||
const achievement =
|
||||
optionsFunc?.call(feature, feature) ??
|
||||
|
@ -232,7 +235,10 @@ export function createAchievement<T extends AchievementOptions>(
|
|||
decorator.postConstruct?.(achievement);
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(achievement)), {});
|
||||
const decoratedProps = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getGatheredProps?.(achievement)),
|
||||
{}
|
||||
);
|
||||
achievement[GatherProps] = function (this: GenericAchievement) {
|
||||
const {
|
||||
visibility,
|
||||
|
|
|
@ -107,7 +107,10 @@ export function createAction<T extends ActionOptions>(
|
|||
...decorators: GenericDecorator[]
|
||||
): Action<T> {
|
||||
const progress = persistent<DecimalSource>(0);
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy(feature => {
|
||||
const action =
|
||||
optionsFunc?.call(feature, feature) ??
|
||||
|
@ -241,7 +244,9 @@ export function createAction<T extends ActionOptions>(
|
|||
decorator.postConstruct?.(action);
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(action)));
|
||||
const decoratedProps = decorators.reduce((current, next) =>
|
||||
Object.assign(current, next.getGatheredProps?.(action))
|
||||
);
|
||||
action[GatherProps] = function (this: GenericAction) {
|
||||
const {
|
||||
display,
|
||||
|
|
|
@ -105,7 +105,10 @@ export function createBar<T extends BarOptions>(
|
|||
optionsFunc: OptionsFunc<T, BaseBar, GenericBar>,
|
||||
...decorators: GenericDecorator[]
|
||||
): Bar<T> {
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy(feature => {
|
||||
const bar = optionsFunc.call(feature, feature);
|
||||
bar.id = getUniqueID("bar-");
|
||||
|
@ -137,7 +140,10 @@ export function createBar<T extends BarOptions>(
|
|||
decorator.postConstruct?.(bar);
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(bar)), {});
|
||||
const decoratedProps = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getGatheredProps?.(bar)),
|
||||
{}
|
||||
);
|
||||
bar[GatherProps] = function (this: GenericBar) {
|
||||
const {
|
||||
progress,
|
||||
|
|
|
@ -154,7 +154,10 @@ export function createChallenge<T extends ChallengeOptions>(
|
|||
): Challenge<T> {
|
||||
const completions = persistent(0);
|
||||
const active = persistent(false, false);
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy(feature => {
|
||||
const challenge = optionsFunc.call(feature, feature);
|
||||
|
||||
|
@ -271,7 +274,10 @@ export function createChallenge<T extends ChallengeOptions>(
|
|||
decorator.postConstruct?.(challenge);
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(challenge)), {});
|
||||
const decoratedProps = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getGatheredProps?.(challenge)),
|
||||
{}
|
||||
);
|
||||
challenge[GatherProps] = function (this: GenericChallenge) {
|
||||
const {
|
||||
active,
|
||||
|
|
|
@ -99,7 +99,10 @@ export function createClickable<T extends ClickableOptions>(
|
|||
optionsFunc?: OptionsFunc<T, BaseClickable, GenericClickable>,
|
||||
...decorators: GenericDecorator[]
|
||||
): Clickable<T> {
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy(feature => {
|
||||
const clickable =
|
||||
optionsFunc?.call(feature, feature) ??
|
||||
|
@ -144,7 +147,10 @@ export function createClickable<T extends ClickableOptions>(
|
|||
decorator.postConstruct?.(clickable);
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(clickable)), {});
|
||||
const decoratedProps = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getGatheredProps?.(clickable)),
|
||||
{}
|
||||
);
|
||||
clickable[GatherProps] = function (this: GenericClickable) {
|
||||
const {
|
||||
display,
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import { Replace } from "features/feature";
|
||||
import Decimal, { DecimalSource } from "util/bignum";
|
||||
import { Computable, GetComputableType, ProcessedComputable, processComputable } from "util/computed";
|
||||
import {
|
||||
Computable,
|
||||
GetComputableType,
|
||||
ProcessedComputable,
|
||||
processComputable
|
||||
} from "util/computed";
|
||||
import { Ref, computed, unref } from "vue";
|
||||
import { Decorator } from "./common";
|
||||
|
||||
|
@ -25,10 +30,12 @@ export interface BaseBonusCompletionsFeature {
|
|||
}
|
||||
|
||||
export type BonusAmountFeature<T extends BonusAmountFeatureOptions> = Replace<
|
||||
T, { bonusAmount: GetComputableType<T["bonusAmount"]>; }
|
||||
T,
|
||||
{ bonusAmount: GetComputableType<T["bonusAmount"]> }
|
||||
>;
|
||||
export type BonusCompletionsFeature<T extends BonusCompletionsFeatureOptions> = Replace<
|
||||
T, { bonusAmount: GetComputableType<T["bonusCompletions"]>; }
|
||||
T,
|
||||
{ bonusAmount: GetComputableType<T["bonusCompletions"]> }
|
||||
>;
|
||||
|
||||
export type GenericBonusAmountFeature = Replace<
|
||||
|
@ -57,22 +64,30 @@ export type GenericBonusCompletionsFeature = Replace<
|
|||
* ...
|
||||
* }), bonusAmountDecorator) as GenericRepeatable & GenericBonusAmountFeature
|
||||
*/
|
||||
export const bonusAmountDecorator: Decorator<BonusAmountFeatureOptions, BaseBonusAmountFeature, GenericBonusAmountFeature> = {
|
||||
export const bonusAmountDecorator: Decorator<
|
||||
BonusAmountFeatureOptions,
|
||||
BaseBonusAmountFeature,
|
||||
GenericBonusAmountFeature
|
||||
> = {
|
||||
preConstruct(feature) {
|
||||
if (feature.amount === undefined) {
|
||||
console.error(`Decorated feature ${feature.id} does not contain the required 'amount' property"`);
|
||||
console.error(
|
||||
`Decorated feature ${feature.id} does not contain the required 'amount' property"`
|
||||
);
|
||||
}
|
||||
},
|
||||
postConstruct(feature) {
|
||||
processComputable(feature, "bonusAmount");
|
||||
if (feature.totalAmount === undefined) {
|
||||
feature.totalAmount = computed(() => Decimal.add(
|
||||
feature.totalAmount = computed(() =>
|
||||
Decimal.add(
|
||||
unref(feature.amount ?? 0),
|
||||
unref(feature.bonusAmount as ProcessedComputable<DecimalSource>)
|
||||
));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Allows the addition of "bonus levels" to the decorated feature, with an accompanying "total amount".
|
||||
|
@ -84,14 +99,20 @@ export const bonusAmountDecorator: Decorator<BonusAmountFeatureOptions, BaseBonu
|
|||
* ...
|
||||
* }), bonusCompletionDecorator) as GenericChallenge & GenericBonusCompletionFeature
|
||||
*/
|
||||
export const bonusCompletionsDecorator: Decorator<BonusCompletionsFeatureOptions, BaseBonusCompletionsFeature, GenericBonusCompletionsFeature> = {
|
||||
export const bonusCompletionsDecorator: Decorator<
|
||||
BonusCompletionsFeatureOptions,
|
||||
BaseBonusCompletionsFeature,
|
||||
GenericBonusCompletionsFeature
|
||||
> = {
|
||||
postConstruct(feature) {
|
||||
processComputable(feature, "bonusCompletions");
|
||||
if (feature.totalCompletions === undefined) {
|
||||
feature.totalCompletions = computed(() => Decimal.add(
|
||||
feature.totalCompletions = computed(() =>
|
||||
Decimal.add(
|
||||
unref(feature.completions ?? 0),
|
||||
unref(feature.bonusCompletions as ProcessedComputable<DecimalSource>)
|
||||
));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,13 +1,29 @@
|
|||
import { Replace, OptionsObject } from "../feature";
|
||||
import { Computable, GetComputableType, processComputable, ProcessedComputable } from "util/computed";
|
||||
import {
|
||||
Computable,
|
||||
GetComputableType,
|
||||
processComputable,
|
||||
ProcessedComputable
|
||||
} from "util/computed";
|
||||
import { Persistent, State } from "game/persistence";
|
||||
|
||||
export type Decorator<FeatureOptions, BaseFeature = object, GenericFeature = BaseFeature, S extends State = State> = {
|
||||
export type Decorator<
|
||||
FeatureOptions,
|
||||
BaseFeature = object,
|
||||
GenericFeature = BaseFeature,
|
||||
S extends State = State
|
||||
> = {
|
||||
getPersistentData?(): Record<string, Persistent<S>>;
|
||||
preConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void;
|
||||
postConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void;
|
||||
getGatheredProps?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): Partial<OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>>
|
||||
}
|
||||
preConstruct?(
|
||||
feature: OptionsObject<FeatureOptions, BaseFeature & { id: string }, GenericFeature>
|
||||
): void;
|
||||
postConstruct?(
|
||||
feature: OptionsObject<FeatureOptions, BaseFeature & { id: string }, GenericFeature>
|
||||
): void;
|
||||
getGatheredProps?(
|
||||
feature: OptionsObject<FeatureOptions, BaseFeature & { id: string }, GenericFeature>
|
||||
): Partial<OptionsObject<FeatureOptions, BaseFeature & { id: string }, GenericFeature>>;
|
||||
};
|
||||
|
||||
export type GenericDecorator = Decorator<unknown>;
|
||||
|
||||
|
@ -16,12 +32,13 @@ export interface EffectFeatureOptions {
|
|||
}
|
||||
|
||||
export type EffectFeature<T extends EffectFeatureOptions> = Replace<
|
||||
T, { effect: GetComputableType<T["effect"]>; }
|
||||
T,
|
||||
{ effect: GetComputableType<T["effect"]> }
|
||||
>;
|
||||
|
||||
export type GenericEffectFeature = Replace<
|
||||
EffectFeature<EffectFeatureOptions>,
|
||||
{ effect: ProcessedComputable<any>; }
|
||||
{ effect: ProcessedComputable<any> }
|
||||
>;
|
||||
|
||||
/**
|
||||
|
@ -39,5 +56,4 @@ export const effectDecorator: Decorator<EffectFeatureOptions, unknown, GenericEf
|
|||
postConstruct(feature) {
|
||||
processComputable(feature, "effect");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -134,7 +134,10 @@ export function createRepeatable<T extends RepeatableOptions>(
|
|||
...decorators: GenericDecorator[]
|
||||
): Repeatable<T> {
|
||||
const amount = persistent<DecimalSource>(0);
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy<Repeatable<T>, Repeatable<T>>(feature => {
|
||||
const repeatable = optionsFunc.call(feature, feature);
|
||||
|
||||
|
@ -274,7 +277,10 @@ export function createRepeatable<T extends RepeatableOptions>(
|
|||
decorator.postConstruct?.(repeatable);
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(repeatable)), {});
|
||||
const decoratedProps = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getGatheredProps?.(repeatable)),
|
||||
{}
|
||||
);
|
||||
repeatable[GatherProps] = function (this: GenericRepeatable) {
|
||||
const { display, visibility, style, classes, onClick, canClick, small, mark, id } =
|
||||
this;
|
||||
|
|
|
@ -105,7 +105,10 @@ export function createTreeNode<T extends TreeNodeOptions>(
|
|||
optionsFunc?: OptionsFunc<T, BaseTreeNode, GenericTreeNode>,
|
||||
...decorators: GenericDecorator[]
|
||||
): TreeNode<T> {
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy(feature => {
|
||||
const treeNode =
|
||||
optionsFunc?.call(feature, feature) ??
|
||||
|
@ -152,7 +155,10 @@ export function createTreeNode<T extends TreeNodeOptions>(
|
|||
};
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(treeNode)), {});
|
||||
const decoratedProps = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getGatheredProps?.(treeNode)),
|
||||
{}
|
||||
);
|
||||
treeNode[GatherProps] = function (this: GenericTreeNode) {
|
||||
const {
|
||||
display,
|
||||
|
|
|
@ -122,7 +122,10 @@ export function createUpgrade<T extends UpgradeOptions>(
|
|||
...decorators: GenericDecorator[]
|
||||
): Upgrade<T> {
|
||||
const bought = persistent<boolean>(false, false);
|
||||
const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {});
|
||||
const decoratedData = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getPersistentData?.()),
|
||||
{}
|
||||
);
|
||||
return createLazyProxy(feature => {
|
||||
const upgrade = optionsFunc.call(feature, feature);
|
||||
upgrade.id = getUniqueID("upgrade-");
|
||||
|
@ -165,7 +168,10 @@ export function createUpgrade<T extends UpgradeOptions>(
|
|||
decorator.preConstruct?.(upgrade);
|
||||
}
|
||||
|
||||
const decoratedProps = decorators.reduce((current, next) => Object.assign(current, next.getGatheredProps?.(upgrade)), {});
|
||||
const decoratedProps = decorators.reduce(
|
||||
(current, next) => Object.assign(current, next.getGatheredProps?.(upgrade)),
|
||||
{}
|
||||
);
|
||||
upgrade[GatherProps] = function (this: GenericUpgrade) {
|
||||
const {
|
||||
display,
|
||||
|
|
Loading…
Reference in a new issue