Skip to content

Commit

Permalink
Validate actor size in pack builder, soften handling in ActorSizePF2e (
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam authored Jun 13, 2022
1 parent ec94706 commit 0d27463
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packs/data/pfs-season-2-bestiary.db/yeth-warbeast.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"value": "darkvision, scent (imprecise) 30 feet"
},
"size": {
"value": "lrg"
"value": "lg"
},
"traits": {
"custom": "",
Expand Down
12 changes: 11 additions & 1 deletion packs/scripts/packman/compendium-pack.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as fs from "fs";
import * as path from "path";
import { isObject, setHasElement, sluggify } from "@util";
import { isObject, setHasElement, sluggify, tupleHasValue } from "@util";
import { ItemSourcePF2e } from "@item/data";
import { isPhysicalData } from "@item/data/helpers";
import { MigrationRunnerBase } from "@module/migration/runner/base";
import { ActorSourcePF2e } from "@actor/data";
import { RuleElementSource } from "@module/rules";
import { FEAT_TYPES } from "@item/feat/values";
import { SIZES } from "@module/data";

export interface PackMetadata {
system: string;
Expand Down Expand Up @@ -165,6 +166,7 @@ export class CompendiumPack {
docSource.flags ??= {};
docSource.flags.core = { sourceId: this.sourceIdOf(docSource._id) };
if (isActorSource(docSource)) {
this.assertSizeValid(docSource);
docSource.data.schema = { version: MigrationRunnerBase.LATEST_SCHEMA_VERSION, lastMigration: null };
for (const item of docSource.items) {
item.data.schema = { version: MigrationRunnerBase.LATEST_SCHEMA_VERSION, lastMigration: null };
Expand Down Expand Up @@ -301,4 +303,12 @@ export class CompendiumPack {
private isPackData(packData: unknown[]): packData is CompendiumSource[] {
return packData.every((maybeDocSource: unknown) => this.isDocumentSource(maybeDocSource));
}

private assertSizeValid(source: ActorSourcePF2e | ItemSourcePF2e): void {
if ("items" in source && "traits" in source.data && source.type !== "character") {
if (!tupleHasValue(SIZES, source.data.traits.size.value)) {
throw PackError(`Actor size on ${source.name} (${source._id}) is invalid.`);
}
}
}
}
4 changes: 2 additions & 2 deletions src/module/actor/data/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export class ActorSizePF2e {
* @param [width] A width of a Pathfinder "space"
*/
constructor({ value, length, width }: { value: Size; length?: number; width?: number }) {
if (typeof value === "object") value = "med"; // Temporary line for pre-migration 728 size data
if (typeof value !== "string") value = "med"; // Temporary line for pre-migration 728 size data

this.value = value;
const spaces = ActorSizePF2e.defaultSpaces[value];
const spaces = ActorSizePF2e.defaultSpaces[value] ?? ActorSizePF2e.defaultSpaces.med;
this.length = length ?? spaces.length;
this.width = width ?? spaces.width;
}
Expand Down

0 comments on commit 0d27463

Please sign in to comment.