Skip to content

Commit

Permalink
10.1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ironmonk88 committed Sep 11, 2022
1 parent 6e37632 commit eecd9ee
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 133 deletions.
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG] Brief description of your issue"
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Please complete as much of the following information as possible:**
- Browser [e.g. chrome, safari]
- Foundry Version [e.g. v9]
- System [e.g. D&D5e, Pathfinder 2e]
- Module version
- Are there any errors in the console [e.g. press F12 and look for red text]
- Have you tried using `Find the Culprit` to make sure it isn't a module interaction.

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Additional context**
Add any other context or screenshots about the feature request here.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## Version 10.1

Fixed issues with assigning xp, leaving the old xp visible on disabled actors.

Switched the setting to select how to deliver lootables to be more inline with how Enhanced Journals is displaying them.

Fixed lootables to work correctly in v10 and with Enhanced Journals.

Fixed issues when switching scenes and refreshing tokens.

## Version 1.0.71

Fixed an issue that the latest v10 update broke.
Expand Down
4 changes: 3 additions & 1 deletion apps/assignxp.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export class AssignXPApp extends Application {
if(xp !== undefined)
this.xp = xp;

this.actors.filter(a => a.disabled).forEach(a => { a.xp = 0 });

let sortedByLevel = this.actors.filter(a => !a.disabled).sort(function (a, b) {
const aXP = MonksTokenBar.system.getXP(a.actor);
const bXP = MonksTokenBar.system.getXP(b.actor);
Expand Down Expand Up @@ -201,7 +203,7 @@ export class AssignXPApp extends Application {
};

setProperty(chatData, "flags.monks-tokenbar", requestdata);
msg = ChatMessage.create(chatData, {});
msg = await ChatMessage.create(chatData, {});
this.close();
} else
ui.notifications.warn(i18n("MonksTokenBar.RequestNoneActorSelected"));
Expand Down
130 changes: 74 additions & 56 deletions apps/lootables.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MonksTokenBar, log, i18n, setting } from "../monks-tokenbar.js";
import { MonksTokenBar, log, i18n, warn, setting } from "../monks-tokenbar.js";

export class LootablesApp extends FormApplication {
constructor(entity, options) {
Expand Down Expand Up @@ -71,43 +71,50 @@ export class LootablesApp extends FormApplication {
});
}

getData(options) {
async getData(options) {
let notes = "";
let hasItems = false;
let lootsheet = setting('loot-sheet');
let lootentity = setting('loot-entity');
let sheetName = "";
switch (lootsheet) {
case 'lootsheetnpc5e': sheetName = "Loot Sheet NPC 5e"; break;
case 'merchantsheetnpc': sheetName = "Merchant Sheet"; break;
case 'monks-enhanced-journal': sheetName = "Monk's Enhanced Journal"; break;
case 'item-piles': sheetName = "Item Piles"; break;
}
if (setting('loot-type') == 'convert')

let entity;
try {
entity = await fromUuid(lootentity);
} catch { }

let convertEntity = lootentity == "convert";
let createEntity = (entity == undefined || entity instanceof Folder || entity instanceof JournalEntry);

if (convertEntity)
notes = `Convert tokens to lootable using ${sheetName}`;
else {
let entityName = "New " + (this.isLootActor(lootsheet) ? "Actor" : "Loot Journal Entry");
if (setting('loot-entity') != 'create') {
if (this.isLootActor(lootsheet)){
let entity = game.actors.get(setting('loot-entity'));
entityName = entity?.name || "Unknown";
hasItems = (entity?.items.size || 0) > 0;
} else {
let entity = game.journal.get(setting('loot-entity'));
entityName = entity?.name || "Unknown";
hasItems = (entity?.getFlag('monks-enhanced-journal', 'items') || []).length > 0;
}
if (this.isLootActor(lootsheet)) {
entityName = this.getEntityName(entity);
hasItems = (entity?.items.size || 0) > 0;
} else {
entityName = this.getEntityName(entity);
hasItems = (entity?.getFlag('monks-enhanced-journal', 'items') || []).length > 0;
}
notes = `Transfer items to <${entityName}> using ${sheetName}${setting('loot-type') == 'transferplus' ? `, and create a ${(this.isLootActor(lootsheet) ? "Token" : "Note")} on the Canvas` : ''}`;
}
notes = `${entityName}, using ${sheetName}${setting("create-canvas-object") ? `, and create a ${(this.isLootActor(lootsheet) ? "Token" : "Note")} on the Canvas` : ''}`;
}

return {
usecr: this.usecr,
loottype: setting('loot-type'),
createEntity: setting('loot-entity') == 'create',
clearEntity: setting('loot-type') != 'convert' && setting('loot-entity') != 'create' && hasItems,
convertEntity: convertEntity,
createEntity: createEntity,
clearEntity: !convertEntity && !createEntity && hasItems,
notes: notes,
placeholder: this.getLootableName(),
entries: this.entries,
actionText: (setting('loot-type') == 'convert' ? i18n('MonksTokenBar.ConvertToLootable') : i18n('MonksTokenBar.TransferToLootable'))
actionText: (convertEntity ? i18n('MonksTokenBar.ConvertToLootable') : (createEntity ? i18n('MonksTokenBar.TransferToNewLootable') : i18n('MonksTokenBar.TransferToLootable')))
};
}

Expand All @@ -122,6 +129,9 @@ export class LootablesApp extends FormApplication {
}

disableToken(ev) {
ev.preventDefault();
ev.stopPropagation();

let id = $(ev.currentTarget).closest('.item').attr('data-item-id');
//let token = this.entries.find(t => { return t.token.id === id; });
//if (token != undefined)
Expand Down Expand Up @@ -213,36 +223,42 @@ export class LootablesApp extends FormApplication {
return data;
}

getLootableName() {
let lootSheet = setting('loot-sheet');
let collection = (this.isLootActor(lootSheet) ? game.actors : game.journal)

let folder = setting('loot-folder');
getEntityName(entity) {
if (entity instanceof JournalEntryPage || entity instanceof Actor)
return "Transferring to " + entity.name;
else if (entity instanceof JournalEntry)
return "Adding new loot page to " + entity.name;
else if (entity instanceof Folder)
return (entity.documentClass.documentName == "JournalEntry" ? "Create new Journal Entry within " + entity.name + " folder" : "Create within " + entity.name + " folder");
else
return "Create in the root folder";
}

getLootableName(entity) {
//find the folder and find the next available 'Loot Entry (x)'
let previous = collection.filter(e => {
return e.folder?.id == folder && e.name.startsWith("Loot Entry");
}).map((e, i) =>
let lootSheet = setting('loot-sheet');
let collection = (this.isLootActor(lootSheet) ? game.actors : game.journal);

let documents = (entity == undefined ? collection.filter(e => e.folder == undefined) : entity.contents || entity.pages);
let previous = documents.map((e, i) =>
parseInt(e.name.replace('Loot Entry ', '').replace('(', '').replace(')', '')) || (i + 1)
).sort((a, b) => { return b - a; });
let num = (previous.length ? previous[0] + 1 : 1);

name = (num == 1 ? 'Loot Entry' : `Loot Entry (${num})`);
name = `${i18n("MonksTokenBar.LootEntry")}${(num > 1 ? ` (${num})` : '')}`;
return name;
}

async convertToLootable({ clear = false, name = null }) {
let data = expandObject(this._getSubmitData());

if (setting('loot-sheet') == 'none') {
return;
}

// Limit selection to Players and Trusted Players
let lootingUsers = game.users.contents.filter(user => { return user.role >= 1 && user.role <= 2 });

let lootType = setting('loot-type');
let lootSheet = setting('loot-sheet');
let lootEntity = setting('loot-entity');

if (lootSheet == 'none')
return;

let msg = "";

Expand All @@ -255,7 +271,7 @@ export class LootablesApp extends FormApplication {
}
}

if (lootType == 'convert') {
if (lootEntity == 'convert') {
if (lootSheet == "item-piles") {
let tokens = this.entries.map(t => t.token);
ItemPiles.API.turnTokensIntoItemPiles(tokens);
Expand Down Expand Up @@ -389,42 +405,43 @@ export class LootablesApp extends FormApplication {

msg = `Actors have been converted to lootable`;
} else {
let lootentity = setting('loot-entity');
let collection = (this.isLootActor(lootSheet) ? game.actors : game.journal);

let entity;
if (lootentity != 'create'){
entity = await collection.get(lootentity);//find the correct entity;
name = entity?.name;
try {
entity = await fromUuid(lootEntity);
} catch { }
name = entity?.name;

if (entity == undefined)
warn("Could not find Loot Entity, defaulting to creating one");
}
if (entity == undefined)
warn("Could not find Loot Entity, defaulting to creating one");

let created = (lootentity == 'create' || entity == undefined);
let created = (entity == undefined || entity instanceof Folder || entity instanceof JournalEntry);
if (created) {
//create the entity in the Correct Folder
let folder = setting('loot-folder');

if (name == undefined || name == '')
name = this.getLootableName();
name = this.getLootableName(entity);

if ((entity instanceof Folder || entity == undefined) && collection.documentName == "JournalEntry") {
entity = await JournalEntry.create({ folder: entity, name: name, ownership: { 'default': CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER } }, { render: false });
}

const cls = collection.documentClass;
if (this.isLootActor(lootSheet)) {
entity = await cls.create({ folder: folder, name: name, img: 'icons/svg/chest.svg', type: 'npc', flags: { core: { 'sheetClass': (lootSheet == "lootsheetnpc5e" ? 'dnd5e.LootSheetNPC5e' : 'core.a') } }, permission: { 'default': CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER } });
const cls = collection.documentClass;
entity = await cls.create({ folder: entity, name: name, img: 'icons/svg/chest.svg', type: 'npc', flags: { core: { 'sheetClass': (lootSheet == "lootsheetnpc5e" ? 'dnd5e.LootSheetNPC5e' : 'core.a') } }, ownership: { 'default': CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER } });
ui.actors.render();
MonksTokenBar.emit("refreshDirectory", { name: "actors" });
} else {
entity = await cls.create({ folder: folder, name: name, permission: { 'default': CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER } }, { render: false });
await entity.setFlag('monks-enhanced-journal', 'type', 'loot');
await entity.setFlag('monks-enhanced-journal', 'purchasing', 'confirm');
entity = await JournalEntryPage.create({ name: name, type: "text", flags: { "monks-enhanced-journal": { type: "loot", purchasing: "confirm" } }, ownership: { 'default': CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER } }, { parent: entity, render: false });
ui.journal.render();
MonksTokenBar.emit("refreshDirectory", { name: "journal" });
}
}

if (!entity)
return ui.notifications.warn("Could not find Loot Entity");

if (clear && lootentity != 'create') {
if (clear) {
if (this.isLootActor(lootSheet)) {
for (let item of entity.items) {
await item.delete();
Expand Down Expand Up @@ -489,7 +506,7 @@ export class LootablesApp extends FormApplication {
`${name} has been created, items have been transferred to it` :
`Items have been transferred to ${name}`);

if (lootType == 'transferplus' && lootSheet !== "item-piles") {
if (setting("create-canvas-object") && lootSheet !== "item-piles") {
let pt = { x: ptAvg.x / ptAvg.count, y: ptAvg.y / ptAvg.count };
// Snap to Grid
let snap = canvas.grid.getSnappedPosition(pt.x, pt.y, canvas[(this.isLootActor(lootSheet) ? 'tokens' : 'notes')].gridPrecision);
Expand All @@ -505,9 +522,10 @@ export class LootablesApp extends FormApplication {
await cls.create(td, { parent: canvas.scene });
} else if (lootSheet == 'monks-enhanced-journal') {
let data = {
x: pt.x + (canvas.scene.size / 2),
y: pt.y + (canvas.scene.size / 2),
entryId: entity.id,
x: parseInt(pt.x + (canvas.scene.dimensions.size / 2)),
y: parseInt(pt.y + (canvas.scene.dimensions.size / 2)),
entryId: entity.parent.id,
pageId: entity.id,
icon: "icons/svg/chest.svg"
};

Expand Down
4 changes: 4 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
"MonksTokenBar.resolution-size.hint": "Set the resolution of the tokens, the larger the number the clearer the image, but the longer it will take to load.",
"MonksTokenBar.allow-roll.name": "Allow Players Roll",
"MonksTokenBar.allow-roll.hint": "Allow players to request rolls",
"MonksTokenBar.create-canvas-object.name": "Create Canvas Object",
"MonksTokenBar.create-canvas-object.hint": "When creating a lootable, also create a related canvas object",

"MonksTokenBar.XP": "XP",
"MonksTokenBar.Actors": "Actors",
Expand Down Expand Up @@ -189,6 +191,7 @@
"MonksTokenBar.AssignByCR": "Assign gold by CR",
"MonksTokenBar.ConvertToLootable": "Convert to Lootable",
"MonksTokenBar.TransferToLootable": "Transfer to Lootable",
"MonksTokenBar.TransferToNewLootable": "Create New Lootable",
"MonksTokenBar.Gold": "Gold",
"MonksTokenBar.Levelup": "You have enough xp to level up!",
"MonksTokenBar.EditStats": "Edit Stats",
Expand All @@ -199,6 +202,7 @@
"MonksTokenBar.CreateEntityName": "New Entity Name",
"MonksTokenBar.ClearCurrentItems": "Clear Current Items",
"MonksTokenBar.SaveToMacro": "Save to Macro",
"MonksTokenBar.LootEntry": "Loot Entry",

"MonksTokenBar.None": "No one",
"MonksTokenBar.GMOnly": "GM Only",
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Monk's TokenBar",
"description": "Add a bar with all the current player tokens. Limit movement, roll saving throws, assign XP.",
"version": "1.0.71",
"version": "10.1",
"authors": [
{
"name": "IronMonk",
Expand Down Expand Up @@ -64,7 +64,7 @@
"css/tokenbar.css"
],
"url": "https://github.com/ironmonk88/monks-tokenbar",
"download": "https://github.com/ironmonk88/monks-tokenbar/archive/1.0.71.zip",
"download": "https://github.com/ironmonk88/monks-tokenbar/archive/10.1.zip",
"manifest": "https://github.com/ironmonk88/monks-tokenbar/releases/latest/download/module.json",
"bugs": "https://github.com/ironmonk88/monks-tokenbar/issues",
"allowBugReporter": true,
Expand Down
Loading

0 comments on commit eecd9ee

Please sign in to comment.