Skip to content

Commit

Permalink
Remove redundant type/value imports of DataFields in rule element f…
Browse files Browse the repository at this point in the history
…iles (#17682)
  • Loading branch information
stwlam authored Dec 11, 2024
1 parent b3b12a5 commit e09dcda
Show file tree
Hide file tree
Showing 35 changed files with 275 additions and 353 deletions.
8 changes: 3 additions & 5 deletions src/module/rules/rule-element/actor-traits.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type { ActorType } from "@actor/types.ts";
import { ErrorPF2e } from "@util";
import type { ArrayField, StringField } from "types/foundry/common/data/fields.d.ts";
import { ModelPropsFromRESchema } from "./data.ts";
import { RuleElementPF2e, RuleElementSchema } from "./index.ts";
import fields = foundry.data.fields;

class ActorTraitsRuleElement extends RuleElementPF2e<ActorTraitsRuleSchema> {
protected static override validActorTypes: ActorType[] = ["character", "npc", "familiar", "hazard", "vehicle"];

static override defineSchema(): ActorTraitsRuleSchema {
const fields = foundry.data.fields;

return {
...super.defineSchema(),
priority: new fields.NumberField({ required: true, nullable: false, integer: true, initial: 51 }),
Expand Down Expand Up @@ -70,8 +68,8 @@ class ActorTraitsRuleElement extends RuleElementPF2e<ActorTraitsRuleSchema> {
}

type ActorTraitsRuleSchema = RuleElementSchema & {
add: ArrayField<StringField<string, string, true, false, false>>;
remove: ArrayField<StringField<string, string, true, false, false>>;
add: fields.ArrayField<fields.StringField<string, string, true, false, false>>;
remove: fields.ArrayField<fields.StringField<string, string, true, false, false>>;
};

interface ActorTraitsRuleElement
Expand Down
10 changes: 4 additions & 6 deletions src/module/rules/rule-element/adjust-degree-of-success.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
DegreeOfSuccessString,
} from "@system/degree-of-success.ts";
import { RecordField } from "@system/schema-data-fields.ts";
import type { StringField } from "types/foundry/common/data/fields.d.ts";
import { ModelPropsFromRESchema } from "./data.ts";
import { RuleElementPF2e, RuleElementSchema } from "./index.ts";
import fields = foundry.data.fields;

/**
* @category RuleElement
Expand All @@ -17,8 +17,6 @@ class AdjustDegreeOfSuccessRuleElement extends RuleElementPF2e<AdjustDegreeRuleS
protected static override validActorTypes: ActorType[] = ["character", "npc"];

static override defineSchema(): AdjustDegreeRuleSchema {
const fields = foundry.data.fields;

return {
...super.defineSchema(),
selector: new fields.StringField({ required: true, nullable: false, blank: false }),
Expand Down Expand Up @@ -89,10 +87,10 @@ const degreeAdjustmentAmountString = [
type DegreeAdjustmentAmountString = (typeof degreeAdjustmentAmountString)[number];

type AdjustDegreeRuleSchema = RuleElementSchema & {
selector: StringField<string, string, true, false, false>;
selector: fields.StringField<string, string, true, false, false>;
adjustment: RecordField<
StringField<"all" | DegreeOfSuccessString, "all" | DegreeOfSuccessString, true, false, false>,
StringField<DegreeAdjustmentAmountString, DegreeAdjustmentAmountString, true, false, false>
fields.StringField<"all" | DegreeOfSuccessString, "all" | DegreeOfSuccessString, true, false, false>,
fields.StringField<DegreeAdjustmentAmountString, DegreeAdjustmentAmountString, true, false, false>
>;
};

Expand Down
18 changes: 8 additions & 10 deletions src/module/rules/rule-element/adjust-modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Predicate } from "@system/predication.ts";
import { StrictArrayField } from "@system/schema-data-fields.ts";
import { objectHasKey } from "@util";
import * as R from "remeda";
import type { ArrayField, BooleanField, NumberField, StringField } from "types/foundry/common/data/fields.d.ts";
import { AELikeChangeMode, AELikeRuleElement } from "./ae-like.ts";
import { ModelPropsFromRESchema, ResolvableValueField } from "./data.ts";
import { RuleElementOptions, RuleElementPF2e, RuleElementSchema, RuleElementSource } from "./index.ts";
import fields = foundry.data.fields;

/** Adjust the value of a modifier, change its damage type (in case of damage modifiers) or suppress it entirely */
class AdjustModifierRuleElement extends RuleElementPF2e<AdjustModifierSchema> {
Expand All @@ -27,8 +27,6 @@ class AdjustModifierRuleElement extends RuleElementPF2e<AdjustModifierSchema> {
}

static override defineSchema(): AdjustModifierSchema {
const fields = foundry.data.fields;

const baseSchema = super.defineSchema();
const PRIORITIES: Record<string, number | undefined> = AELikeRuleElement.CHANGE_MODE_DEFAULT_PRIORITIES;
baseSchema.priority.initial = (d) => PRIORITIES[String(d.mode)] ?? 50;
Expand Down Expand Up @@ -131,16 +129,16 @@ interface AdjustModifierRuleElement
}

type AdjustModifierSchema = RuleElementSchema & {
mode: StringField<AELikeChangeMode, AELikeChangeMode, true, false, false>;
mode: fields.StringField<AELikeChangeMode, AELikeChangeMode, true, false, false>;
/** An optional relabeling of the adjusted modifier */
relabel: StringField<string, string, false, true, true>;
selector: StringField<string, string, false, false, false>;
selectors: ArrayField<StringField<string, string, true, false, false>>;
damageType: StringField<string, string, false, true, true>;
relabel: fields.StringField<string, string, false, true, true>;
selector: fields.StringField<string, string, false, false, false>;
selectors: fields.ArrayField<fields.StringField<string, string, true, false, false>>;
damageType: fields.StringField<string, string, false, true, true>;
/** Rather than changing a modifier's value, ignore it entirely */
suppress: BooleanField<boolean, boolean, false, false, true>;
suppress: fields.BooleanField<boolean, boolean, false, false, true>;
/** The maximum number of times this adjustment can be applied */
maxApplications: NumberField<number, number, false, true, true>;
maxApplications: fields.NumberField<number, number, false, true, true>;
value: ResolvableValueField<false, true, true>;
};

Expand Down
8 changes: 3 additions & 5 deletions src/module/rules/rule-element/adjust-strike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { MaterialDamageEffect } from "@system/damage/index.ts";
import { PredicateField } from "@system/schema-data-fields.ts";
import { ErrorPF2e, objectHasKey, sluggify } from "@util";
import * as R from "remeda";
import type { StringField } from "types/foundry/common/data/fields.d.ts";
import { StrikeAdjustment } from "../synthetics.ts";
import { AELikeChangeMode, AELikeRuleElement } from "./ae-like.ts";
import { RuleElementOptions, RuleElementPF2e } from "./base.ts";
import { ModelPropsFromRESchema, ResolvableValueField, RuleElementSchema, RuleElementSource } from "./data.ts";
import fields = foundry.data.fields;

class AdjustStrikeRuleElement extends RuleElementPF2e<AdjustStrikeSchema> {
protected static override validActorTypes: ActorType[] = ["character", "familiar", "npc"];
Expand All @@ -30,8 +30,6 @@ class AdjustStrikeRuleElement extends RuleElementPF2e<AdjustStrikeSchema> {
] as const);

static override defineSchema(): AdjustStrikeSchema {
const fields = foundry.data.fields;

return {
...super.defineSchema(),
mode: new fields.StringField({
Expand Down Expand Up @@ -210,9 +208,9 @@ interface AdjustStrikeRuleElement
ModelPropsFromRESchema<AdjustStrikeSchema> {}

type AdjustStrikeSchema = RuleElementSchema & {
mode: StringField<AELikeChangeMode, AELikeChangeMode, true, false, false>;
mode: fields.StringField<AELikeChangeMode, AELikeChangeMode, true, false, false>;
/** The property of the strike to adjust */
property: StringField<AdjustStrikeProperty, AdjustStrikeProperty, true, false, false>;
property: fields.StringField<AdjustStrikeProperty, AdjustStrikeProperty, true, false, false>;
/** The definition of the strike in terms of its item (weapon) roll options */
definition: PredicateField;
value: ResolvableValueField<true, false, false>;
Expand Down
4 changes: 1 addition & 3 deletions src/module/rules/rule-element/ae-like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import * as R from "remeda";
import type { DataModelValidationFailure } from "types/foundry/common/data/validation-failure.d.ts";
import { RuleElementPF2e } from "./base.ts";
import { ModelPropsFromRESchema, ResolvableValueField, RuleElementSchema, RuleElementSource } from "./data.ts";
import fields = foundry.data.fields;

/**
* Make a numeric modification to an arbitrary property in a similar way as `ActiveEffect`s
* @category RuleElement
*/
class AELikeRuleElement<TSchema extends AELikeSchema> extends RuleElementPF2e<TSchema> {
static override defineSchema(): AELikeSchema {
const fields = foundry.data.fields;

const baseSchema = super.defineSchema();
const PRIORITIES: Record<string, number | undefined> = this.CHANGE_MODE_DEFAULT_PRIORITIES;
baseSchema.priority.initial = (d) => PRIORITIES[String(d.mode)] ?? 50;
Expand Down Expand Up @@ -257,7 +256,6 @@ interface AutoChangeEntry {
mode: AELikeChangeMode;
}

import fields = foundry.data.fields;
type AELikeSchema = RuleElementSchema & {
/** How to apply the `value` at the `path` */
mode: fields.StringField<AELikeChangeMode, AELikeChangeMode, true, false, false>;
Expand Down
Loading

0 comments on commit e09dcda

Please sign in to comment.