From 7c40c0a8c0ca7d3d9c1b1d1b4785d44a85ce77c9 Mon Sep 17 00:00:00 2001 From: LiukRast Date: Fri, 8 Nov 2024 13:41:44 +0100 Subject: [PATCH] Fixed #4 --- assets/frozenblock/textures/render/skin.js | 62 +++++++++++----------- js/index.js | 5 +- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/assets/frozenblock/textures/render/skin.js b/assets/frozenblock/textures/render/skin.js index 69e6ba1..f798d37 100644 --- a/assets/frozenblock/textures/render/skin.js +++ b/assets/frozenblock/textures/render/skin.js @@ -1,3 +1,5 @@ +// Should generate a skin 3D render based on the uuid + const express = require('express'); const { createCanvas, loadImage } = require('canvas'); const fetch = require('node-fetch'); @@ -9,103 +11,103 @@ app.get('/assets/frozenblock/render/skin.png', async (req, res) => { const uuid = req.query.uuid; if (!uuid) { - res.status(400).send('UUID non fornito'); + res.status(400).send('UUID not found'); return; } try { - // Carica la skin di Minecraft usando l'UUID + // Fetch UUID from mojang const response = await fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${uuid}`); const data = await response.json(); const textures = data.properties.find(prop => prop.name === "textures"); if (!textures) { - res.status(404).send('Texture non trovata per l\'UUID fornito'); + res.status(404).send('Texture not found for given UUID'); return; } const textureData = JSON.parse(Buffer.from(textures.value, 'base64').toString('utf-8')); const skinUrl = textureData['textures']['SKIN']['url']; - // Crea un canvas con dimensioni 360x864 + // Create a 360x864 canvas const width = 360; const height = 864; const canvas = createCanvas(width, height); const ctx = canvas.getContext('2d'); - // Imposta lo sfondo trasparente + // Set the background to transparent ctx.clearRect(0, 0, width, height); - // Carica l'immagine della skin + // Load Skin image const skinImage = await loadImage(skinUrl); - // Imposta il filtro "nearest neighbor" per un effetto pixelato + // sets Nearest Neighbor ctx.imageSmoothingEnabled = false; - const scale = 20; // Scala per ingrandire il rombo + const scale = 20; // Scale image - // Centro della testa + // Middle of head const centerX = width / 2; - const topMargin = 100; // Spostamento verticale + const topMargin = 100; // Vertical translation - // === Prima faccia (frontale) === + // === First face === const frontSx = 8; const frontSy = 8; const sWidth = 8; const sHeight = 8; - // Trasformazione isometrica per la prima faccia (frontale) + // Isometric transform for first face ctx.setTransform(1, 0.5, 0, 1, centerX - (sWidth * scale) / 2 - 90, topMargin); - // Ombreggiatura per la faccia frontale (nessuna modifica) + // Shadow for first face ctx.drawImage(skinImage, frontSx, frontSy, sWidth, sHeight, 0, 0, sWidth * scale, sHeight * scale); - // Ripristina la trasformazione originale + // Reset transformations ctx.setTransform(1, 0, 0, 1, 0, 0); - // === Seconda faccia (laterale destra) === + // === Second face === const rightSx = 16; const rightSy = 8; - // Trasformazione isometrica per la seconda faccia (laterale destra) + // Isometric transform for second face ctx.setTransform(1, -0.5, 0, 1, centerX + (sWidth * scale) / 2 - scale - 70, topMargin + 80); - // Ombreggiatura per la faccia laterale (leggermente più scura) + // Shadow for second face ctx.drawImage(skinImage, rightSx, rightSy, sWidth, sHeight, 0, 0, sWidth * scale, sHeight * scale); - ctx.globalAlpha = 1.0; // Ripristina opacità per le altre facce + ctx.globalAlpha = 1.0; // Resets opacity for other faces - // Ripristina la trasformazione originale + // Reset transformations ctx.setTransform(1, 0, 0, 1, 0, 0); - // === Terza faccia (superiore) === + // === Third face === const topSx = 8; const topSy = 0; - // Trasformazione isometrica per la faccia superiore (ruotata e traslata sopra le altre facce) + // Isometric transform for third face ctx.setTransform(1, 0.5, -1, 0.5, centerX - scale / 2, topMargin - (sHeight * scale) / 2); - // Ombreggiatura per la faccia superiore (ancora più scura) + // Shadow for third face ctx.drawImage(skinImage, topSx, topSy, sWidth, sHeight, 0, 0, sWidth * scale, sHeight * scale); - ctx.globalAlpha = 1.0; // Ripristina opacità + ctx.globalAlpha = 1.0; // Resets opacity for other faces - // Ripristina la trasformazione originale + // Reset transformations ctx.setTransform(1, 0, 0, 1, 0, 0); - // Imposta l'intestazione della risposta + // Sets the header res.setHeader('Content-Type', 'image/png'); - // Invia l'immagine generata come risposta + // Sends the image as response canvas.toBuffer((err, buf) => { if (err) { - res.status(500).send('Errore nella generazione dell\'immagine'); + res.status(500).send('Generating skin image error'); return; } res.end(buf); }); } catch (error) { - console.error('Errore nel caricamento della skin:', error); - res.status(500).send('Errore nel caricamento della skin'); + console.error('Loading skin error:', error); + res.status(500).send('Loading skin error'); } }); app.listen(port, () => { - console.log(`Server in ascolto su http://localhost:${port}`); + //console.log(`Server listening to http://localhost:${port}`); }); diff --git a/js/index.js b/js/index.js index 4e304fb..941b150 100644 --- a/js/index.js +++ b/js/index.js @@ -4,10 +4,11 @@ function increase(index, n) { } function setCurrent(index, n) { - func_092018(index, temp[index] = n) + rawSetCurrent(index, temp[index] = n) } -function func_092018(index, n) { +// Dont use. Use setCurrent instead. This is an internal function. +function rawSetCurrent(index, n) { let slideshow = document.getElementById(`slideshow-${index}`) let slides = slideshow.children