From 9c332f614b4dc5b570954c38835c7028e1248539 Mon Sep 17 00:00:00 2001 From: Samir Hadi Date: Wed, 10 Jun 2020 23:24:33 +0200 Subject: [PATCH 1/2] making better rolltable functionality accessible to macros --- scripts/better-table-view.js | 25 +++++++------------------ scripts/better-tables.js | 33 +++++++++++++++++++++++++++++++++ scripts/brt-main.js | 6 ++++++ scripts/utils.js | 2 -- 4 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 scripts/better-tables.js diff --git a/scripts/better-table-view.js b/scripts/better-table-view.js index cfe63f6c..88dad12d 100644 --- a/scripts/better-table-view.js +++ b/scripts/better-table-view.js @@ -1,6 +1,7 @@ import { i18n } from './utils.js'; import { LootBuilder } from './loot-builder.js' import { BRTCONFIG } from './config.js'; +import { BetterTables } from './better-tables.js'; import { LootCreator } from './loot-creator.js'; import { LootChatCard } from './loot-chat-card.js'; import { StoryBuilder } from './story/story-builder.js'; @@ -197,12 +198,8 @@ export class BetterRT { } static async generateLoot(tableEntity) { - const lootBuilder = new LootBuilder(tableEntity); - const generatedLoot = await lootBuilder.generateLoot(); - const lootCreator = new LootCreator(generatedLoot); - await lootCreator.createActor(); - await lootCreator.addCurrenciesToActor(); - await lootCreator.addItemsToActor(); + const betterTables = new BetterTables(); + await betterTables.generateLoot(tableEntity); } static async onOptionTypeChanged(value, tableEntity) { @@ -210,20 +207,12 @@ export class BetterRT { } static async onLootRollClicked(tableEntity) { - const lootBuilder = new LootBuilder(tableEntity); - const generatedLoot = await lootBuilder.generateLoot(); - const lootChatCard = new LootChatCard(generatedLoot); - await lootChatCard.createChatCard(tableEntity); + const betterTables = new BetterTables(); + await betterTables.generateChatLoot(tableEntity); } static async onStoryRollClicked(tableEntity) { - const storyBuilder = new StoryBuilder(tableEntity); - await storyBuilder.drawStory(); - const storyHtml = storyBuilder.generatedStory(); - const storyGMHtml = storyBuilder.generatedStoryGM(); - - const storyChat = new StoryChatCard(tableEntity); - storyChat.createChatCard(storyHtml); - storyChat.createChatCard(storyGMHtml, {gmOnly: true}); + const betterTables = new BetterTables(); + await betterTables.generateChatStory(tableEntity); } } \ No newline at end of file diff --git a/scripts/better-tables.js b/scripts/better-tables.js new file mode 100644 index 00000000..64a5d187 --- /dev/null +++ b/scripts/better-tables.js @@ -0,0 +1,33 @@ +import { LootCreator } from './loot-creator.js'; +import { LootBuilder } from './loot-builder.js' +import { LootChatCard } from './loot-chat-card.js'; +import { StoryBuilder } from './story/story-builder.js'; +import { StoryChatCard } from './story/story-chat-card.js'; + +export class BetterTables { + async generateLoot(tableEntity) { + const lootBuilder = new LootBuilder(tableEntity); + const generatedLoot = await lootBuilder.generateLoot(); + const lootCreator = new LootCreator(generatedLoot); + await lootCreator.createActor(); + await lootCreator.addCurrenciesToActor(); + await lootCreator.addItemsToActor(); + } + + async generateChatLoot(tableEntity) { + const lootBuilder = new LootBuilder(tableEntity); + const generatedLoot = await lootBuilder.generateLoot(); + const lootChatCard = new LootChatCard(generatedLoot); + await lootChatCard.createChatCard(tableEntity); + } + + async generateChatStory(tableEntity) { + const storyBuilder = new StoryBuilder(tableEntity); + await storyBuilder.drawStory(); + const storyHtml = storyBuilder.generatedStory(); + const storyGMHtml = storyBuilder.generatedStoryGM(); + const storyChat = new StoryChatCard(tableEntity); + storyChat.createChatCard(storyHtml); + storyChat.createChatCard(storyGMHtml, { gmOnly: true }); + } +} \ No newline at end of file diff --git a/scripts/brt-main.js b/scripts/brt-main.js index 6d444089..daa1a498 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -1,6 +1,7 @@ import { BetterRT } from './better-table-view.js'; import { BRTCONFIG } from './config.js'; import { i18n } from './utils.js'; +import { BetterTables } from './better-tables.js'; // CONFIG.debug.hooks = true; @@ -11,6 +12,8 @@ Hooks.on("init", function () { }); registerSettings(); + + game.betterTables = new BetterTables(); }); Hooks.on("renderRollTableConfig", BetterRT.enhanceRollTableView); @@ -48,3 +51,6 @@ function registerSettings() { type: String }); } + + + diff --git a/scripts/utils.js b/scripts/utils.js index e69e314a..4f48b825 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -25,8 +25,6 @@ export async function findInCompendiumByName(compendiumName, entityName){ } export async function findInCompendiumById(compendiumName, entityId){ - console.log("findInCompendiumById compendiumName ", compendiumName); - console.log("findInCompendiumById entityId ", entityId); const compendium = game.packs.find(t => t.collection === compendiumName); if(compendium) { const compendiumIndex = await compendium.getIndex(); From 91637ba9f9316dd3ce3f5d288bb9f44052328fb4 Mon Sep 17 00:00:00 2001 From: Samir Hadi Date: Thu, 11 Jun 2020 00:34:19 +0200 Subject: [PATCH 2/2] v 1.1.0 --- module.json | 4 ++-- scripts/better-table-view.js | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/module.json b/module.json index 92f61787..c5d66098 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "name": "better-rolltables", "title": "Better Roll Tables", "description": "Adding functionality to roll tables, especially to roll treasure and magic items", - "version": "1.0.0", + "version": "1.1.0", "author": "Ultrakorne#6240", "esmodules": [ "./scripts/brt-main.js" @@ -40,5 +40,5 @@ ], "url": "https://github.com/ultrakorne/better-rolltables", "manifest": "https://raw.githubusercontent.com/ultrakorne/better-rolltables/master/module.json", - "download": "https://github.com/ultrakorne/better-rolltables/releases/download/v1.0.0/better-rolltables.zip" + "download": "https://github.com/ultrakorne/better-rolltables/releases/download/v1.1.0/better-rolltables.zip" } \ No newline at end of file diff --git a/scripts/better-table-view.js b/scripts/better-table-view.js index 88dad12d..38beaed6 100644 --- a/scripts/better-table-view.js +++ b/scripts/better-table-view.js @@ -1,11 +1,6 @@ import { i18n } from './utils.js'; -import { LootBuilder } from './loot-builder.js' import { BRTCONFIG } from './config.js'; import { BetterTables } from './better-tables.js'; -import { LootCreator } from './loot-creator.js'; -import { LootChatCard } from './loot-chat-card.js'; -import { StoryBuilder } from './story/story-builder.js'; -import { StoryChatCard } from './story/story-chat-card.js'; export class BetterRT { static async enhanceRollTableView(rollTableConfig, html, rollTable) {