This commit is contained in:
TheGiddyLimit
2024-02-11 22:28:07 +00:00
parent d16f838683
commit 661a119c6d
106 changed files with 6046 additions and 1330 deletions

View File

@@ -0,0 +1,35 @@
import "../js/parser.js";
import "../js/utils.js";
import * as ut from "../node/util.js";
const _BLOCKLIST_SOURCES = new Set([
Parser.SRC_SCREEN,
Parser.SRC_SCREEN_WILDERNESS_KIT,
Parser.SRC_SCREEN_DUNGEON_KIT,
Parser.SRC_SCREEN_SPELLJAMMER,
]);
async function main () {
console.log(`##### Validating adventure/book credits #####`);
[
{filename: "adventures.json", prop: "adventure"},
{filename: "books.json", prop: "book"},
]
.map(({filename, prop}) => {
const json = ut.readJson(`./data/${filename}`);
const noCredits = json[prop]
.filter(meta => {
if (_BLOCKLIST_SOURCES.has(meta.source)) return false;
return meta.contents && !meta.contents.some(it => it.name === "Credits");
});
if (!noCredits.length) return;
console.error(`\nMissing "Credits" chapters in "${filename}":\n${noCredits.map(meta => `\t${meta.source}`).join("\n")}`);
});
return true;
}
export default main();

View File

@@ -1,11 +1,57 @@
import "../js/parser.js";
import "../js/utils.js";
import * as ut from "../node/util.js";
import {BLOCKLIST_SOURCES_PAGES} from "./util-test.js";
function getErrorMonotonicallyIncreasing ({walker, filename, json, source}) {
const stack = [];
let pagePrev = -1;
const errorsFile = [];
walker.walk(
json,
{
object: (obj) => {
if (obj.page == null || typeof obj.page !== "number") return;
if (obj.page < pagePrev) {
const id = obj.id || [...stack].reverse().find(it => it.id)?.id;
const name = obj.name || [...stack].reverse().find(it => it.name)?.name;
errorsFile.push(`Previous page ${pagePrev} > ${obj.page}${id || name ? ` (at or near ${[id ? `id "${id}"` : "", name ? `name "${name}"` : ""].filter(Boolean).join("; ")})` : ""}`);
}
pagePrev = obj.page;
},
},
null,
stack,
);
if (!errorsFile.length) return null;
return `Page numbers were not monotonically increasing in "${filename}":\n${errorsFile.map(err => `\t${err}\n`).join("")}\n`;
}
// TODO(Future) could e.g. objects; count pages; if ratio below threshold then error
function getErrorNoPages ({walker, filename, json, source}) {
if (BLOCKLIST_SOURCES_PAGES.has(source)) return null;
let hasPage = false;
walker.walk(
json,
{
object: (obj) => {
if (obj.page != null && (typeof obj.page !== "number" || obj.page !== 0)) return hasPage = true;
},
},
);
if (hasPage) return null;
return `No page numbers found in "${filename}"\n`;
}
async function main () {
console.log(`##### Validating adventure/book page numbers #####`);
const walker = MiscUtil.getWalker({isNoModification: true});
const walker = MiscUtil.getWalker({isNoModification: true, isBreakOnReturn: true});
const errors = [];
@@ -13,34 +59,18 @@ async function main () {
{filename: "adventures.json", prop: "adventure", dir: "adventure"},
{filename: "books.json", prop: "book", dir: "book"},
].flatMap(({filename, prop, dir}) => ut.readJson(`./data/${filename}`)[prop]
.map(({id}) => `./data/${dir}/${dir}-${id.toLowerCase()}.json`))
.forEach(filename => {
const stack = [];
let pagePrev = -1;
const errorsFile = [];
.map(({id, source}) => ({
filename: `./data/${dir}/${dir}-${id.toLowerCase()}.json`,
source,
})))
.forEach(({filename, source}) => {
const json = ut.readJson(filename);
walker.walk(
ut.readJson(filename),
{
object: (obj) => {
if (obj.page == null || typeof obj.page !== "number") return obj;
if (obj.page < pagePrev) {
const id = obj.id || [...stack].reverse().find(it => it.id)?.id;
const name = obj.name || [...stack].reverse().find(it => it.name)?.name;
errorsFile.push(`Previous page ${pagePrev} > ${obj.page}${id || name ? ` (at or near ${[id ? `id "${id}"` : "", name ? `name "${name}"` : ""].filter(Boolean).join("; ")})` : ""}`);
}
pagePrev = obj.page;
const errorMonotonicallyIncreasing = getErrorMonotonicallyIncreasing({walker, filename, json, source});
if (errorMonotonicallyIncreasing) errors.push(errorMonotonicallyIncreasing);
return obj;
},
},
null,
stack,
);
if (!errorsFile.length) return;
errors.push(`Page numbers were not monotonically increasing in "${filename}":\n${errorsFile.map(err => `\t${err}\n`).join("")}\n`);
const errorNoPages = getErrorNoPages({walker, filename, json, source});
if (errorNoPages) errors.push(errorNoPages);
});
if (errors.length) {

View File

@@ -3,6 +3,7 @@ import * as rl from "readline-sync";
import * as fs from "fs";
import "../js/parser.js";
import "../js/utils.js";
import {BLOCKLIST_SOURCES_PAGES} from "./util-test.js";
const BLOCKLIST_FILE_PREFIXES = [
...ut.FILE_PREFIX_BLOCKLIST,
@@ -33,30 +34,6 @@ const BLOCKLIST_KEYS = new Set([
"dragonMundaneItems",
]);
const BLOCKLIST_SOURCES = new Set([
// region Sources which only exist in digital form
Parser.SRC_DC,
Parser.SRC_SLW,
Parser.SRC_SDW,
Parser.SRC_VD,
Parser.SRC_HAT_TG,
Parser.SRC_HAT_LMI,
Parser.SRC_LK,
Parser.SRC_AATM,
Parser.SRC_HFStCM,
// N.b.: other MCV source creatures mysteriously have page numbers on Beyond
Parser.SRC_MCV4EC,
// endregion
// region Sources which are screens, and therefore "pageless"
Parser.SRC_SCREEN,
Parser.SRC_SCREEN_WILDERNESS_KIT,
Parser.SRC_SCREEN_DUNGEON_KIT,
Parser.SRC_SCREEN_SPELLJAMMER,
// endregion
]);
const SUB_KEYS = {};
function run ({isModificationMode = false} = {}) {
@@ -74,7 +51,7 @@ function run ({isModificationMode = false} = {}) {
const data = json[k];
if (data instanceof Array) {
const noPage = data
.filter(it => !BLOCKLIST_SOURCES.has(SourceUtil.getEntitySource(it)))
.filter(it => !BLOCKLIST_SOURCES_PAGES.has(SourceUtil.getEntitySource(it)))
.filter(it => !(it.inherits ? it.inherits.page : it.page))
.filter(it => !it._copy?._preserve?.page);
@@ -90,7 +67,7 @@ function run ({isModificationMode = false} = {}) {
noPage.push(...subArr
// Skip un-named entries, as these are usually found on the page of their parent
.filter(subIt => subIt.name)
.filter(subIt => !BLOCKLIST_SOURCES.has(subIt.source))
.filter(subIt => !BLOCKLIST_SOURCES_PAGES.has(subIt.source))
.filter(subIt => !subIt.page));
});
});

26
test/util-test.js Normal file
View File

@@ -0,0 +1,26 @@
import "../js/parser.js";
import "../js/utils.js";
export const BLOCKLIST_SOURCES_PAGES = new Set([
// region Sources which only exist in digital form
Parser.SRC_DC,
Parser.SRC_SLW,
Parser.SRC_SDW,
Parser.SRC_VD,
Parser.SRC_HAT_TG,
Parser.SRC_HAT_LMI,
Parser.SRC_LK,
Parser.SRC_AATM,
Parser.SRC_HFStCM,
// N.b.: other MCV source creatures mysteriously have page numbers on Beyond
Parser.SRC_MCV4EC,
// endregion
// region Sources which are screens, and therefore "pageless"
Parser.SRC_SCREEN,
Parser.SRC_SCREEN_WILDERNESS_KIT,
Parser.SRC_SCREEN_DUNGEON_KIT,
Parser.SRC_SCREEN_SPELLJAMMER,
// endregion
]);