Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement equipable (composable) viewer. #5530

Closed
vikiival opened this issue Apr 5, 2023 · 9 comments
Closed

Implement equipable (composable) viewer. #5530

vikiival opened this issue Apr 5, 2023 · 9 comments
Labels
A-rmrk2 design-request p3 non-core, affecting less than 40%

Comments

@vikiival
Copy link
Member

vikiival commented Apr 5, 2023

@joelamouche
Copy link

Screenshot 2023-04-05 at 5 18 37 PM
This is on Koda

Screenshot 2023-04-05 at 5 18 56 PM
This is on Singular

This is the view to equip items
Screenshot 2023-04-05 at 5 19 16 PM

@yangwao yangwao added p3 non-core, affecting less than 40% A-rmrk2 labels Apr 5, 2023
@preschian
Copy link
Member

@vikiival how do we get the equipable item list?

@vikiival
Copy link
Member Author

@vikiival how do we get the equipable item list?

to get the inventory

query itemInventory($id: String!) {
  nftEntities(where: { parent: { id_eq: $id } }) {
    image
    name
    image
  }
}

To find out which are equipped I will do it today:

@vikiival
Copy link
Member Author

@preschian
Copy link
Member

this is my snippet code, to merge the images. not tested

// List of image URLs
const imageURLs = [
  'path/to/image1.jpg',
  'path/to/image2.jpg',
  // ...
];

// Load all images
const loadImages = (imageURLs) => {
  const images = imageURLs.map((url) => {
    const img = new Image();
    img.src = url;
    return new Promise((resolve, reject) => {
      img.onload = () => resolve(img);
      img.onerror = () => reject(new Error(`Failed to load image: ${url}`));
    });
  });
  return Promise.all(images);
};

// Combine images into one
const combineImages = async (imageURLs) => {
  const images = await loadImages(imageURLs);

  // Calculate the combined width and maximum height of the images
  const combinedWidth = images.reduce((width, img) => width + img.width, 0);
  const maxHeight = Math.max(...images.map(img => img.height));

  // Create an offscreen canvas
  const offscreenCanvas = new OffscreenCanvas(combinedWidth, maxHeight);
  const ctx = offscreenCanvas.getContext('2d');

  // Draw images on the canvas side by side
  let currentX = 0;
  images.forEach((img) => {
    ctx.drawImage(img, currentX, 0);
    currentX += img.width;
  });

  // Get the combined image as a data URL
  const dataURL = offscreenCanvas.toDataURL('image/png');
  return dataURL;
};

// Check for OffscreenCanvas support
if (typeof OffscreenCanvas !== 'undefined') {
  // Example usage
  combineImages(imageURLs).then((dataURL) => {
    // Do something with the combined image data URL
    console.log(dataURL);
  });
} else {
  // OffscreenCanvas is not supported, handle the fallback or show an error message
  console.error('Your browser does not support OffscreenCanvas.');
}

@vikiival vikiival changed the title Implement equipable viewer. Implement equipable (composable) viewer. Apr 18, 2023
@vikiival
Copy link
Member Author

vikiival commented Apr 18, 2023

cc @preschian

I also made a resolver for this case

URL: https://squid.subsquid.io/marck/v/v3/graphql

query MyQuery {
  childListByNftId(id: "12126283-7472058104f9f93924-SKC-soldier_1-00000001") {
    id
    name
    image
    media
    pending
    resourceMetadata
    resourceSrc
    resourceThumb
  }
}

@Matehoo
Copy link
Contributor

Matehoo commented Apr 20, 2023

👋

@kodabot
Copy link
Collaborator

kodabot commented Apr 20, 2023

ASSIGNED - @Matehoo 🔒 LOCKED -> Friday, April 21st 2023, 09:58:13 UTC -> 24 hours

@kodabot
Copy link
Collaborator

kodabot commented Apr 21, 2023

ASSIGNMENT EXPIRED - @Matehoo has been unassigned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rmrk2 design-request p3 non-core, affecting less than 40%
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants