Ran prettier

This commit is contained in:
thepaperpilot 2023-04-19 20:39:25 -05:00
parent c9ca85978d
commit 98f18fef43
11 changed files with 139 additions and 55 deletions

View file

@ -142,7 +142,10 @@ export function createAchievement<T extends AchievementOptions>(
...decorators: GenericDecorator[] ...decorators: GenericDecorator[]
): Achievement<T> { ): Achievement<T> {
const earned = persistent<boolean>(false, false); 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 => { return createLazyProxy(feature => {
const achievement = const achievement =
optionsFunc?.call(feature, feature) ?? optionsFunc?.call(feature, feature) ??
@ -232,7 +235,10 @@ export function createAchievement<T extends AchievementOptions>(
decorator.postConstruct?.(achievement); 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) { achievement[GatherProps] = function (this: GenericAchievement) {
const { const {
visibility, visibility,

View file

@ -107,7 +107,10 @@ export function createAction<T extends ActionOptions>(
...decorators: GenericDecorator[] ...decorators: GenericDecorator[]
): Action<T> { ): Action<T> {
const progress = persistent<DecimalSource>(0); 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 => { return createLazyProxy(feature => {
const action = const action =
optionsFunc?.call(feature, feature) ?? optionsFunc?.call(feature, feature) ??
@ -241,7 +244,9 @@ export function createAction<T extends ActionOptions>(
decorator.postConstruct?.(action); 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) { action[GatherProps] = function (this: GenericAction) {
const { const {
display, display,

View file

@ -105,7 +105,10 @@ export function createBar<T extends BarOptions>(
optionsFunc: OptionsFunc<T, BaseBar, GenericBar>, optionsFunc: OptionsFunc<T, BaseBar, GenericBar>,
...decorators: GenericDecorator[] ...decorators: GenericDecorator[]
): Bar<T> { ): 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 => { return createLazyProxy(feature => {
const bar = optionsFunc.call(feature, feature); const bar = optionsFunc.call(feature, feature);
bar.id = getUniqueID("bar-"); bar.id = getUniqueID("bar-");
@ -137,7 +140,10 @@ export function createBar<T extends BarOptions>(
decorator.postConstruct?.(bar); 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) { bar[GatherProps] = function (this: GenericBar) {
const { const {
progress, progress,

View file

@ -154,7 +154,10 @@ export function createChallenge<T extends ChallengeOptions>(
): Challenge<T> { ): Challenge<T> {
const completions = persistent(0); const completions = persistent(0);
const active = persistent(false, false); 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 => { return createLazyProxy(feature => {
const challenge = optionsFunc.call(feature, feature); const challenge = optionsFunc.call(feature, feature);
@ -271,7 +274,10 @@ export function createChallenge<T extends ChallengeOptions>(
decorator.postConstruct?.(challenge); 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) { challenge[GatherProps] = function (this: GenericChallenge) {
const { const {
active, active,

View file

@ -99,7 +99,10 @@ export function createClickable<T extends ClickableOptions>(
optionsFunc?: OptionsFunc<T, BaseClickable, GenericClickable>, optionsFunc?: OptionsFunc<T, BaseClickable, GenericClickable>,
...decorators: GenericDecorator[] ...decorators: GenericDecorator[]
): Clickable<T> { ): 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 => { return createLazyProxy(feature => {
const clickable = const clickable =
optionsFunc?.call(feature, feature) ?? optionsFunc?.call(feature, feature) ??
@ -144,7 +147,10 @@ export function createClickable<T extends ClickableOptions>(
decorator.postConstruct?.(clickable); 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) { clickable[GatherProps] = function (this: GenericClickable) {
const { const {
display, display,

View file

@ -1,6 +1,11 @@
import { Replace } from "features/feature"; import { Replace } from "features/feature";
import Decimal, { DecimalSource } from "util/bignum"; 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 { Ref, computed, unref } from "vue";
import { Decorator } from "./common"; import { Decorator } from "./common";
@ -25,10 +30,12 @@ export interface BaseBonusCompletionsFeature {
} }
export type BonusAmountFeature<T extends BonusAmountFeatureOptions> = Replace< export type BonusAmountFeature<T extends BonusAmountFeatureOptions> = Replace<
T, { bonusAmount: GetComputableType<T["bonusAmount"]>; } T,
{ bonusAmount: GetComputableType<T["bonusAmount"]> }
>; >;
export type BonusCompletionsFeature<T extends BonusCompletionsFeatureOptions> = Replace< export type BonusCompletionsFeature<T extends BonusCompletionsFeatureOptions> = Replace<
T, { bonusAmount: GetComputableType<T["bonusCompletions"]>; } T,
{ bonusAmount: GetComputableType<T["bonusCompletions"]> }
>; >;
export type GenericBonusAmountFeature = Replace< export type GenericBonusAmountFeature = Replace<
@ -57,22 +64,30 @@ export type GenericBonusCompletionsFeature = Replace<
* ... * ...
* }), bonusAmountDecorator) as GenericRepeatable & GenericBonusAmountFeature * }), bonusAmountDecorator) as GenericRepeatable & GenericBonusAmountFeature
*/ */
export const bonusAmountDecorator: Decorator<BonusAmountFeatureOptions, BaseBonusAmountFeature, GenericBonusAmountFeature> = { export const bonusAmountDecorator: Decorator<
BonusAmountFeatureOptions,
BaseBonusAmountFeature,
GenericBonusAmountFeature
> = {
preConstruct(feature) { preConstruct(feature) {
if (feature.amount === undefined) { 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) { postConstruct(feature) {
processComputable(feature, "bonusAmount"); processComputable(feature, "bonusAmount");
if (feature.totalAmount === undefined) { if (feature.totalAmount === undefined) {
feature.totalAmount = computed(() => Decimal.add( feature.totalAmount = computed(() =>
unref(feature.amount ?? 0), Decimal.add(
unref(feature.bonusAmount as ProcessedComputable<DecimalSource>) 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". * 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 * }), bonusCompletionDecorator) as GenericChallenge & GenericBonusCompletionFeature
*/ */
export const bonusCompletionsDecorator: Decorator<BonusCompletionsFeatureOptions, BaseBonusCompletionsFeature, GenericBonusCompletionsFeature> = { export const bonusCompletionsDecorator: Decorator<
BonusCompletionsFeatureOptions,
BaseBonusCompletionsFeature,
GenericBonusCompletionsFeature
> = {
postConstruct(feature) { postConstruct(feature) {
processComputable(feature, "bonusCompletions"); processComputable(feature, "bonusCompletions");
if (feature.totalCompletions === undefined) { if (feature.totalCompletions === undefined) {
feature.totalCompletions = computed(() => Decimal.add( feature.totalCompletions = computed(() =>
unref(feature.completions ?? 0), Decimal.add(
unref(feature.bonusCompletions as ProcessedComputable<DecimalSource>) unref(feature.completions ?? 0),
)); unref(feature.bonusCompletions as ProcessedComputable<DecimalSource>)
)
);
} }
} }
} };

View file

@ -1,13 +1,29 @@
import { Replace, OptionsObject } from "../feature"; 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"; 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>>; getPersistentData?(): Record<string, Persistent<S>>;
preConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void; preConstruct?(
postConstruct?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): void; feature: OptionsObject<FeatureOptions, BaseFeature & { id: string }, GenericFeature>
getGatheredProps?(feature: OptionsObject<FeatureOptions,BaseFeature & {id:string},GenericFeature>): Partial<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>; export type GenericDecorator = Decorator<unknown>;
@ -16,12 +32,13 @@ export interface EffectFeatureOptions {
} }
export type EffectFeature<T extends EffectFeatureOptions> = Replace< export type EffectFeature<T extends EffectFeatureOptions> = Replace<
T, { effect: GetComputableType<T["effect"]>; } T,
{ effect: GetComputableType<T["effect"]> }
>; >;
export type GenericEffectFeature = Replace< export type GenericEffectFeature = Replace<
EffectFeature<EffectFeatureOptions>, EffectFeature<EffectFeatureOptions>,
{ effect: ProcessedComputable<any>; } { effect: ProcessedComputable<any> }
>; >;
/** /**
@ -39,5 +56,4 @@ export const effectDecorator: Decorator<EffectFeatureOptions, unknown, GenericEf
postConstruct(feature) { postConstruct(feature) {
processComputable(feature, "effect"); processComputable(feature, "effect");
} }
} };

View file

@ -42,7 +42,7 @@ export type Replace<T, S> = S & Omit<T, keyof S>;
* with "this" bound to what the type will eventually be processed into. * with "this" bound to what the type will eventually be processed into.
* Intended for making lazily evaluated objects. * Intended for making lazily evaluated objects.
*/ */
export type OptionsFunc<T, R = unknown, S = R> = (obj: R) => OptionsObject<T,R,S>; export type OptionsFunc<T, R = unknown, S = R> = (obj: R) => OptionsObject<T, R, S>;
export type OptionsObject<T, R = unknown, S = R> = T & Partial<R> & ThisType<T & S>; export type OptionsObject<T, R = unknown, S = R> = T & Partial<R> & ThisType<T & S>;

View file

@ -134,7 +134,10 @@ export function createRepeatable<T extends RepeatableOptions>(
...decorators: GenericDecorator[] ...decorators: GenericDecorator[]
): Repeatable<T> { ): Repeatable<T> {
const amount = persistent<DecimalSource>(0); 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 => { return createLazyProxy<Repeatable<T>, Repeatable<T>>(feature => {
const repeatable = optionsFunc.call(feature, feature); const repeatable = optionsFunc.call(feature, feature);
@ -233,10 +236,10 @@ export function createRepeatable<T extends RepeatableOptions>(
<div> <div>
<br /> <br />
joinJSX( joinJSX(
<>Amount: {formatWhole(genericRepeatable.amount.value)}</>, <>Amount: {formatWhole(genericRepeatable.amount.value)}</>,
{unref(genericRepeatable.limit) !== Decimal.dInf ? ( {unref(genericRepeatable.limit) !== Decimal.dInf ? (
<> / {formatWhole(unref(genericRepeatable.limit))}</> <> / {formatWhole(unref(genericRepeatable.limit))}</>
) : undefined} ) : undefined}
) )
</div> </div>
)} )}
@ -274,7 +277,10 @@ export function createRepeatable<T extends RepeatableOptions>(
decorator.postConstruct?.(repeatable); 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) { repeatable[GatherProps] = function (this: GenericRepeatable) {
const { display, visibility, style, classes, onClick, canClick, small, mark, id } = const { display, visibility, style, classes, onClick, canClick, small, mark, id } =
this; this;

View file

@ -105,7 +105,10 @@ export function createTreeNode<T extends TreeNodeOptions>(
optionsFunc?: OptionsFunc<T, BaseTreeNode, GenericTreeNode>, optionsFunc?: OptionsFunc<T, BaseTreeNode, GenericTreeNode>,
...decorators: GenericDecorator[] ...decorators: GenericDecorator[]
): TreeNode<T> { ): 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 => { return createLazyProxy(feature => {
const treeNode = const treeNode =
optionsFunc?.call(feature, feature) ?? 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) { treeNode[GatherProps] = function (this: GenericTreeNode) {
const { const {
display, display,

View file

@ -21,7 +21,7 @@ import type { GenericLayer } from "game/layers";
import type { Persistent } from "game/persistence"; import type { Persistent } from "game/persistence";
import { persistent } from "game/persistence"; import { persistent } from "game/persistence";
import { import {
createCostRequirement, createCostRequirement,
createVisibilityRequirement, createVisibilityRequirement,
payRequirements, payRequirements,
Requirements, Requirements,
@ -122,7 +122,10 @@ export function createUpgrade<T extends UpgradeOptions>(
...decorators: GenericDecorator[] ...decorators: GenericDecorator[]
): Upgrade<T> { ): Upgrade<T> {
const bought = persistent<boolean>(false, false); 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 => { return createLazyProxy(feature => {
const upgrade = optionsFunc.call(feature, feature); const upgrade = optionsFunc.call(feature, feature);
upgrade.id = getUniqueID("upgrade-"); upgrade.id = getUniqueID("upgrade-");
@ -165,7 +168,10 @@ export function createUpgrade<T extends UpgradeOptions>(
decorator.preConstruct?.(upgrade); 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) { upgrade[GatherProps] = function (this: GenericUpgrade) {
const { const {
display, display,