Skip to content

Commit 7c40c0a

Browse files
committed
Fixed #4
1 parent 1be7f26 commit 7c40c0a

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed
Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Should generate a skin 3D render based on the uuid
2+
13
const express = require('express');
24
const { createCanvas, loadImage } = require('canvas');
35
const fetch = require('node-fetch');
@@ -9,103 +11,103 @@ app.get('/assets/frozenblock/render/skin.png', async (req, res) => {
911
const uuid = req.query.uuid;
1012

1113
if (!uuid) {
12-
res.status(400).send('UUID non fornito');
14+
res.status(400).send('UUID not found');
1315
return;
1416
}
1517

1618
try {
17-
// Carica la skin di Minecraft usando l'UUID
19+
// Fetch UUID from mojang
1820
const response = await fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${uuid}`);
1921
const data = await response.json();
2022
const textures = data.properties.find(prop => prop.name === "textures");
2123

2224
if (!textures) {
23-
res.status(404).send('Texture non trovata per l\'UUID fornito');
25+
res.status(404).send('Texture not found for given UUID');
2426
return;
2527
}
2628

2729
const textureData = JSON.parse(Buffer.from(textures.value, 'base64').toString('utf-8'));
2830
const skinUrl = textureData['textures']['SKIN']['url'];
2931

30-
// Crea un canvas con dimensioni 360x864
32+
// Create a 360x864 canvas
3133
const width = 360;
3234
const height = 864;
3335
const canvas = createCanvas(width, height);
3436
const ctx = canvas.getContext('2d');
3537

36-
// Imposta lo sfondo trasparente
38+
// Set the background to transparent
3739
ctx.clearRect(0, 0, width, height);
3840

39-
// Carica l'immagine della skin
41+
// Load Skin image
4042
const skinImage = await loadImage(skinUrl);
4143

42-
// Imposta il filtro "nearest neighbor" per un effetto pixelato
44+
// sets Nearest Neighbor
4345
ctx.imageSmoothingEnabled = false;
4446

45-
const scale = 20; // Scala per ingrandire il rombo
47+
const scale = 20; // Scale image
4648

47-
// Centro della testa
49+
// Middle of head
4850
const centerX = width / 2;
49-
const topMargin = 100; // Spostamento verticale
51+
const topMargin = 100; // Vertical translation
5052

51-
// === Prima faccia (frontale) ===
53+
// === First face ===
5254
const frontSx = 8;
5355
const frontSy = 8;
5456
const sWidth = 8;
5557
const sHeight = 8;
5658

57-
// Trasformazione isometrica per la prima faccia (frontale)
59+
// Isometric transform for first face
5860
ctx.setTransform(1, 0.5, 0, 1, centerX - (sWidth * scale) / 2 - 90, topMargin);
59-
// Ombreggiatura per la faccia frontale (nessuna modifica)
61+
// Shadow for first face
6062
ctx.drawImage(skinImage, frontSx, frontSy, sWidth, sHeight, 0, 0, sWidth * scale, sHeight * scale);
6163

62-
// Ripristina la trasformazione originale
64+
// Reset transformations
6365
ctx.setTransform(1, 0, 0, 1, 0, 0);
6466

65-
// === Seconda faccia (laterale destra) ===
67+
// === Second face ===
6668
const rightSx = 16;
6769
const rightSy = 8;
6870

69-
// Trasformazione isometrica per la seconda faccia (laterale destra)
71+
// Isometric transform for second face
7072
ctx.setTransform(1, -0.5, 0, 1, centerX + (sWidth * scale) / 2 - scale - 70, topMargin + 80);
71-
// Ombreggiatura per la faccia laterale (leggermente più scura)
73+
// Shadow for second face
7274
ctx.drawImage(skinImage, rightSx, rightSy, sWidth, sHeight, 0, 0, sWidth * scale, sHeight * scale);
73-
ctx.globalAlpha = 1.0; // Ripristina opacità per le altre facce
75+
ctx.globalAlpha = 1.0; // Resets opacity for other faces
7476

75-
// Ripristina la trasformazione originale
77+
// Reset transformations
7678
ctx.setTransform(1, 0, 0, 1, 0, 0);
7779

78-
// === Terza faccia (superiore) ===
80+
// === Third face ===
7981
const topSx = 8;
8082
const topSy = 0;
8183

82-
// Trasformazione isometrica per la faccia superiore (ruotata e traslata sopra le altre facce)
84+
// Isometric transform for third face
8385
ctx.setTransform(1, 0.5, -1, 0.5, centerX - scale / 2, topMargin - (sHeight * scale) / 2);
84-
// Ombreggiatura per la faccia superiore (ancora più scura)
86+
// Shadow for third face
8587
ctx.drawImage(skinImage, topSx, topSy, sWidth, sHeight, 0, 0, sWidth * scale, sHeight * scale);
86-
ctx.globalAlpha = 1.0; // Ripristina opacità
88+
ctx.globalAlpha = 1.0; // Resets opacity for other faces
8789

88-
// Ripristina la trasformazione originale
90+
// Reset transformations
8991
ctx.setTransform(1, 0, 0, 1, 0, 0);
9092

91-
// Imposta l'intestazione della risposta
93+
// Sets the header
9294
res.setHeader('Content-Type', 'image/png');
9395

94-
// Invia l'immagine generata come risposta
96+
// Sends the image as response
9597
canvas.toBuffer((err, buf) => {
9698
if (err) {
97-
res.status(500).send('Errore nella generazione dell\'immagine');
99+
res.status(500).send('Generating skin image error');
98100
return;
99101
}
100102
res.end(buf);
101103
});
102104

103105
} catch (error) {
104-
console.error('Errore nel caricamento della skin:', error);
105-
res.status(500).send('Errore nel caricamento della skin');
106+
console.error('Loading skin error:', error);
107+
res.status(500).send('Loading skin error');
106108
}
107109
});
108110

109111
app.listen(port, () => {
110-
console.log(`Server in ascolto su http://localhost:${port}`);
112+
//console.log(`Server listening to http://localhost:${port}`);
111113
});

js/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ function increase(index, n) {
44
}
55

66
function setCurrent(index, n) {
7-
func_092018(index, temp[index] = n)
7+
rawSetCurrent(index, temp[index] = n)
88
}
99

10-
function func_092018(index, n) {
10+
// Dont use. Use setCurrent instead. This is an internal function.
11+
function rawSetCurrent(index, n) {
1112
let slideshow = document.getElementById(`slideshow-${index}`)
1213
let slides = slideshow.children
1314

0 commit comments

Comments
 (0)