Skip to content

Commit

Permalink
Merge pull request #133 from darthbeep/json-importer
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGiddyLimit authored Sep 21, 2022
2 parents 18ab299 + 7d10b25 commit ad6fd3f
Show file tree
Hide file tree
Showing 14 changed files with 1,013 additions and 985 deletions.
2 changes: 1 addition & 1 deletion js/5etools-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const betteR205etools = function () {

d20plus.bindDropLocations();
d20plus.ui.addHtmlHeader();
d20plus.addCustomHTML();
d20plus.template5e.addCustomHTML();
d20plus.ui.addHtmlFooter();
d20plus.engine.enhanceMarkdown();
d20plus.engine.addProFeatures();
Expand Down
94 changes: 53 additions & 41 deletions js/5etools-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ function d20plusClass () {
}
};

d20plus.classes.getDataForImport = async function (oldData) {
await d20plus.importer.pAddBrew(oldData);
const data = MiscUtil.copy(oldData);
data.class = data.class || [];
for (let i = 0; i < data.class.length; ++i) {
data.class[i] = await DataUtil.class.pGetDereferencedClassData(data.class[i]);
}

if (data.subclass) {
for (let i = 0; i < data.subclass.length; ++i) {
data.subclass[i] = await DataUtil.class.pGetDereferencedSubclassData(data.subclass[i]);
}
}

d20plus.classes._doAttachChildSubclasses(data);

return data;
}

// Import Classes button was clicked
d20plus.classes.button = function (forcePlayer) {
const playerMode = forcePlayer || !window.is_gm;
Expand All @@ -30,23 +49,9 @@ function d20plusClass () {
const officialClassUrls = Object.values(classDataUrls).map(v => d20plus.formSrcUrl(CLASS_DATA_DIR, v));

DataUtil.loadJSON(url).then(async (data) => {
await d20plus.importer.pAddBrew(data);

if (!data.class) return;

data = MiscUtil.copy(data);
data.class = data.class || [];
for (let i = 0; i < data.class.length; ++i) {
data.class[i] = await DataUtil.class.pGetDereferencedClassData(data.class[i]);
}

if (data.subclass) {
for (let i = 0; i < data.subclass.length; ++i) {
data.subclass[i] = await DataUtil.class.pGetDereferencedSubclassData(data.subclass[i]);
}
}

d20plus.classes._doAttachChildSubclasses(data);
data = await d20plus.classes.getDataForImport(data);

d20plus.importer.showImportList(
"class",
Expand Down Expand Up @@ -503,6 +508,37 @@ function d20plusClass () {
source: Parser.sourceJsonToAbv(sc.source).toLowerCase(),
};
};

d20plus.subclasses.getDataForImport = async function (data) {
await d20plus.importer.pAddBrew(data);

data = MiscUtil.copy(data);
for (let i = 0; i < (data.class || []).length; ++i) {
data.class[i] = await DataUtil.class.pGetDereferencedClassData(data.class[i]);
}
for (let i = 0; i < (data.subclass || []).length; ++i) {
data.subclass[i] = await DataUtil.class.pGetDereferencedSubclassData(data.subclass[i]);
}

// merge in any subclasses contained in class data
const allData = MiscUtil.copy(data.subclass || []);
(data.class || []).map(c => {
if (c.subclasses) {
// make a copy without subclasses to prevent circular references
const cpy = MiscUtil.copy(c);
delete cpy.subclasses;
c.subclasses.forEach(sc => {
sc.className = c.name;
sc.source = sc.source || c.source;
sc._baseClass = cpy;
});
return c.subclasses;
} else return false;
}).filter(Boolean).forEach(sc => allData.push(sc));

return allData.flat();
}

// Import Subclasses button was clicked
d20plus.subclasses.button = function (forcePlayer) {
const playerMode = forcePlayer || !window.is_gm;
Expand All @@ -511,35 +547,11 @@ function d20plusClass () {
const handoutBuilder = playerMode ? d20plus.subclasses.playerImportBuilder : d20plus.subclasses.handoutBuilder;

DataUtil.loadJSON(url).then(async (data) => {
await d20plus.importer.pAddBrew(data);

data = MiscUtil.copy(data);
for (let i = 0; i < (data.class || []).length; ++i) {
data.class[i] = await DataUtil.class.pGetDereferencedClassData(data.class[i]);
}
for (let i = 0; i < (data.subclass || []).length; ++i) {
data.subclass[i] = await DataUtil.class.pGetDereferencedSubclassData(data.subclass[i]);
}

// merge in any subclasses contained in class data
const allData = MiscUtil.copy(data.subclass || []);
(data.class || []).map(c => {
if (c.subclasses) {
// make a copy without subclasses to prevent circular references
const cpy = MiscUtil.copy(c);
delete cpy.subclasses;
c.subclasses.forEach(sc => {
sc.className = c.name;
sc.source = sc.source || c.source;
sc._baseClass = cpy;
});
return c.subclasses;
} else return false;
}).filter(Boolean).forEach(sc => allData.push(sc));
const allData = await d20plus.subclasses.getDataForImport(data);

d20plus.importer.showImportList(
"subclass",
allData.flat(),
allData,
handoutBuilder,
{
groupOptions: d20plus.subclasses._groupOptions,
Expand Down
108 changes: 108 additions & 0 deletions js/5etools-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
function css5eTool () {
d20plus.css.cssRules = d20plus.css.cssRules.concat([
{
s: ".no-shrink",
r: "flex-shrink: 0;",
},
{
s: "#initiativewindow ul li span.initiative,#initiativewindow ul li span.tracker-col,#initiativewindow ul li span.initmacro",
r: "font-size: 25px;font-weight: bold;text-align: right;float: right;padding: 2px 5px;width: 10%;min-height: 20px;display: block;",
},
{
s: "#initiativewindow ul li span.editable input",
r: "width: 100%; box-sizing: border-box;height: 100%;",
},
{
s: "#initiativewindow div.header",
r: "height: 30px;",
},
{
s: "#initiativewindow div.header span",
r: "cursor: default;font-size: 15px;font-weight: bold;text-align: right;float: right;width: 10%;min-height: 20px;padding: 5px;",
},
{
s: ".ui-dialog-buttonpane span.difficulty",
r: "display: inline-block;padding: 5px 4px 6px;margin: .5em .4em .5em 0;font-size: 18px;",
},
{
s: ".ui-dialog-buttonpane.buttonpane-absolute-position",
r: "position: absolute;bottom: 0;box-sizing: border-box;width: 100%;",
},
{
s: ".ui-dialog.dialog-collapsed .ui-dialog-buttonpane",
r: "position: initial;",
},
{
s: ".token .cr,.header .cr",
r: "display: none!important;",
},
{
s: "li.handout.compendium-item .namecontainer",
r: "box-shadow: inset 0px 0px 25px 2px rgb(195, 239, 184);",
},
{
s: ".bind-drop-locations:active",
r: "box-shadow: inset 0px 0px 25px 2px rgb(195, 239, 184);",
},
{
s: "del.userscript-hidden",
r: "display: none;",
},
{
s: ".importer-section",
r: "display: none;",
},
{
s: ".userscript-rd__h",
r: "font-weight: bold;",
},
{
s: ".userscript-rd__h--0",
r: "font-weight: bold; font-size: 1.5em;",
},
{
s: ".userscript-rd__h--2",
r: "font-weight: bold; font-size: 1.3em;",
},
{
s: ".userscript-rd__h--3, .userscript-rd__h--4",
r: "font-style: italic",
},
{
s: ".userscript-rd__b-inset--readaloud",
r: "background: #cbd6c688 !important",
},
// "No character sheet" message
{
s: ".ve-nosheet__body",
r: "overflow: hidden !important;",
},
{
s: ".ve-nosheet__overlay",
r: `
background: darkred;
position: fixed;
z-index: 99999;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100vw;
height: 100vh;
color: white;
font-family: monospace;`,
},
{
s: ".ve-nosheet__title",
r: "font-size: 72px;",
},
{
s: ".ve-nosheet__btn-close",
r: `position: absolute;
top: 8px;
right: 8px;
font-size: 16px;`,
},
]);
}
SCRIPT_EXTENSIONS.push(css5eTool);
2 changes: 1 addition & 1 deletion js/5etools-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function d20plusImporter () {
character.abilities.create({
name: `${prefix + index}: ${name}`,
istokenaction: true,
action: d20plus.actionMacroAction(baseAction, index),
action: d20plus.macro.actionMacroAction(baseAction, index),
}).save();
}

Expand Down
Loading

0 comments on commit ad6fd3f

Please sign in to comment.