Skip to content

Commit

Permalink
Setup all done
Browse files Browse the repository at this point in the history
Need to re-implement the loot/buy functionality
  • Loading branch information
jopeek committed Sep 25, 2024
1 parent dbe6442 commit cb55fc9
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 127 deletions.
41 changes: 34 additions & 7 deletions css/lootsheet-simple.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,39 @@
z-index: 3;
}

/* .loot-sheet-npc nav.tabs .item i:first-of-type {
display: none; /* Hides the first icon */
.loot-sheet-npc label.slide-toggle {
float: right;
}

.loot-sheet-npc nav.tabs .item:first-of-type::before {
content: '\f03a'; /* Unicode of the new icon */
font-family: 'FontAwesome'; /* Set the correct font if necessary */
/* Additional styles to adjust position, size, etc. */
} */
.loot-sheet-npc .flexrow {
margin-top: 0.3rem;
margin-bottom: 0.3rem;
}

.loot-sheet-npc .pills-group {
margin-bottom: 1rem;
}

.loot-sheet-npc .permissions-list {
margin: 0;
padding-left: 1rem;
list-style: none;
}

.loot-sheet-npc li.permission {
text-indent: -0.5rem;
}

.loot-sheet-npc button.update-inventory {
color: inherit;
}

.loot-sheet-npc .currency.false,
.loot-sheet-npc .middle.false,
.loot-sheet-npc .tab.biography.active.false {
margin-left: 196px;
}

.loot-sheet-npc .tab.inventory.active.false {
padding-left: 0 !important;
}
14 changes: 7 additions & 7 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
"LOOTSHEET.TypeOfSheetHelp":"Loot: allows for looting of items and coins.\nMerchant: allows players to purchase items directly from the sheet.",
"LOOTSHEET.MerchantSettings":"Merchant Settings",
"LOOTSHEET.MerchantSettingsInfo":"Replace this merchant's inventory with a random number of items from a Rollable Table. Specify the Rollable Table's name, along with how a formula for how many different items to add (Shop Qty Formula), and a formula for determining how many of each item to add (Item Qty Formula).",
"LOOTSHEET.RollableTable":"Rollable Table:",
"LOOTSHEET.ShopFormula":"Shop Qty Formula:",
"LOOTSHEET.ItemFormula":"Item Qty Formula:",
"LOOTSHEET.LimitQty":"Limit Qty:",
"LOOTSHEET.ClearInventory":"Clear Inventory:",
"LOOTSHEET.UpdateShop":"Update Shop Inventory",
"LOOTSHEET.Permissions":"Permissions",
"LOOTSHEET.RollableTable":"Rollable Table",
"LOOTSHEET.ShopFormula":"Shop Qty Formula",
"LOOTSHEET.ItemFormula":"Item Qty Formula",
"LOOTSHEET.LimitQty":"Limit Qty",
"LOOTSHEET.ClearInventory":"Clear Inventory",
"LOOTSHEET.UpdateShop":"Update Inventory",
"LOOTSHEET.Permissions":"Access Permissions",
"LOOTSHEET.PermissionInfo":"Ensure players have selected a character via the Player Configuration (right-click player in bottom left) menu.",
"LOOTSHEET.Currency":"Currency",
"LOOTSHEET.QuantityWindow": "Quantity",
Expand Down
117 changes: 80 additions & 37 deletions lootsheet-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ class QuantityDialog extends Dialog {
}
}



class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
static SOCKET = 'module.lootsheet-simple'

Expand All @@ -89,13 +87,13 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {

Handlebars.registerHelper('ifnoteq', function (a, b, options) {
if (a != b) {
return options.fn(this);
return options.fn(this)
}
return options.inverse(this);
});
return options.inverse(this)
})

Handlebars.registerHelper('debug', function (context) {
console.log('lootsheet debug', context);
console.log('lootsheet debug', context)
})

Handlebars.registerHelper('lootsheetprice', function (basePrice, modifier) {
Expand Down Expand Up @@ -262,6 +260,18 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {

html.find('.merchant-settings').change((ev) => this._merchantSettingChange(ev))
html.find('.update-inventory').click((ev) => this._merchantInventoryUpdate(ev))
html.find('.clear-inventory.slide-toggle').click((ev) => this._clearInventoryChange(ev))

const selectRollTable = document.getElementById('lootsheet-rolltable')
const buttonUpdateInventory = document.getElementById('update-inventory')

if (selectRollTable) {
buttonUpdateInventory.disabled = !selectRollTable.value
selectRollTable.addEventListener('change', function () {
// Enable the button only if the selected value is not blank
buttonUpdateInventory.disabled = !selectRollTable.value
})
}
}

// Split Coins
Expand Down Expand Up @@ -291,24 +301,33 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
html.find('.sheet-type').change((ev) => this._changeSheetType(ev, html))

// Select the <nav> element and find all <a> elements inside it
const nav = $('.loot-sheet-npc nav.tabs');
const links = nav.find('a.item.control');
const nav = $('.loot-sheet-npc nav.tabs')
const links = nav.find('a.item.control')

// Check if the first tab's data-tab attribute is not "features"
if (links.first().attr('data-tooltip') !== 'DND5E.Inventory') {
// Move the second <a> to the first position
if (links.eq(1).length) {
links.eq(1).insertBefore(links.eq(0)) // Move the second <a> before the first <a>
}

// Move the second <a> to the first position
if (links.eq(1).length) {
links.eq(1).insertBefore(links.eq(0)); // Move the second <a> before the first <a>
}
// Move the fifth <a> to the second position
if (links.eq(4).length) {
links.eq(4).insertAfter(nav.find('a.item.control').first()) // Move the fifth <a> to after the new first <a>
}

// Move the fifth <a> to the second position
if (links.eq(4).length) {
links.eq(4).insertAfter(nav.find('a.item.control').first()); // Move the fifth <a> to after the new first <a>
}
// Remove the remaining <a> elements (original first, third, and fourth)
nav.find('a.item.control').slice(2).remove() // Remove from the third onward

// Remove the remaining <a> elements (original first, third, and fourth)
nav.find('a.item.control').slice(2).remove(); // Remove from the third onward
// Set the data-tab attribute to features
nav.find('a.item.control').first().attr('data-tab', 'features')

// Add the "active" class to the new first <a> element
nav.find('a.item.control').first().addClass('active').attr('data-tab', 'features');
// Check if no <li> elements have the 'active' class
if (!nav.find('a.active').length) {
// Add the "active" class to the new first <a> element if no other <li> is active
nav.find('a.item.control').first().addClass('active')
}
}

// Roll Table
//html.find('.sheet-type').change(ev => this._changeSheetType(ev, html));
Expand All @@ -320,7 +339,7 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
* Handle merchant settings change
* @private
*/
async _merchantSettingChange(event, html) {
async _merchantSettingChange(event) {
event.preventDefault()
// console.log("Loot Sheet | Merchant settings changed");

Expand All @@ -330,31 +349,60 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
'shopQty',
'itemQty',
'itemQtyLimit',
'clearInventory',
// 'clearInventory',
'itemOnlyOnce',
]

let targetKey = event.target.name.split('.')[3]

console.log(event)
if (expectedKeys.indexOf(targetKey) === -1) {
// console.log(`Loot Sheet | Error changing stettings for "${targetKey}".`);
return ui.notifications.error(`Error changing stettings for "${targetKey}".`)
}

if (targetKey == 'clearInventory' || targetKey == 'itemOnlyOnce') {
// console.log(targetKey + " set to " + event.target.checked);
//console.log(targetKey + ' set to ' + event.target.checked)
await this.actor.setFlag(moduleNamespace, targetKey, event.target.checked)
} else if (event.target.value) {
// console.log(targetKey + " set to " + event.target.value);
// console.log("A");
//console.log(targetKey + ' set to ' + event.target.value)
await this.actor.setFlag(moduleNamespace, targetKey, event.target.value)
} else {
// console.log(targetKey + " set to " + event.target.value);
// console.log("B");
//console.log(targetKey + ' set to ' + event.target.value)
await this.actor.unsetFlag(moduleNamespace, targetKey, event.target.value)
}
}

/**
* Handle clear inventory settings change
* @private
*/
async _clearInventoryChange(event) {
// Prevent default behavior of label-click that directly interacts with the checkbox
event.preventDefault()

const clickedElement = $(event.currentTarget)

// Find the checkbox and icon within the label
const checkbox = clickedElement.find('input[type="checkbox"]')[0]
const icon = clickedElement.find('i')[0]

// Toggle the checkbox checked state
checkbox.checked = !checkbox.checked

// Update the icon class based on the checkbox state
if (checkbox.checked) {
icon.classList.remove('fa-toggle-off')
icon.classList.add('fa-toggle-on')
} else {
icon.classList.remove('fa-toggle-on')
icon.classList.add('fa-toggle-off')
}

// console.log("Loot Sheet | ClearInventory Changed");

await this.actor.setFlag('lootsheet-simple', 'clearInventory', checkbox.checked)
}

/* -------------------------------------------- */

/**
Expand Down Expand Up @@ -391,8 +439,6 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
}

if (clearInventory) {
confirm
console.log(this.actor)
let currentItems = this.actor.items.map((i) => i.id)
await this.actor.deleteEmbeddedDocuments('Item', currentItems)
}
Expand Down Expand Up @@ -1016,7 +1062,7 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
let playerId = field[0].name

this._updatePermissions(this.actor, playerId, newLevel, event)
console.log('here?')

this._onSubmit(event)
}

Expand Down Expand Up @@ -1050,14 +1096,14 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
}
const lootPermissions = new DocumentOwnershipConfig(this.actor)
lootPermissions._updateObject(event, currentPermissions)
console.log('here?')

this._onSubmit(event)
}

_updatePermissions(actorData, playerId, newLevel, event) {
// Read player permission on this actor and adjust to new level
let currentPermissions = foundry.utils.duplicate(actorData.ownership)
console.log(currentPermissions)

currentPermissions[playerId] = newLevel
// Save updated player permissions
const lootPermissions = new DocumentOwnershipConfig(this.actor)
Expand All @@ -1074,11 +1120,9 @@ class LootSheet5eNPC extends dnd5e.applications.actor.ActorSheet5eNPC2 {
// super._prepareItems(context);
// }
_prepareItems(context) {
super._prepareItems(context);

super._prepareItems(context)
}


/* -------------------------------------------- */

/**
Expand Down Expand Up @@ -1157,7 +1201,6 @@ Actors.registerSheet('dnd5e', LootSheet5eNPC, {
})

Hooks.once('init', () => {
// console.log("Lootsheet: Test2");
Handlebars.registerHelper('ifeq', function (a, b, options) {
if (a == b) {
return options.fn(this)
Expand Down
Loading

0 comments on commit cb55fc9

Please sign in to comment.