Skip to content

Commit

Permalink
Move source data in actors and items to fuller publication object
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Oct 13, 2023
1 parent da7c636 commit 3e0f172
Show file tree
Hide file tree
Showing 38 changed files with 432 additions and 227 deletions.
9 changes: 6 additions & 3 deletions build/lib/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ActorSourcePF2e } from "@actor/data/index.ts";
import type { NPCAttributesSource, NPCSystemSource } from "@actor/npc/data.ts";
import { isPhysicalData } from "@item/data/helpers.ts";
import { ItemSourcePF2e, MeleeSource, SpellSource } from "@item/data/index.ts";
import { PublicationData } from "@module/data.ts";
import { RuleElementSource } from "@module/rules/index.ts";
import { isObject, sluggify } from "@util/index.ts";
import fs from "fs";
Expand Down Expand Up @@ -462,9 +463,8 @@ class PackExtractor {
if (docSource.type === "character") {
delete (docSource.system.details.biography as { visibility?: unknown }).visibility;
} else if (docSource.type === "npc") {
const source: Partial<NPCSystemSource["details"]["source"]> =
docSource.system.details.source;
if (!source.author?.trim()) delete source.author;
const publication: Partial<PublicationData> = docSource.system.details.publication;
if (!publication.authors?.trim()) delete publication.authors;

const speed: Partial<NPCAttributesSource["speed"]> = docSource.system.attributes.speed;
if (!speed.details?.trim()) delete speed.details;
Expand Down Expand Up @@ -506,6 +506,9 @@ class PackExtractor {
delete (source.system.traits as { otherTags?: unknown }).otherTags;
}

const publication: Partial<PublicationData> = source.system.publication;
if (!publication.authors?.trim()) delete publication.authors;

if (isPhysicalData(source)) {
delete (source.system as { identification?: unknown }).identification;

Expand Down
2 changes: 2 additions & 0 deletions build/run-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Migration873RemoveBonusBulkLimit } from "@module/migration/migrations/8
import { Migration874MoveStaminaStuff } from "@module/migration/migrations/874-move-stamina-stuff.ts";
import { Migration875SetInnovationIdEarly } from "@module/migration/migrations/875-set-innovation-id-early.ts";
import { Migration876FeatLevelTaken } from "@module/migration/migrations/876-feat-level-taken.ts";
import { Migration877PublicationData } from "@module/migration/migrations/877-publication-data.ts";

// ^^^ don't let your IDE use the index in these imports. you need to specify the full path ^^^

Expand Down Expand Up @@ -54,6 +55,7 @@ const migrations: MigrationBase[] = [
new Migration874MoveStaminaStuff(),
new Migration875SetInnovationIdEarly(),
new Migration876FeatLevelTaken(),
new Migration877PublicationData(),
];

global.deepClone = <T>(original: T): T => {
Expand Down
10 changes: 4 additions & 6 deletions src/module/actor/hazard/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ActorSizePF2e } from "@actor/data/size.ts";
import { InitiativeTraceData } from "@actor/initiative.ts";
import { NPCStrike } from "@actor/npc/index.ts";
import { SaveType } from "@actor/types.ts";
import { Rarity, Size } from "@module/data.ts";
import { PublicationData, Rarity, Size } from "@module/data.ts";
import { HazardTrait } from "./types.ts";

/** The stored source data of a hazard actor */
Expand Down Expand Up @@ -54,11 +54,9 @@ interface HazardDetailsSource extends ActorDetailsSource {
description?: string;
reset?: string;
routine?: string;
/** Book source, along with author */
source: {
value: string;
author: string;
};
/** Information concerning the publication from which this actor originates */
publication: PublicationData;

readonly alliance?: never;
}

Expand Down
13 changes: 4 additions & 9 deletions src/module/actor/npc/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { InitiativeTraceData } from "@actor/initiative.ts";
import type { ModifierPF2e, StatisticModifier } from "@actor/modifiers.ts";
import { ActorAlliance, AttributeString, SaveType } from "@actor/types.ts";
import type { MeleePF2e } from "@item";
import { Rarity, Size } from "@module/data.ts";
import { PublicationData, Rarity, Size } from "@module/data.ts";
import type { ArmorClassTraceData, StatisticTraceData } from "@system/statistic/index.ts";

type NPCSource = BaseCreatureSource<"npc", NPCSystemSource> & {
Expand Down Expand Up @@ -95,21 +95,16 @@ interface NPCDetailsSource extends CreatureDetailsSource {
level: {
value: number;
};

/** Which sourcebook this creature comes from. */
source: {
value: string;
author: string;
};

/** The type of this creature (such as 'undead') */
creatureType: string;
/** A very brief description */
blurb: string;
/** The in depth descripton and any other public notes */
/** The in-depth description and any other public notes */
publicNotes: string;
/** The private GM notes */
privateNotes: string;
/** Information concerning the publication from which this actor originates */
publication: PublicationData;
}

type NPCSavesSource = Record<SaveType, { value: number; saveDetail: string }>;
Expand Down
4 changes: 3 additions & 1 deletion src/module/actor/vehicle/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@actor/data/base.ts";
import { ImmunitySource } from "@actor/data/iwr.ts";
import type { ActorSizePF2e } from "@actor/data/size.ts";
import { Rarity, Size } from "@module/data.ts";
import { PublicationData, Rarity, Size } from "@module/data.ts";
import type { ArmorClassTraceData, StatisticTraceData } from "@system/statistic/index.ts";
import { VehicleTrait } from "./types.ts";

Expand Down Expand Up @@ -51,6 +51,8 @@ interface VehicleDetailsSource extends ActorDetailsSource {
pilotingCheck: string;
AC: number;
speed: number;
/** Information concerning the publication from which this actor originates */
publication: PublicationData;
}

interface VehicleTraitsSource extends ActorTraitsSource<VehicleTrait> {
Expand Down
19 changes: 10 additions & 9 deletions src/module/apps/compendium-browser/tabs/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export class CompendiumBrowserActionTab extends CompendiumBrowserTab {
"system.category",
"system.traits.value",
"system.actionType.value",
"system.source.value",
"system.publication",
"system.source",
];
const sources: Set<string> = new Set();
const publications = new Set<string>();

for await (const { pack, index } of this.browser.packLoader.loadPacks(
"Item",
Expand All @@ -52,12 +53,12 @@ export class CompendiumBrowserActionTab extends CompendiumBrowserTab {
// update icons for any passive actions
if (actionData.system.actionType.value === "passive") actionData.img = getActionIcon("passive");

// Prepare source
const source = actionData.system.source.value;
const sourceSlug = sluggify(source);
if (source) {
sources.add(source);
}
// Prepare publication source
const { system } = actionData;
const pubSource = String(system.publication?.title ?? system.source?.value ?? "").trim();
const sourceSlug = sluggify(pubSource);
if (pubSource) publications.add(pubSource);

actions.push({
type: actionData.type,
name: actionData.name,
Expand All @@ -81,7 +82,7 @@ export class CompendiumBrowserActionTab extends CompendiumBrowserTab {
this.filterData.checkboxes.category.options = this.generateCheckboxOptions(
R.pick(CONFIG.PF2E.actionCategories, ["familiar"])
);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(sources);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(publications);

console.debug("PF2e System | Compendium Browser | Finished loading actions");
}
Expand Down
2 changes: 1 addition & 1 deletion src/module/apps/compendium-browser/tabs/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export abstract class CompendiumBrowserTab {
/** Ensure all index fields are present in the index data */
protected hasAllIndexFields(data: CompendiumIndexData, indexFields: string[]): boolean {
for (const field of indexFields) {
if (getProperty(data, field) === undefined) {
if (getProperty(data, field) === undefined && !/\.(?:source|publication)/.test(field)) {
return false;
}
}
Expand Down
23 changes: 11 additions & 12 deletions src/module/apps/compendium-browser/tabs/bestiary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export class CompendiumBrowserBestiaryTab extends CompendiumBrowserTab {

protected index = [
"img",
"system.details.level.value",
"system.details.alignment.value",
"system.details.level.value",
"system.details.publication.title",
"system.details.source.value",
"system.traits",
];
Expand All @@ -29,7 +30,7 @@ export class CompendiumBrowserBestiaryTab extends CompendiumBrowserTab {
"actorSize",
"traits",
"rarity",
"source",
"publication",
];

constructor(browser: CompendiumBrowser) {
Expand All @@ -40,10 +41,8 @@ export class CompendiumBrowserBestiaryTab extends CompendiumBrowserTab {
}

protected override async loadData(): Promise<void> {
console.debug("PF2e System | Compendium Browser | Started loading Bestiary actors");

const bestiaryActors: CompendiumBrowserIndexData[] = [];
const sources: Set<string> = new Set();
const publications = new Set<string>();
const indexFields = [...this.index];

for await (const { pack, index } of this.browser.packLoader.loadPacks(
Expand All @@ -59,12 +58,12 @@ export class CompendiumBrowserBestiaryTab extends CompendiumBrowserTab {
);
continue;
}
// Prepare source
const source = actorData.system.details.source.value;
const sourceSlug = sluggify(source);
if (source) {
sources.add(source);
}

// Prepare publication source
const { details } = actorData.system;
const pubSource = String(details.publication?.title ?? details.source?.value ?? "").trim();
const sourceSlug = sluggify(pubSource);
if (pubSource) publications.add(pubSource);

bestiaryActors.push({
type: actorData.type,
Expand All @@ -90,7 +89,7 @@ export class CompendiumBrowserBestiaryTab extends CompendiumBrowserTab {
this.filterData.checkboxes.alignments.options = this.generateCheckboxOptions(CONFIG.PF2E.alignments, false);
this.filterData.multiselects.traits.options = this.generateMultiselectOptions(CONFIG.PF2E.creatureTraits);
this.filterData.checkboxes.rarity.options = this.generateCheckboxOptions(CONFIG.PF2E.rarityTraits, false);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(sources);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(publications);

console.debug("PF2e System | Compendium Browser | Finished loading Bestiary actors");
}
Expand Down
18 changes: 9 additions & 9 deletions src/module/apps/compendium-browser/tabs/campaign-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ export class CompendiumBrowserCampaignFeaturesTab extends CompendiumBrowserTab {
console.debug("PF2e System | Compendium Browser | Started loading feats");

const feats: CompendiumBrowserIndexData[] = [];
const sources: Set<string> = new Set();
const publications = new Set<string>();
const indexFields = [
"img",
"system.actionType.value",
"system.actions.value",
"system.category",
"system.level.value",
"system.prerequisites.value",
"system.source.value",
"system.traits",
"system.publication",
"system.source",
];

for await (const { pack, index } of this.browser.packLoader.loadPacks(
Expand All @@ -46,12 +47,11 @@ export class CompendiumBrowserCampaignFeaturesTab extends CompendiumBrowserTab {
for (const featData of index.filter((i) => i.type === "campaignFeature")) {
featData.filters = {};

// Prepare source
const source = featData.system.source.value;
const sourceSlug = sluggify(source);
if (source) {
sources.add(source);
}
// Prepare publication source
const { system } = featData;
const pubSource = String(system.publication?.title ?? system.source?.value ?? "").trim();
const sourceSlug = sluggify(pubSource);
if (pubSource) publications.add(pubSource);

// Only store essential data
feats.push({
Expand All @@ -74,7 +74,7 @@ export class CompendiumBrowserCampaignFeaturesTab extends CompendiumBrowserTab {
// Filters
this.filterData.checkboxes.category.options = this.generateCheckboxOptions(KINGMAKER_CATEGORIES);
this.filterData.checkboxes.rarity.options = this.generateCheckboxOptions(CONFIG.PF2E.rarityTraits);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(sources);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(publications);
this.filterData.multiselects.traits.options = this.generateMultiselectOptions(CONFIG.PF2E.kingmakerTraits);

console.debug("PF2e System | Compendium Browser | Finished loading feats");
Expand Down
25 changes: 15 additions & 10 deletions src/module/apps/compendium-browser/tabs/equipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CompendiumBrowserEquipmentTab extends CompendiumBrowserTab {
"priceInCopper",
"traits",
"rarity",
"source",
"publication",
];

#localizeCoins = localizer("PF2E.CurrencyAbbreviations");
Expand All @@ -43,7 +43,13 @@ export class CompendiumBrowserEquipmentTab extends CompendiumBrowserTab {
const itemTypes = ["weapon", "armor", "equipment", "consumable", "treasure", "backpack", "kit"];
// Define index fields for different types of equipment
const kitFields = ["img", "system.price", "system.traits"];
const baseFields = [...kitFields, "system.stackGroup", "system.level.value", "system.source.value"];
const baseFields = [
...kitFields,
"system.stackGroup",
"system.level.value",
"system.publication",
"system.source",
];
const armorFields = [...baseFields, "system.category", "system.group", "system.potencyRune.value"];
const weaponFields = [...armorFields, "system.strikingRune.value", "system.potencyRune.value"];
const consumableFields = [...baseFields, "system.consumableType.value"];
Expand All @@ -52,7 +58,7 @@ export class CompendiumBrowserEquipmentTab extends CompendiumBrowserTab {
"system.denomination.value",
"system.value.value",
];
const sources: Set<string> = new Set();
const publications = new Set<string>();

for await (const { pack, index } of this.browser.packLoader.loadPacks(
"Item",
Expand Down Expand Up @@ -90,12 +96,11 @@ export class CompendiumBrowserEquipmentTab extends CompendiumBrowserTab {
typeof priceValue === "string" ? CoinsPF2e.fromString(priceValue) : new CoinsPF2e(priceValue);
const coinValue = priceCoins.copperValue;

// Prepare source
const source = itemData.system.source.value;
const sourceSlug = sluggify(source);
if (source) {
sources.add(source);
}
// Prepare publication source
const { system } = itemData;
const pubSource = String(system.publication?.title ?? system.source?.value ?? "").trim();
const sourceSlug = sluggify(pubSource);
if (pubSource) publications.add(pubSource);

// Infer magical trait from runes
const traits = itemData.system.traits.value ?? [];
Expand Down Expand Up @@ -157,7 +162,7 @@ export class CompendiumBrowserEquipmentTab extends CompendiumBrowserTab {
kit: "TYPES.Item.kit",
});
this.filterData.checkboxes.rarity.options = this.generateCheckboxOptions(CONFIG.PF2E.rarityTraits, false);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(sources);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(publications);

console.debug("PF2e System | Compendium Browser | Finished loading inventory items");
}
Expand Down
15 changes: 7 additions & 8 deletions src/module/apps/compendium-browser/tabs/feat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class CompendiumBrowserFeatTab extends CompendiumBrowserTab {
console.debug("PF2e System | Compendium Browser | Started loading feats");

const feats: CompendiumBrowserIndexData[] = [];
const sources: Set<string> = new Set();
const publications = new Set<string>();
const indexFields = [
"img",
"system.actionType.value",
Expand All @@ -37,8 +37,9 @@ export class CompendiumBrowserFeatTab extends CompendiumBrowserTab {
"system.featType.value",
"system.level.value",
"system.prerequisites.value",
"system.source.value",
"system.traits",
"system.publication",
"system.source",
];

const translatedSkills = Object.entries(CONFIG.PF2E.skillList).reduce(
Expand Down Expand Up @@ -99,11 +100,9 @@ export class CompendiumBrowserFeatTab extends CompendiumBrowserTab {
}

// Prepare source
const source = featData.system.source.value;
const sourceSlug = sluggify(source);
if (source) {
sources.add(source);
}
const pubSource = featData.system.publication?.title ?? featData.system.source?.value ?? "";
const sourceSlug = sluggify(pubSource);
if (pubSource) publications.add(pubSource);

// Only store essential data
feats.push({
Expand All @@ -129,7 +128,7 @@ export class CompendiumBrowserFeatTab extends CompendiumBrowserTab {
this.filterData.checkboxes.category.options = this.generateCheckboxOptions(CONFIG.PF2E.featCategories);
this.filterData.checkboxes.skills.options = this.generateCheckboxOptions(CONFIG.PF2E.skillList);
this.filterData.checkboxes.rarity.options = this.generateCheckboxOptions(CONFIG.PF2E.rarityTraits);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(sources);
this.filterData.checkboxes.source.options = this.generateSourceCheckboxOptions(publications);
this.filterData.multiselects.traits.options = this.generateMultiselectOptions(CONFIG.PF2E.featTraits);

console.debug("PF2e System | Compendium Browser | Finished loading feats");
Expand Down
Loading

0 comments on commit 3e0f172

Please sign in to comment.