From 1fd1898573c349bb485bb78611217f7515c545dd Mon Sep 17 00:00:00 2001 From: Jack Holloway Date: Sat, 6 Aug 2022 12:17:00 +0100 Subject: [PATCH] v0.0.19 --- CHANGELOG.md | 5 +++++ index.js | 6 +++++- package.json | 2 +- spells.js | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f81f3..e0accdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.0.19 + +* Prevent legacy checkbox excluding homebrew. +* If homebrew was disabled on the character, it would still add homebrew spells to the characters available selection. + # 0.0.18 * Some more clauses to try and stop issue #18 when it can't find a cobalt. diff --git a/index.js b/index.js index 12469ee..bf46ef0 100644 --- a/index.js +++ b/index.js @@ -208,6 +208,10 @@ app.post(["/proxy/character", "/proxy/v5/character"], cors(), express.json(), (r : []; return spells.getSpellAdditions(result, spellListIds, cobaltId); }) + .then((result) => { + const includeHomebrew = result.character.preferences.useHomebrewContent; + return spells.filterHomebrew(result, includeHomebrew); + }) .then((data) => { data = filterModifiers(data); return { success: true, messages: ["Character successfully received."], ddb: data }; @@ -258,7 +262,7 @@ app.post(getMonsterProxyRoutes, cors(), express.json(), (req, res) => { .extractMonsters(cacheId, searchTerm, homebrew, homebrewOnly, sources) .then((data) => { if (excludeLegacy) { - const filteredMonsters = data.filter((monster) => !monster.isHomebrew && !monster.isLegacy); + const filteredMonsters = data.filter((monster) => !monster.isLegacy); return filteredMonsters; } else { return data; diff --git a/package.json b/package.json index c649055..c305c22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ddb-proxy", - "version": "0.0.18", + "version": "0.0.19", "main": "index.js", "license": "MIT", "scripts": { diff --git a/spells.js b/spells.js index 42f2afe..1b77e56 100644 --- a/spells.js +++ b/spells.js @@ -263,5 +263,23 @@ function getSpellAdditions(data, spellListIds, cacheId) { }); } +function filterHomebrew(data, includeHomebrew) { + if (includeHomebrew) { + return data; + } else { + data.character.classSpells = data.character.classSpells.map((classSpells) => { + classSpells.spells = classSpells.spells.filter(spell => !spell.definition.isHomebrew); + return classSpells; + }); + data.character.spells.class = data.character.spells.class.filter(spell => !spell.definition.isHomebrew); + data.character.spells.race = data.character.spells.race.filter(spell => !spell.definition.isHomebrew); + data.character.spells.feat = data.character.spells.feat.filter(spell => !spell.definition.isHomebrew); + data.character.spells.item = data.character.spells.item.filter(spell => !spell.definition.isHomebrew); + return data; + } +} + + exports.loadSpells = loadSpells; exports.getSpellAdditions = getSpellAdditions; +exports.filterHomebrew = filterHomebrew;