Skip to content

Commit

Permalink
readded caching for card assets
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-demos-stefan-untitled-board-game-ubg-card.js,AUTO-COMMIT-src-components-widgets-ubg-card.js,AUTO-COMMIT-src-components-widgets-ubg-cards.js,AUTO-COMMIT-src-components-widgets-ubg-rules-text.js,
  • Loading branch information
onsetsu committed Jan 13, 2025
1 parent 96381e0 commit 8f14f15
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 299 deletions.
9 changes: 0 additions & 9 deletions demos/stefan/untitled-board-game/ubg-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ export default class Card {
}
}

// getType() {
// return this.versions.last.type;
// }

// setType(type) {
// this.ensureUnprintedVersion();
// this.versions.last.type = type;
// }

getTypes() {
const type = this.versions.last.type;

Expand Down
26 changes: 18 additions & 8 deletions src/components/widgets/ubg-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ class FileCache {
this.files = {};
}

dirtyFolder(path) {}
dirtyFolder(folderPath) {
for (const filePath in this.files) {
if (filePath.startsWith(folderPath)) {
delete this.files[filePath];
}
}
}

getFile(path, callback) {
if (this.files[path]) {
Expand Down Expand Up @@ -89,7 +95,9 @@ export default class UbgCard extends Morph {

/*MD ## Build MD*/
async fetchAssetsInfo() {
return (await this.assetsFolder.fetchStats()).contents;
return globalThis.__ubg_file_cache__.getFile(this.assetsFolder, async url => {
return (await url.fetchStats()).contents;
})
}

/*MD ## Extract Card Info MD*/
Expand Down Expand Up @@ -245,12 +253,14 @@ background: ${color};
}

async loadImage(filePath) {
return new Promise((resolve, reject) => {
const image = new Image();
image.addEventListener('load', resolve);
image.addEventListener('error', reject);
image.src = filePath;
});
return globalThis.__ubg_file_cache__.getFile(filePath, filePath => {
return new Promise((resolve, reject) => {
const image = new Image();
image.addEventListener('load', resolve);
image.addEventListener('error', reject);
image.src = filePath;
});
})
}

/*MD ## Rendering MD*/
Expand Down
Loading

0 comments on commit 8f14f15

Please sign in to comment.