cubeforge 0.3.6 → 0.3.8
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/dist/index.js +18 -8
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1502,7 +1502,8 @@ var RenderSystem = class {
|
|
|
1502
1502
|
loadTexture(src) {
|
|
1503
1503
|
const cached = this.textures.get(src);
|
|
1504
1504
|
if (cached) return cached;
|
|
1505
|
-
const
|
|
1505
|
+
const imgSrc = src.endsWith(":repeat") ? src.slice(0, -7) : src;
|
|
1506
|
+
const existing = this.imageCache.get(imgSrc);
|
|
1506
1507
|
if (existing && existing.complete && existing.naturalWidth > 0) {
|
|
1507
1508
|
const gl = this.gl;
|
|
1508
1509
|
const tex = gl.createTexture();
|
|
@@ -1518,7 +1519,8 @@ var RenderSystem = class {
|
|
|
1518
1519
|
}
|
|
1519
1520
|
if (!existing) {
|
|
1520
1521
|
const img = new Image();
|
|
1521
|
-
img.src =
|
|
1522
|
+
img.src = imgSrc;
|
|
1523
|
+
const tiled = src.endsWith(":repeat");
|
|
1522
1524
|
img.onload = () => {
|
|
1523
1525
|
const gl = this.gl;
|
|
1524
1526
|
const tex = gl.createTexture();
|
|
@@ -1527,11 +1529,12 @@ var RenderSystem = class {
|
|
|
1527
1529
|
gl.generateMipmap(gl.TEXTURE_2D);
|
|
1528
1530
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
1529
1531
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
1530
|
-
|
|
1531
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.
|
|
1532
|
+
const wrap = tiled ? gl.REPEAT : gl.CLAMP_TO_EDGE;
|
|
1533
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap);
|
|
1534
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap);
|
|
1532
1535
|
this.textures.set(src, tex);
|
|
1533
1536
|
};
|
|
1534
|
-
this.imageCache.set(
|
|
1537
|
+
this.imageCache.set(imgSrc, img);
|
|
1535
1538
|
}
|
|
1536
1539
|
return this.whiteTexture;
|
|
1537
1540
|
}
|
|
@@ -1674,8 +1677,14 @@ var RenderSystem = class {
|
|
|
1674
1677
|
if (dy > halfH) cam.y = t.y - halfH;
|
|
1675
1678
|
else if (dy < -halfH) cam.y = t.y + halfH;
|
|
1676
1679
|
} else if (cam.smoothing > 0) {
|
|
1677
|
-
|
|
1678
|
-
|
|
1680
|
+
const distSq = (t.x - cam.x) ** 2 + (t.y - cam.y) ** 2;
|
|
1681
|
+
if (distSq > 16e4) {
|
|
1682
|
+
cam.x = t.x;
|
|
1683
|
+
cam.y = t.y;
|
|
1684
|
+
} else {
|
|
1685
|
+
cam.x += (t.x - cam.x) * (1 - cam.smoothing);
|
|
1686
|
+
cam.y += (t.y - cam.y) * (1 - cam.smoothing);
|
|
1687
|
+
}
|
|
1679
1688
|
} else {
|
|
1680
1689
|
cam.x = t.x;
|
|
1681
1690
|
cam.y = t.y;
|
|
@@ -1835,7 +1844,8 @@ var RenderSystem = class {
|
|
|
1835
1844
|
const ss = world.getComponent(id, "SquashStretch");
|
|
1836
1845
|
const scaleXMod = ss ? ss.currentScaleX : 1;
|
|
1837
1846
|
const scaleYMod = ss ? ss.currentScaleY : 1;
|
|
1838
|
-
const
|
|
1847
|
+
const hasTexture = sprite.image && sprite.image.complete && sprite.image.naturalWidth > 0;
|
|
1848
|
+
const [r, g, b, a] = hasTexture ? [1, 1, 1, 1] : parseCSSColor(sprite.color);
|
|
1839
1849
|
const uv = getUVRect(sprite);
|
|
1840
1850
|
this.writeInstance(
|
|
1841
1851
|
batchCount * FLOATS_PER_INSTANCE,
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cubeforge",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "React-first 2D browser game engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./dist/index.d.
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
}
|