Skip to content

Commit

Permalink
V10 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jessev14 committed Sep 6, 2022
1 parent 0740adf commit b4ab69b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 130 deletions.
82 changes: 0 additions & 82 deletions lib/shim.js

This file was deleted.

31 changes: 27 additions & 4 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
{
"name": "custom-character-sheet-sections",
"id": "custom-character-sheet-sections",
"title": "Custom Character Sheet Sections",
"description": "",
"author": "enso#0361",
"version": "1.0.0",
"minimumCoreVersion": "9",
"compatibleCoreVersion": "9",
"compatibility": {
"minimum": "10",
"verified": "10"
},
"relationships": {
"systems": [
{
"id": "dnd5e",
"type": "system",
"compatibility": {
"minimum": "2.0.0",
"verified": "2.0.0"
}
}
],
"requires": [
{
"id": "lib-wrapper",
"type": "module",
"compatibility": {
"minimum": "1",
"verified": "1.12.7.1"
}
}
]
},
"esmodules": [
"./scripts/custom-character-sheet-sections.js"
],
Expand All @@ -19,5 +43,4 @@
"url": "https://github.com/jessev14/custom-character-sheet-sections",
"manifest": "https://github.com/jessev14/custom-character-sheet-sections/releases/latest/download/module.json",
"download": "https://github.com/jessev14/custom-character-sheet-sections/releases/download/1.0.0/CCSS.zip"

}
65 changes: 21 additions & 44 deletions scripts/custom-character-sheet-sections.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
import { libWrapper } from "../lib/shim.js";

const moduleName = "custom-character-sheet-sections";
const moduleID = "custom-character-sheet-sections";


Hooks.once("ready", () => {
libWrapper.register(moduleName, "CONFIG.Actor.sheetClasses.character['dnd5e.ActorSheet5eCharacter'].cls.prototype.getData", customSectionGetData, "WRAPPER");
libWrapper.register(moduleID, "CONFIG.Actor.sheetClasses.character['dnd5e.ActorSheet5eCharacter'].cls.prototype.getData", customSectionGetData, "WRAPPER");
});


Hooks.on("renderItemSheet", (app, html, appData) => {
const custom2 = `
<div class="form-group" style="border: 1px solid var(--faint-color); border-radius: 5px; flex-direction: column;">
<label>${game.i18n.localize(`${moduleName}.customSection`)}</label>
<input style="text-align: left;" type="text" name="flags.${moduleName}.sectionName" value="${app.object.data.flags[moduleName]?.sectionName || ""}" />
</div>
Hooks.on("renderItemSheet", (app, [html], appData) => {
const customSectionInput = document.createElement('div');
customSectionInput.classList.add('form-group');
customSectionInput.style.cssText = `
border: 1px solid var(--faint-color);
border-radius: 5px;
flex-direction: column;
`;
html.find(`div.item-properties`).append(custom2);

return;

// Inject input element into Item sheets to input custom section name
const customSectionInput = `
<h3 class="form-header">${game.i18n.localize(`${moduleName}.customSection`)}</h3>
<div class="form-group">
<label>${game.i18n.localize(`${moduleName}.sectionName`)}</label>
<div class="form-fields">
<input type="text" name="flags.${moduleName}.sectionName" value="${app.object.data.flags[moduleName]?.sectionName || ""}" />
</div>
</div>
customSectionInput.innerHTML = `
<label>${game.i18n.localize(`${moduleID}.customSection`)}</label>
<input style="text-align: left;" type="text" name="flags.${moduleID}.sectionName" value="${app.object.flags[moduleID]?.sectionName || ""}" />
`;
html.querySelector(`div.item-properties`).appendChild(customSectionInput);

html.find(`div.tab.details`).append(customSectionInput);
return;
});

Hooks.on("renderActorSheet5eCharacter", (app, html, appData) => {
Expand All @@ -46,31 +36,18 @@ Hooks.on("renderActorSheet5eCharacter", (app, html, appData) => {
const prevItem = app.object.items.get(prevItemLi?.data("itemId"));

const item = firstItem || prevItem;
const customSectionName = item?.getFlag(moduleName, "sectionName");
const customSectionName = item?.getFlag(moduleID, "sectionName");
if (!customSectionName) return;

$(this).remove();
return;

/*
// Add Item buttons create new item with pre-set custom section // Only works for Features; Inventory items pull a type from the header element
$(this).click(function(event) {
Hooks.once("preCreateItem", (item, data, options, userID) => {
item.data.update({
flags: {
[moduleName]: { sectionName: customSectionName }
}
});
});
});
*/
});
});


function customSectionGetData(wrapped) {
async function customSectionGetData(wrapped) {
// Call wrapped function to get appData
const data = wrapped();
const data = await wrapped();

// Loop for Feature-type items, Inventory items, and Spell-type items
for (const type of ["features", "inventory", "spellbook"]) {
Expand All @@ -85,11 +62,11 @@ function customSectionGetData(wrapped) {


// Get items flagged with a custom section
const customSectionItems = items.filter(i => i.flags[moduleName]?.sectionName);
const customSectionItems = items.filter(i => i.flags[moduleID]?.sectionName);
// Create array of custom section names
const customSections = [];
for (const item of customSectionItems) {
if (!customSections.includes(item.flags[moduleName].sectionName)) customSections.push(item.flags[moduleName].sectionName);
if (!customSections.includes(item.flags[moduleID].sectionName)) customSections.push(item.flags[moduleID].sectionName);
}

// For items flagged with a custom section, remove them from their original section
Expand All @@ -101,7 +78,7 @@ function customSectionGetData(wrapped) {
for (const customSection of customSections) {
const newSection = {
label: customSection,
[itemsSpells]: customSectionItems.filter(i => i.flags[moduleName].sectionName === customSection)
[itemsSpells]: customSectionItems.filter(i => i.flags[moduleID].sectionName === customSection)
};
if (type === "features") {
newSection.hasActions = true;
Expand All @@ -110,7 +87,7 @@ function customSectionGetData(wrapped) {
} else if (type === "inventory") {

} else if (type === "spellbook") {
//newSection.spells = customSectionItems.filter(i => i.flags[moduleName].sectionName === customSection);
//newSection.spells = customSectionItems.filter(i => i.flags[moduleID].sectionName === customSection);
newSection.canCreate = false;
newSection.canPrepare = true;
newSection.dataset = {
Expand Down

0 comments on commit b4ab69b

Please sign in to comment.