5etools-utils 0.16.37 → 0.16.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,7 @@ export class BrewTesterEdition extends BrewTesterBase {
13
13
  _LOG_TAG = "EDITION";
14
14
 
15
15
  static _EDITION_CLASSIC = "classic";
16
+ static _EDITION_ONE = "one";
16
17
 
17
18
  // TODO(Future) this is non-exhaustive; we do not check e.g. `item.attachedSpells`
18
19
  // Generalize an "entity -> used UIDs" system to use both here and in other tests
@@ -74,6 +75,32 @@ export class BrewTesterEdition extends BrewTesterBase {
74
75
 
75
76
  /* -------------------------------------------- */
76
77
 
78
+ static _getSpellClassSourceErrors ({filePath, json, sourceToEdition}) {
79
+ const edition = json._meta?.edition || this._EDITION_CLASSIC;
80
+
81
+ return (json.spell || [])
82
+ .flatMap(spell => {
83
+ return [
84
+ ...(spell.classes?.fromClassList || [])
85
+ .map(classMeta => ({prop: "fromClassList", classMeta})),
86
+ ...(spell.classes?.fromClassListVariant || [])
87
+ .map(classMeta => ({prop: "fromClassListVariant", classMeta})),
88
+ ...(spell.classes?.fromSubclass || [])
89
+ .map(({class: classMeta}) => ({prop: "fromSubclass", classMeta})),
90
+ ]
91
+ .map(({prop, classMeta}) => {
92
+ const editionClass = sourceToEdition[classMeta.source.toLowerCase()];
93
+ if (!editionClass) return null;
94
+ if (editionClass === edition) return null;
95
+
96
+ return `${filePath} spell "${spell.name}" (${spell.source}) from edition "${edition}" had ${prop} "${classMeta.name}" (${classMeta.source}) from edition "${editionClass}"!`;
97
+ })
98
+ .filter(Boolean);
99
+ });
100
+ }
101
+
102
+ /* -------------------------------------------- */
103
+
77
104
  async _pRun () {
78
105
  Um.info(this._LOG_TAG, `Checking sources used...`);
79
106
 
@@ -82,6 +109,12 @@ export class BrewTesterEdition extends BrewTesterBase {
82
109
  schemaSources.$defs.sourcesModern.enum
83
110
  .map(src => [src.toLowerCase(), src]),
84
111
  );
112
+ const sourceToEdition = Object.fromEntries([
113
+ ...schemaSources.$defs.sourcesClassic.enum
114
+ .map(src => [src.toLowerCase(), this.constructor._EDITION_CLASSIC]),
115
+ ...schemaSources.$defs.sourcesModern.enum
116
+ .map(src => [src.toLowerCase(), this.constructor._EDITION_ONE]),
117
+ ]);
85
118
 
86
119
  const results = [];
87
120
  Uf.runOnDirs((dir) => {
@@ -94,6 +127,8 @@ export class BrewTesterEdition extends BrewTesterBase {
94
127
 
95
128
  const json = JSON.parse(fs.readFileSync(filePath, "utf-8"));
96
129
 
130
+ results.push(...this.constructor._getSpellClassSourceErrors({filePath, json, sourceToEdition}));
131
+
97
132
  if (json._meta?.edition !== this.constructor._EDITION_CLASSIC) return;
98
133
 
99
134
  const sourcesUsedModern = this.constructor._getSourcesUsed({filePath, json})
@@ -107,7 +142,7 @@ export class BrewTesterEdition extends BrewTesterBase {
107
142
 
108
143
  if (results.length) {
109
144
  results.forEach(r => Um.error(this._LOG_TAG, r));
110
- throw new Error(`${results.length} file${results.length === 1 ? ` used modern source(s) but was marked as "edition": ${this.constructor._EDITION_CLASSIC}"!` : `s used modern source(s) but were marked as "edition": ${this.constructor._EDITION_CLASSIC}"!`} See above for more info.`);
145
+ throw new Error(`${results.length} source edition error${results.length === 1 ? "" : "s"}! See above for more info.`);
111
146
  }
112
147
 
113
148
  Um.info(this._LOG_TAG, `Complete.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.16.37",
3
+ "version": "0.16.38",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",