v10 WIP
This commit is contained in:
parent
336767c19e
commit
5cd9fb3a1c
@ -2,42 +2,47 @@ import { Misc } from "./misc.js";
|
|||||||
|
|
||||||
export class RdDHotbar {
|
export class RdDHotbar {
|
||||||
|
|
||||||
|
static async createMacro(item, command) {
|
||||||
|
let macro = await Macro.create({
|
||||||
|
name: item.name,
|
||||||
|
type: "script",
|
||||||
|
img: item.img,
|
||||||
|
command: command
|
||||||
|
}, { displaySheet: false })
|
||||||
|
return macro
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a macro when dropping an entity on the hotbar
|
* Create a macro when dropping an entity on the hotbar
|
||||||
* Item - open roll dialog for item
|
* Item - open roll dialog for item
|
||||||
* Actor - open actor sheet
|
* Actor - open actor sheet
|
||||||
* Journal - open journal sheet
|
* Journal - open journal sheet
|
||||||
*/
|
*/
|
||||||
static initDropbar( ) {
|
static initDropbar() {
|
||||||
|
|
||||||
Hooks.on("hotbarDrop", async (bar, documentData, slot) => {
|
Hooks.on("hotbarDrop", (bar, documentData, slot) => {
|
||||||
|
|
||||||
|
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
||||||
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
if (documentData.type == "Item") {
|
||||||
if (documentData.type == "Item") {
|
let item = fromUuidSync(documentData.uuid)
|
||||||
let item = fromUuidSync(documentData.uuid)
|
if (item == undefined) {
|
||||||
if (item == undefined) {
|
item = this.actor.items.get(documentData.uuid)
|
||||||
item = this.actor.items.get( documentData.uuid )
|
}
|
||||||
|
console.log("DROP", documentData, item)
|
||||||
|
if (!item || (item.type != "arme" && item.type != "competence")) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}");`;
|
||||||
|
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command));
|
||||||
|
if (!macro) {
|
||||||
|
macro = this.createMacro(item, command)
|
||||||
|
}
|
||||||
|
game.user.assignHotbarMacro(macro, slot);
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
console.log( "DROP", documentData, item)
|
|
||||||
if (!item || (item.type != "arme" && item.type != "competence" ) ) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}");`;
|
|
||||||
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command));
|
|
||||||
if (!macro) {
|
|
||||||
macro = await Macro.create({
|
|
||||||
name: item.name,
|
|
||||||
type: "script",
|
|
||||||
img: item.img,
|
|
||||||
command: command
|
|
||||||
}, { displaySheet: false })
|
|
||||||
}
|
|
||||||
game.user.assignHotbarMacro(macro, slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a macro to open the actor sheet of the actor dropped on the hotbar
|
// Create a macro to open the actor sheet of the actor dropped on the hotbar
|
||||||
else if (documentData.type == "Actor") {
|
/*else if (documentData.type == "Actor") {
|
||||||
let actor = game.actors.get(documentData.id);
|
let actor = game.actors.get(documentData.id);
|
||||||
let command = `game.actors.get("${documentData.id}").sheet.render(true)`
|
let command = `game.actors.get("${documentData.id}").sheet.render(true)`
|
||||||
let macro = game.macros.contents.find(m => (m.name === actor.name) && (m.command === command));
|
let macro = game.macros.contents.find(m => (m.name === actor.name) && (m.command === command));
|
||||||
@ -51,6 +56,7 @@ export class RdDHotbar {
|
|||||||
game.user.assignHotbarMacro(macro, slot);
|
game.user.assignHotbarMacro(macro, slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a macro to open the journal sheet of the journal dropped on the hotbar
|
// Create a macro to open the journal sheet of the journal dropped on the hotbar
|
||||||
else if (documentData.type == "JournalEntry") {
|
else if (documentData.type == "JournalEntry") {
|
||||||
let journal = fromUuidSync(documentData.uuid)
|
let journal = fromUuidSync(documentData.uuid)
|
||||||
@ -65,30 +71,30 @@ export class RdDHotbar {
|
|||||||
}, { displaySheet: false })
|
}, { displaySheet: false })
|
||||||
game.user.assignHotbarMacro(macro, slot);
|
game.user.assignHotbarMacro(macro, slot);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
return false;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Roll macro */
|
/** Roll macro */
|
||||||
static rollMacro(itemName, itemType, bypassData) {
|
static rollMacro(itemName, itemType, bypassData) {
|
||||||
const speaker = ChatMessage.getSpeaker();
|
const speaker = ChatMessage.getSpeaker();
|
||||||
let actor;
|
let actor;
|
||||||
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
||||||
if (!actor) actor = game.actors.get(speaker.actor);
|
if (!actor) actor = game.actors.get(speaker.actor);
|
||||||
|
|
||||||
let item = actor?.items.find(it => it.name === itemName && it.type == itemType) ?? undefined;
|
let item = actor?.items.find(it => it.name === itemName && it.type == itemType) ?? undefined;
|
||||||
if (!item){
|
if (!item) {
|
||||||
return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`);
|
return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`);
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger the item roll
|
|
||||||
switch (item.type) {
|
|
||||||
case "arme":
|
|
||||||
return actor.rollArme(item);
|
|
||||||
case "competence":
|
|
||||||
return actor.rollCompetence( itemName );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger the item roll
|
||||||
|
switch (item.type) {
|
||||||
|
case "arme":
|
||||||
|
return actor.rollArme(item);
|
||||||
|
case "competence":
|
||||||
|
return actor.rollCompetence(itemName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
],
|
],
|
||||||
"url": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/",
|
"url": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/",
|
||||||
"license": "LICENSE.txt",
|
"license": "LICENSE.txt",
|
||||||
"version": "10.0.10",
|
"version": "10.0.11",
|
||||||
"compatibility": {
|
"compatibility": {
|
||||||
"minimum": "10"
|
"minimum": "10"
|
||||||
},
|
},
|
||||||
@ -332,7 +332,7 @@
|
|||||||
],
|
],
|
||||||
"socket": true,
|
"socket": true,
|
||||||
"manifest": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/raw/v10/system.json",
|
"manifest": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/raw/v10/system.json",
|
||||||
"download": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/archive/foundryvtt-reve-de-dragon-10.0.10.zip",
|
"download": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/archive/foundryvtt-reve-de-dragon-10.0.11.zip",
|
||||||
"gridDistance": 1,
|
"gridDistance": 1,
|
||||||
"gridUnits": "m",
|
"gridUnits": "m",
|
||||||
"primaryTokenAttribute": "sante.vie",
|
"primaryTokenAttribute": "sante.vie",
|
||||||
|
Loading…
Reference in New Issue
Block a user