"use strict";
class RenderSpells {
static SETTINGS = {
isDisplayGroups: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Groups",
help: `Whether or not "Groups" should be shown for a spell.`,
defaultVal: true,
}),
isDisplayClasses: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Classes",
help: `Whether or not "Classes" should be shown for a spell.`,
defaultVal: true,
}),
isDisplayClassesLegacy: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Classes (Legacy)",
help: `Whether or not "Classes (legacy)" should be shown for a spell.`,
defaultVal: false,
}),
isDisplaySubclasses: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Subclasses",
help: `Whether or not "Subclasses" should be shown for a spell.`,
defaultVal: true,
}),
isDisplaySubclassesLegacy: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Subclasses (Legacy)",
help: `Whether or not "Subclasses (legacy)" should be shown for a spell.`,
defaultVal: false,
}),
isDisplayVariantClasses: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Optional/Variant Classes",
help: `Whether or not "Optional/Variant Classes" should be shown for a spell.`,
defaultVal: true,
}),
isDisplayVariantClassesLegacy: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Optional/Variant Classes (Legacy)",
help: `Whether or not "Optional/Variant Classes (legacy)" should be shown for a spell.`,
defaultVal: false,
}),
isDisplayRaces: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Races",
help: `Whether or not "Races" should be shown for a spell.`,
defaultVal: true,
}),
isDisplayBackgrounds: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Backgrounds",
help: `Whether or not "Backgrounds" should be shown for a spell.`,
defaultVal: true,
}),
isDisplayFeats: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Show Feats",
help: `Whether or not "Feats" should be shown for a spell.`,
defaultVal: true,
}),
isDisplayOptionalfeatures: new SettingsUtil.Setting({
type: "boolean",
name: "Spell Sources: Other Options/Features",
help: `Whether or not "Other Options/Features" should be shown for a spell.`,
defaultVal: true,
}),
};
static $getRenderedSpell (sp, subclassLookup, {isSkipExcludesRender = false, settings} = {}) {
if (settings == null) settings = SettingsUtil.getDefaultSettings(this.SETTINGS);
const renderer = Renderer.get();
const renderStack = [];
renderer.setFirstSection(true);
renderStack.push(`
${Renderer.utils.getBorderTr()}
${!isSkipExcludesRender ? Renderer.utils.getExcludedTr({entity: sp, dataProp: "spell", page: UrlUtil.PG_SPELLS}) : ""}
${Renderer.utils.getNameTr(sp, {page: UrlUtil.PG_SPELLS})}
| ${Parser.spLevelSchoolMetaToFull(sp.level, sp.school, sp.meta, sp.subschools)} |
| Casting Time: ${Parser.spTimeListToFull(sp.time)} |
| Range: ${Parser.spRangeToFull(sp.range)} |
| Components: ${Parser.spComponentsToFull(sp.components, sp.level)} |
| Duration: ${Parser.spDurationToFull(sp.duration)} |
${Renderer.utils.getDividerTr()}
`);
const entryList = {type: "entries", entries: sp.entries};
renderStack.push(`| `);
renderer.recursiveRender(entryList, renderStack, {depth: 1});
if (sp.entriesHigherLevel) {
const higherLevelsEntryList = {type: "entries", entries: sp.entriesHigherLevel};
renderer.recursiveRender(higherLevelsEntryList, renderStack, {depth: 2});
}
renderStack.push(` |
`);
const stackFroms = [];
if (settings.isDisplayGroups) this._mutStackPtSpellSource({sp, stackFroms, renderer, title: "Groups", propSpell: "groups"});
const fromClassList = Renderer.spell.getCombinedClasses(sp, "fromClassList");
if (fromClassList.length) {
const [current, legacy] = Parser.spClassesToCurrentAndLegacy(fromClassList);
if (settings.isDisplayClasses) {
stackFroms.push(`Classes: ${Parser.spMainClassesToFull(current)}
`);
}
if (settings.isDisplayClassesLegacy && legacy.length) {
stackFroms.push(`Classes (legacy): ${Parser.spMainClassesToFull(legacy)}
`);
}
}
const fromSubclass = Renderer.spell.getCombinedClasses(sp, "fromSubclass");
if (fromSubclass.length) {
const [current, legacy] = Parser.spSubclassesToCurrentAndLegacyFull(sp, subclassLookup);
if (settings.isDisplaySubclasses) {
stackFroms.push(`Subclasses: ${current}
`);
}
if (settings.isDisplaySubclassesLegacy && legacy.length) {
stackFroms.push(`Subclasses (legacy): ${legacy}
`);
}
}
const fromClassListVariant = Renderer.spell.getCombinedClasses(sp, "fromClassListVariant");
if (fromClassListVariant.length) {
const [current, legacy] = Parser.spVariantClassesToCurrentAndLegacy(fromClassListVariant);
if (settings.isDisplayVariantClasses && current.length) {
stackFroms.push(`Optional/Variant Classes: ${Parser.spMainClassesToFull(current)}
`);
}
if (settings.isDisplayVariantClassesLegacy && legacy.length) {
stackFroms.push(`Optional/Variant Classes (legacy): ${Parser.spMainClassesToFull(legacy)}
`);
}
}
if (settings.isDisplayRaces) this._mutStackPtSpellSource({sp, stackFroms, renderer, title: "Races", propSpell: "races", prop: "race", tag: "race"});
if (settings.isDisplayBackgrounds) this._mutStackPtSpellSource({sp, stackFroms, renderer, title: "Backgrounds", propSpell: "backgrounds", prop: "background", tag: "background"});
if (settings.isDisplayFeats) this._mutStackPtSpellSource({sp, stackFroms, renderer, title: "Feats", propSpell: "feats", prop: "feat", tag: "feat"});
if (settings.isDisplayOptionalfeatures) this._mutStackPtSpellSource({sp, stackFroms, renderer, title: "Other Options/Features", propSpell: "optionalfeatures", prop: "optionalfeature", tag: "optfeature"});
if (stackFroms.length) {
renderStack.push(`| ${stackFroms.join("")} |
`);
}
if (
sp.level >= 5
&& fromClassList?.some(it => it.name === "Wizard" && it?.source === Parser.SRC_PHB)
) {
renderStack.push(`| `);
renderer.recursiveRender(`{@italic Note: Both the {@class fighter||Fighter (Eldritch Knight)|eldritch knight} and the {@class rogue||Rogue (Arcane Trickster)|arcane trickster} spell lists include all {@class Wizard} spells. Spells of 5th level or higher may be cast with the aid of a spell scroll or similar.}`, renderStack, {depth: 2});
renderStack.push(` |
`);
}
renderStack.push(`
${Renderer.utils.getPageTr(sp)}
${Renderer.utils.getBorderTr()}
`);
return $(renderStack.join(""));
}
static _mutStackPtSpellSource ({sp, stackFroms, renderer, title, propSpell, prop, tag}) {
const froms = Renderer.spell.getCombinedGeneric(sp, {propSpell, prop});
if (!froms.length) return;
const ptFroms = froms
.map(it => {
const pt = tag ? renderer.render(`{@${tag} ${it.name}|${it.source}}`) : `${it.name}`;
return `${SourceUtil.isNonstandardSource(it.source) ? `` : ``}${pt}${SourceUtil.isNonstandardSource(it.source) ? `` : ``}`;
})
.join(", ");
stackFroms.push(`${title}: ${ptFroms}
`);
}
}