minecraft-inventory 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const POOL_SIZE = 8
|
|
7
|
-
const OUTPUT_SIZE =
|
|
7
|
+
const OUTPUT_SIZE = 64
|
|
8
8
|
|
|
9
9
|
const pool: HTMLCanvasElement[] = []
|
|
10
10
|
const inUse = new Set<HTMLCanvasElement>()
|
|
@@ -59,42 +59,43 @@ export function renderBlockIcon(
|
|
|
59
59
|
ctx.imageSmoothingEnabled = false
|
|
60
60
|
ctx.clearRect(0, 0, OUTPUT_SIZE, OUTPUT_SIZE)
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
62
|
+
// Parameters from the original minecraft-inventory-gui renderer
|
|
63
|
+
const A = 0.9 // horizontal compression (makes blocks narrower/taller)
|
|
64
|
+
const K = 0.5 // skew factor
|
|
65
|
+
const s = OUTPUT_SIZE / 2 - 2
|
|
66
|
+
const cubeWidth = 2 * A * s
|
|
67
|
+
const cubeHeight = 2 * K * s + s
|
|
68
|
+
const ox = Math.round((OUTPUT_SIZE - cubeWidth) / 2)
|
|
69
|
+
const topY = Math.round((OUTPUT_SIZE - cubeHeight) / 2)
|
|
70
|
+
const ex = ox
|
|
71
|
+
const ey = topY + K * s
|
|
72
|
+
|
|
65
73
|
const [tx, ty, tw, th] = top
|
|
66
74
|
const [lx, ly, lw, lh] = left
|
|
67
75
|
const [rx, ry, rw, rh] = right
|
|
68
76
|
|
|
69
|
-
// Enable smoothing for isometric transforms (better diagonal edges)
|
|
70
77
|
ctx.imageSmoothingEnabled = true
|
|
71
78
|
ctx.imageSmoothingQuality = 'high'
|
|
72
79
|
|
|
73
|
-
// Isometric cube using affine transforms.
|
|
74
|
-
// Face vertices for a cube centered in OUTPUT_SIZE × OUTPUT_SIZE:
|
|
75
|
-
// Top: (s+ox, oy) → (2s+ox, s/2+oy) → (s+ox, s+oy) → (ox, s/2+oy)
|
|
76
|
-
// Left: (ox, s/2+oy) → (s+ox, s+oy) → (s+ox, 2s+oy) → (ox, 3s/2+oy)
|
|
77
|
-
// Right: (s+ox, s+oy) → (2s+ox, s/2+oy) → (2s+ox, 3s/2+oy) → (s+ox, 2s+oy)
|
|
78
|
-
|
|
79
80
|
// Top face
|
|
80
81
|
ctx.save()
|
|
81
|
-
ctx.setTransform(
|
|
82
|
+
ctx.setTransform(A, -K, A, K, ex, ey)
|
|
82
83
|
ctx.drawImage(image, tx, ty, tw, th, 0, 0, s, s)
|
|
83
84
|
ctx.restore()
|
|
84
85
|
|
|
85
|
-
// Left face (darkened)
|
|
86
|
+
// Left face (lightly darkened)
|
|
86
87
|
ctx.save()
|
|
87
|
-
ctx.setTransform(
|
|
88
|
+
ctx.setTransform(A, K, 0, 1, ex, ey)
|
|
88
89
|
ctx.drawImage(image, lx, ly, lw, lh, 0, 0, s, s)
|
|
89
|
-
ctx.fillStyle = 'rgba(0, 0, 0, 0.
|
|
90
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.35)'
|
|
90
91
|
ctx.fillRect(0, 0, s, s)
|
|
91
92
|
ctx.restore()
|
|
92
93
|
|
|
93
|
-
// Right face (
|
|
94
|
+
// Right face (darkened — light comes from upper-left)
|
|
94
95
|
ctx.save()
|
|
95
|
-
ctx.setTransform(
|
|
96
|
+
ctx.setTransform(A, -K, 0, 1, A * s + ex, K * s + ey)
|
|
96
97
|
ctx.drawImage(image, rx, ry, rw, rh, 0, 0, s, s)
|
|
97
|
-
ctx.fillStyle = 'rgba(0, 0, 0, 0.
|
|
98
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)'
|
|
98
99
|
ctx.fillRect(0, 0, s, s)
|
|
99
100
|
ctx.restore()
|
|
100
101
|
|