Skip to content

Commit

Permalink
closes #765
Browse files Browse the repository at this point in the history
  • Loading branch information
Muttley committed Apr 30, 2024
1 parent 5d6826f commit 680f162
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 35 deletions.
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v2.2.0

## Enhancements
* [#765] Implement generic loading dialog that can be used whenever potentially slow compendium searching occurs

---

# v2.1.0

## Bugfixes
Expand Down
9 changes: 6 additions & 3 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ SHADOWDARK.app.light-tracker.douse-light: Douse Light
SHADOWDARK.app.light-tracker.hide-inactive: Hide Actors Without Lights
SHADOWDARK.app.light-tracker.show-all-actors: Show All Actors
SHADOWDARK.app.light-tracker.turn-out-the-lights: Turn Out the Lights
SHADOWDARK.app.loading.body: Searching Distant Lands...
SHADOWDARK.app.loading.title: Loading
SHADOWDARK.app.npc_attack_ranges.title: Attack Ranges
SHADOWDARK.apps.character-generator.create_character: Create Character
SHADOWDARK.apps.character-generator.error.create: Failed to create player character {error}
SHADOWDARK.apps.character-generator.error.name: Character name cannot be blank
SHADOWDARK.apps.character-generator.error.no_ancestry_for_name: Unable to roll a random name without a selected Ancestry
SHADOWDARK.apps.character-generator.name: Character Name
SHADOWDARK.apps.character-generator.success: Character created
SHADOWDARK.apps.character-generator.starting_gear: Starting Gear
SHADOWDARK.apps.character-generator.starting_gold: Starting Gold
SHADOWDARK.apps.character-generator.stats: Stats
SHADOWDARK.apps.character-generator.success: Character created
SHADOWDARK.apps.character-generator.title: Character Generator
SHADOWDARK.apps.character-generator.type: Type
SHADOWDARK.apps.character-generator.update_character: Update Character
Expand Down Expand Up @@ -241,6 +243,7 @@ SHADOWDARK.dialog.item_roll.talent_bonus: Talent Bonus
SHADOWDARK.dialog.item_roll.title: Roll Attack with
SHADOWDARK.dialog.item_selector.default_title: Choose Items
SHADOWDARK.dialog.item_selector.error.max_choices_exceeded: You can only select a maximum of {maxChoices} of this Item type.
SHADOWDARK.dialog.item_selector.error.no_items_found: Unable to find items of the correct type in the available compendiums.
SHADOWDARK.dialog.item_selector.select_item.prompt: Select Item...
SHADOWDARK.dialog.item.confirm_delete: Confirm Deletion
SHADOWDARK.dialog.item.confirm_sale: Confirm Sale
Expand Down Expand Up @@ -619,8 +622,8 @@ SHADOWDARK.sheet.item.tab.details: Details
SHADOWDARK.sheet.item.tab.effects: Effects
SHADOWDARK.sheet.item.tab.light: Light
SHADOWDARK.sheet.item.tab.magic: Magic
SHADOWDARK.sheet.item.tab.spellsknown: Spells Known
SHADOWDARK.sheet.item.tab.source: Source
SHADOWDARK.sheet.item.tab.spellsknown: Spells Known
SHADOWDARK.sheet.item.tab.titles: Titles
SHADOWDARK.sheet.npc.attacks_label: Attacks
SHADOWDARK.sheet.npc.dark_adapted: Dark-Adapted
Expand All @@ -642,9 +645,9 @@ SHADOWDARK.sheet.player.boons.blessings.label: Blessings
SHADOWDARK.sheet.player.boons.label: Boons
SHADOWDARK.sheet.player.boons.oaths.label: Oaths
SHADOWDARK.sheet.player.boons.secrets.label: Secrets
SHADOWDARK.sheet.player.class_spells: Class Spells
SHADOWDARK.sheet.player.class.label: Class
SHADOWDARK.sheet.player.class.tooltip: Your character's job
SHADOWDARK.sheet.player.class_spells: Class Spells
SHADOWDARK.sheet.player.deity.label: Deity
SHADOWDARK.sheet.player.deity.tooltip: Your character’s cosmic link to the opposing forces of Law and Chaos, or balanced Neutrality.
SHADOWDARK.sheet.player.languages: Languages
Expand Down
1 change: 1 addition & 0 deletions scss/ui/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@forward 'compendium-item-selector';
@forward 'loading-spinner';
7 changes: 7 additions & 0 deletions scss/ui/_loading-spinner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.shadowdark.loading-spinner {
img {
border-width:0px;
width:50px;
height:50px;
}
}
27 changes: 2 additions & 25 deletions system/src/apps/CharacterGeneratorSD.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
Handlebars.registerHelper("remove-p-tag", str1 => {
return str1.replace(/(<p[^>]+?>|<p>|<\/p>)/img, "");
});

class loadingDialog extends Dialog {
constructor() {
let data = {
title: "Character Generator",
content: "<center>Searching Distant Lands...<br><img src='systems/shadowdark/assets/logo/arcane-library-logo.webp' class='fa-spin' style='border-width:0px;width:50px;height:50px;'></img></center>",
buttons: {},
};
let options = {
height: 125,
width: 250,
};
super(data, options);
}
}


export default class CharacterGeneratorSD extends FormApplication {
/**
* Contains functions for building Shadowdark characters
Expand Down Expand Up @@ -124,8 +104,6 @@ export default class CharacterGeneratorSD extends FormApplication {
},
};

this.loadingDialog = new loadingDialog();

if (actorUid) {
this.formData.editing = true;
this.actorUid = actorUid;
Expand Down Expand Up @@ -249,12 +227,11 @@ export default class CharacterGeneratorSD extends FormApplication {
this.firstrun = false;

// Put up a loading screen as compendium searching can take a while
this.loadingDialog.render(true);
const loadingDialog = new shadowdark.apps.LoadingSD().render(true);

// Initialize Alignment
this.formData.alignments = CONFIG.SHADOWDARK.ALIGNMENTS;


// setup ability range as 3-18
this.formData.statRange = [];
for (let i =3; i<19; i++) {
Expand Down Expand Up @@ -311,7 +288,7 @@ export default class CharacterGeneratorSD extends FormApplication {
}

// loading is finished, pull down the loading screen
this.loadingDialog.close();
loadingDialog.close({force: true});
}

// format talents
Expand Down
47 changes: 44 additions & 3 deletions system/src/apps/CompendiumItemSelector.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default class CompendiumItemSelector extends FormApplication {

maxChoices = 0;

itemsLoaded = false;

uuid = randomID();

static get defaultOptions() {
Expand Down Expand Up @@ -32,6 +34,42 @@ export default class CompendiumItemSelector extends FormApplication {
return game.i18n.localize("SHADOWDARK.dialog.item_selector.default_title");
}

async _autoCloseWhenRendered() {
while (!this.rendered) {
await shadowdark.utils.sleep(100); // millisecs
}

this.close({force: true});
}

async _getAvailableItems() {
const loadingDialog = new shadowdark.apps.LoadingSD().render(true);

const availableItems = await this.getAvailableItems() ?? [];
this.itemsLoaded = true;

const itemsAvailable = availableItems?.size > 0 ?? false;

if (itemsAvailable) {
for (const item of availableItems) {
item.decoratedName = await this.decorateName(item);
}

this.availableItems = Array.from(availableItems).sort(
(a, b) => a.name.localeCompare(b.name)
);
}
else {
ui.notifications.warn(
game.i18n.localize("SHADOWDARK.dialog.item_selector.error.no_items_found")
);

this._autoCloseWhenRendered();
}

loadingDialog.close({force: true});
}

activateListeners(html) {
html.find(".remove-item").click(event => this._onRemoveItem(event));

Expand All @@ -44,8 +82,7 @@ export default class CompendiumItemSelector extends FormApplication {
return item.name;
}

async getAllItemData() {
this.availableItems = await this.getAvailableItems() ?? [];
async getCurrentItemData() {
this.currentItemUuids = await this.getUuids() ?? [];
this.currentItems = await this.getCurrentItems() ?? [];

Expand All @@ -65,7 +102,11 @@ export default class CompendiumItemSelector extends FormApplication {
}

async getData() {
await this.getAllItemData();
if (!this.itemsLoaded) {
await this._getAvailableItems();
}

await this.getCurrentItemData();

const data = {
currentItems: this.currentItems,
Expand Down
34 changes: 34 additions & 0 deletions system/src/apps/LoadingSD.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export default class LoadingSD extends Application {

static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["shadowdark", "loading-spinner"],
resizable: false,
width: "auto",
height: 120,
});
}

get template() {
return "systems/shadowdark/templates/apps/loading.hbs";
}

get title() {
return game.i18n.localize("SHADOWDARK.app.loading.title");
}

async close(options={}) {
// Occasionally the loading dialog will try to close before it has fully
// rendered.
//
// If this happens Foundry will not remove the window correctly, so we
// make sure to only try and properly close the window once it has
// finished rendering.
//
while (!this.rendered) {
await shadowdark.utils.sleep(100); // millisecs
}

super.close(options);
}
}
1 change: 1 addition & 0 deletions system/src/apps/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {default as GemBagSD} from "./GemBagSD.mjs";
export {default as ItemImporterSD} from "./ItemImporterSD.mjs";
export {default as LevelUpSD} from "./LevelUpSD.mjs";
export {default as LightSourceTrackerSD} from "./LightSourceTrackerSD.mjs";
export {default as LoadingSD} from "./LoadingSD.mjs";
export {default as MonsterImporterSD} from "./MonsterImporterSD.mjs";
export {default as NpcAttackRangesSD} from "./NpcAttackRangesSD.mjs";
export {default as ShadowdarklingImporterSD} from "./ShadowdarklingImporterSD.mjs";
Expand Down
12 changes: 8 additions & 4 deletions system/src/handlebars.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import EffectPanelSD from "./apps/EffectPanelSD.mjs";

export default function registerHandlebarsHelpers() {

Handlebars.registerHelper("secondsToMins", seconds => {
return Math.ceil(seconds / 60);
});

Handlebars.registerHelper("ifCond", function(v1, operator, v2, options) {
switch (operator) {
case "==":
Expand Down Expand Up @@ -171,4 +167,12 @@ export default function registerHandlebarsHelpers() {
return game.i18n.localize("SHADOWDARK.apps.effect_panel.duration_label.expired");
}
});

Handlebars.registerHelper("remove-p-tag", str1 => {
return str1.replace(/(<p[^>]+?>|<p>|<\/p>)/img, "");
});

Handlebars.registerHelper("secondsToMins", seconds => {
return Math.ceil(seconds / 60);
});
}
6 changes: 6 additions & 0 deletions system/src/utils/UtilitySD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export default class UtilitySD {
}
}

static async sleep(millisecs=1000) {
return new Promise((resolve, reject) => {
setTimeout(resolve, millisecs);
});
}

/**
* Asks the user for input if necessary for an effect that requires said input.
* @param {Item} item - Item that has the effects
Expand Down
8 changes: 8 additions & 0 deletions system/templates/apps/loading.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<center>
{{localize "SHADOWDARK.app.loading.body"}}
<br>
<img
class="fa-spin"
src="systems/shadowdark/assets/logo/arcane-library-logo.webp"
></img>
</center>

0 comments on commit 680f162

Please sign in to comment.