Skip to content

Commit

Permalink
add multipler export, fix some drag and drop issues, add DD in diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMonette committed Aug 30, 2022
1 parent 0d4451d commit e6b803f
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@
"WITCHER.Loot.HowMany": "How Many Items",
"WITCHER.Loot.ItemCost": "Cost by item",
"WITCHER.Loot.Percent": "Apply Percent",

"WITCHER.Loot.MultipleExport": "Export How Many Times?",

"WITCHER.Loot.BuyTitle": "Buy/Sell Items",
"WITCHER.Monster.exportLoot": "Export To loot",
Expand Down
58 changes: 45 additions & 13 deletions module/sheets/MonsterSheet.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { buttonDialog } from "../chat.js";

function onChangeSkillList(actor) {
let content = ``
for (let parent in actor.data.data.skills) {
Expand Down Expand Up @@ -76,21 +78,51 @@ function onChangeSkillList(actor) {
}

async function exportLoot(actor) {
let newLoot = await Actor.create(actor.data);
await newLoot.update({
"folder": null,
"name" : newLoot.data.name + "--loot",
"type" : "loot"
});
let content = `${ game.i18n.localize("WITCHER.Loot.MultipleExport")} <input type="number" class="small" name="multiple" value=1><br />`
let cancel = true
let multiplier = 0
let dialogData = {
buttons : [
[`${game.i18n.localize("WITCHER.Button.Cancel")}`, ()=>{} ],
[`${game.i18n.localize("WITCHER.Button.Continue")}`, (html)=>{
multiplier = html.find("[name=multiple]")[0].value;
cancel = false
} ]
],
title : game.i18n.localize("WITCHER.Monster.exportLoot"),
content : content
}
await buttonDialog(dialogData)
if (cancel) {
return
} else {

let newLoot = await Actor.create(actor.data);
await newLoot.update({
"folder": null,
"name" : newLoot.data.name + "--loot",
"type" : "loot"
});

newLoot.items.forEach(async item=>{
let newQuantity = item.data.data.quantity
if (typeof(newQuantity) === 'string' && item.data.data.quantity.includes("d")){
let total = 0
for (let i = 0; i < multiplier; i++) {
let roll = await new Roll(item.data.data.quantity).roll()
total += Math.ceil(roll.total)
}
newQuantity = total
} else {

newQuantity = Number(newQuantity) * multiplier
}
item.update({ 'data.quantity': newQuantity})
});

newLoot.items.forEach(async item=>{
if (typeof(item.data.data.quantity) === 'string' && item.data.data.quantity.includes("d")){
let roll = await new Roll(item.data.data.quantity).roll()
item.update({ 'data.quantity': Math.ceil(roll.total)})
}
});
newLoot.sheet.render(true)

newLoot.sheet.render(true)
}
}

export { onChangeSkillList, exportLoot};
21 changes: 17 additions & 4 deletions module/sheets/WitcherActorSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export default class WitcherActorSheet extends ActorSheet {

const newDragDrop = new DragDrop({
dragSelector:`.dragable`,
dropSelector:`.items`,
dropSelector:`.window-content`,
permissions: { dragstart: this._canDragStart.bind(this), drop: this._canDragDrop.bind(this) },
callbacks: { dragstart: this._onDragStart.bind(this), drop: this._onDrop.bind(this) }
})
Expand Down Expand Up @@ -356,20 +356,33 @@ export default class WitcherActorSheet extends ActorSheet {
await buttonDialog(dialogData)
if (cancel) {
return
}else {
} else {
this._removeItem(previousActor, dragData.item._id, numberOfItem)
if (numberOfItem > dragData.item.data.quantity) {
numberOfItem = dragData.item.data.quantity
}
this._addItem(this.actor, dragData.item, numberOfItem)
}
}else {
this._addItem(this.actor, dragData.item)
} else {
this._addItem(this.actor, dragData.item, 1)
if (previousActor) {
await previousActor.items.get(dragData.item._id).delete()
}
}
}
} else if (dragData.type === "Item") {
let dragEventData = TextEditor.getDragEventData(event)
if (dragEventData.pack){
let pack = await game.packs.get(dragEventData.pack)
pack.getDocument(dragEventData.id).then(item => {
this._addItem(this.actor, item.data, 1)
})
} else {
let item = game.items.get(dragEventData.id)
if (item) {
this._addItem(this.actor, item.data, 1)
}
}
} else {
super._onDrop(event, data);
}
Expand Down
52 changes: 51 additions & 1 deletion module/sheets/WitcherItemSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default class WitcherItemSheet extends ItemSheet {
width: 520,
height: 480,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
dragDrop: [{
dragSelector: ".items-list .item",
dropSelector: null
}],
});
}

Expand Down Expand Up @@ -63,8 +67,54 @@ export default class WitcherItemSheet extends ItemSheet {
html.find(".modifiers-edit-derived").on("change", this._onModifierDerivedEdit.bind(this));
html.find("input").focusin(ev => this._onFocusIn(ev));
html.find(".damage-type").on("change", this._onDamageTypeEdit.bind(this));
html.find(".dragable").on("dragstart", (ev) => {
let itemId = ev.target.dataset.id
let item = this.actor.items.get(itemId);
ev.originalEvent.dataTransfer.setData(
"text/plain",
JSON.stringify({
item: item,
actor: this.actor,
type: "itemDrop",
}),
)});

const newDragDrop = new DragDrop({
dragSelector:`.dragable`,
dropSelector:`.window-content`,
permissions: { dragstart: this._canDragStart.bind(this), drop: this._canDragDrop.bind(this) },
callbacks: { dragstart: this._onDragStart.bind(this), drop: this._onDrop.bind(this) }
})
this._dragDrop.push(newDragDrop);
}

_onDrop(event) {
if (this.item.type == "diagrams") {
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
let dragEventData = TextEditor.getDragEventData(event)
if(dragEventData.pack) {
let pack = game.packs.get(dragEventData.pack)
pack.getDocument(dragEventData.id).then(item => {
let newComponentList = []
if (this.item.data.data.craftingComponents){
newComponentList = this.item.data.data.craftingComponents
}
newComponentList.push({id: genId(), name: item.data.name, quantity: 1})
this.item.update({'data.craftingComponents': newComponentList});
})
} else {
let item = game.items.get(dragEventData.id)
if (item) {
let newComponentList = []
if (this.item.data.data.craftingComponents){
newComponentList = this.item.data.data.craftingComponents
}
newComponentList.push({id: genId(), name: item.data.name, quantity: 1})
this.item.update({'data.craftingComponents': newComponentList});
}
}
}
}

_onEffectEdit(event) {
event.preventDefault();
Expand Down Expand Up @@ -197,7 +247,7 @@ export default class WitcherItemSheet extends ItemSheet {
if (this.item.data.data.craftingComponents){
newComponentList = this.item.data.data.craftingComponents
}
newComponentList.push({id: genId(), name: "component", percentage: ""})
newComponentList.push({id: genId(), name: "component", quantity: ""})
this.item.update({'data.craftingComponents': newComponentList});
}

Expand Down
2 changes: 1 addition & 1 deletion system.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "The Witcher TRPG System.",
"minimumCoreVersion" : "9",
"compatibleCoreVersion" : "9",
"version": 0.83,
"version": 0.84,
"author": "TechAntho",
"scripts": [
],
Expand Down

0 comments on commit e6b803f

Please sign in to comment.