Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadImageStack(imageStack, width = 24, height = 24) {
- if(!Array.isArray(imageStack)) {
- imageStack = [imageStack];
- }
- for(let index = 0; index < imageStack.length; index++){
- imageStack[index] = loadImage(imageStack[index], width, height);
- }
- return imageStack;
- }
- function loadImage(imagePath, width = 24, height = 24) {
- if (imagePath === undefined) {
- return undefined;
- }
- if(isObject(imagePath)) {
- return undefined;
- }
- if(Array.isArray(imagePath)) {
- return loadImageStack(imagePath, width, height)[0];
- }
- if ( right ( imagePath, 4 ) === `.png` ) {
- imagePath = left( imagePath, len(imagePath) - 4 );
- }
- if ( len ( imagePath ) === 4 || len ( imagePath ) === 8 ) {
- imagePath = left(imagePath + `________`, 8);
- if (imagePath === `________`) {
- // logFeats(`Placeholder Image: ${fullPath}`);
- return undefined;
- }
- let fullPath = `${host}/GFX/${imagePath}.png`;
- } else {
- let fullPath = `{{ project root }}${imagePath}.png`;
- }
- let cachedImage = imageCache.find(img => img.src === fullPath);
- if (!cachedImage) {
- cachedImage = new Image(width, height);
- cachedImage.src = fullPath;
- cachedImage.onload = function ( ) {
- imageCache.push(cachedImage);
- logFeats(`Loaded: ${cachedImage.src}`);
- // backContext.drawImage(cachedImage, x, y, width, height); // Draw image after loading
- };
- cachedImage.onerror = function ( ) {
- logFeats(`Failed to load: ${cachedImage.src}`);
- cachedImage = undefined;
- };
- } else {
- // logFeats(`Drawing Image: ${cachedImage.src}`);
- return cachedImage;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement