cubeforge 0.3.2 → 0.3.4
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 +15 -9
- package/package.json +20 -9
package/dist/index.js
CHANGED
|
@@ -1338,8 +1338,8 @@ function createWhiteTexture(gl) {
|
|
|
1338
1338
|
return tex;
|
|
1339
1339
|
}
|
|
1340
1340
|
function getTextureKey(sprite) {
|
|
1341
|
-
|
|
1342
|
-
if (
|
|
1341
|
+
const src = sprite.image?.src || sprite.src;
|
|
1342
|
+
if (src) return sprite.tileX || sprite.tileY ? `${src}:repeat` : src;
|
|
1343
1343
|
return `__color__:${sprite.color}`;
|
|
1344
1344
|
}
|
|
1345
1345
|
function getUVRect(sprite) {
|
|
@@ -1361,7 +1361,9 @@ function getUVRect(sprite) {
|
|
|
1361
1361
|
const { sx, sy, sw, sh } = sprite.frame;
|
|
1362
1362
|
return [sx / iw, sy / ih, sw / iw, sh / ih];
|
|
1363
1363
|
}
|
|
1364
|
-
|
|
1364
|
+
const uw = sprite.tileX ? sprite.width / iw : 1;
|
|
1365
|
+
const vh = sprite.tileY ? sprite.height / ih : 1;
|
|
1366
|
+
return [0, 0, uw, vh];
|
|
1365
1367
|
}
|
|
1366
1368
|
var RenderSystem = class {
|
|
1367
1369
|
constructor(canvas, entityIds) {
|
|
@@ -1790,8 +1792,9 @@ var RenderSystem = class {
|
|
|
1790
1792
|
const sprite = world.getComponent(id, "Sprite");
|
|
1791
1793
|
if (!sprite.visible) continue;
|
|
1792
1794
|
if (sprite.image && sprite.image.complete && sprite.image.naturalWidth > 0) {
|
|
1793
|
-
const
|
|
1794
|
-
|
|
1795
|
+
const tiled = sprite.tileX || sprite.tileY;
|
|
1796
|
+
const cacheKey = sprite.image.src ? tiled ? `${sprite.image.src}:repeat` : sprite.image.src : null;
|
|
1797
|
+
if (cacheKey && !this.textures.has(cacheKey)) {
|
|
1795
1798
|
const gl2 = this.gl;
|
|
1796
1799
|
const tex = gl2.createTexture();
|
|
1797
1800
|
gl2.bindTexture(gl2.TEXTURE_2D, tex);
|
|
@@ -1799,9 +1802,10 @@ var RenderSystem = class {
|
|
|
1799
1802
|
gl2.generateMipmap(gl2.TEXTURE_2D);
|
|
1800
1803
|
gl2.texParameteri(gl2.TEXTURE_2D, gl2.TEXTURE_MIN_FILTER, gl2.LINEAR_MIPMAP_LINEAR);
|
|
1801
1804
|
gl2.texParameteri(gl2.TEXTURE_2D, gl2.TEXTURE_MAG_FILTER, gl2.LINEAR);
|
|
1802
|
-
|
|
1803
|
-
gl2.texParameteri(gl2.TEXTURE_2D, gl2.
|
|
1804
|
-
|
|
1805
|
+
const wrap = tiled ? gl2.REPEAT : gl2.CLAMP_TO_EDGE;
|
|
1806
|
+
gl2.texParameteri(gl2.TEXTURE_2D, gl2.TEXTURE_WRAP_S, wrap);
|
|
1807
|
+
gl2.texParameteri(gl2.TEXTURE_2D, gl2.TEXTURE_WRAP_T, wrap);
|
|
1808
|
+
this.textures.set(cacheKey, tex);
|
|
1805
1809
|
}
|
|
1806
1810
|
} else if (sprite.src && !sprite.image) {
|
|
1807
1811
|
let img = this.imageCache.get(sprite.src);
|
|
@@ -2129,7 +2133,8 @@ function getSlopeSurfaceY(st, sc, worldX) {
|
|
|
2129
2133
|
}
|
|
2130
2134
|
function maskAllows(mask, layer) {
|
|
2131
2135
|
if (mask === "*") return true;
|
|
2132
|
-
|
|
2136
|
+
if (Array.isArray(mask)) return mask.includes(layer);
|
|
2137
|
+
return mask === layer;
|
|
2133
2138
|
}
|
|
2134
2139
|
function canInteract(a, b) {
|
|
2135
2140
|
return maskAllows(a.mask, b.layer) && maskAllows(b.mask, a.layer);
|
|
@@ -3718,6 +3723,7 @@ function Sprite({
|
|
|
3718
3723
|
const viteEnv = import.meta.env;
|
|
3719
3724
|
const base = (viteEnv?.BASE_URL ?? "/").replace(/\/$/, "");
|
|
3720
3725
|
const resolvedSrc = base && src.startsWith("/") ? base + src : src;
|
|
3726
|
+
comp.src = resolvedSrc;
|
|
3721
3727
|
engine.assets.loadImage(resolvedSrc).then((img) => {
|
|
3722
3728
|
const c = engine.ecs.getComponent(entityId, "Sprite");
|
|
3723
3729
|
if (c) c.image = img;
|
package/package.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cubeforge",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "React-first 2D browser game engine",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"typecheck": "tsc --noEmit",
|
|
8
8
|
"build": "tsup"
|
|
9
9
|
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.mts"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
10
20
|
"files": [
|
|
11
21
|
"dist"
|
|
12
22
|
],
|
|
@@ -15,6 +25,14 @@
|
|
|
15
25
|
"react-dom": "^18.0.0"
|
|
16
26
|
},
|
|
17
27
|
"devDependencies": {
|
|
28
|
+
"@cubeforge/audio": "workspace:*",
|
|
29
|
+
"@cubeforge/context": "workspace:*",
|
|
30
|
+
"@cubeforge/core": "workspace:*",
|
|
31
|
+
"@cubeforge/devtools": "workspace:*",
|
|
32
|
+
"@cubeforge/gameplay": "workspace:*",
|
|
33
|
+
"@cubeforge/input": "workspace:*",
|
|
34
|
+
"@cubeforge/physics": "workspace:*",
|
|
35
|
+
"@cubeforge/renderer": "workspace:*",
|
|
18
36
|
"tsup": "^8.0.0"
|
|
19
37
|
},
|
|
20
38
|
"keywords": [
|
|
@@ -28,12 +46,5 @@
|
|
|
28
46
|
"repository": {
|
|
29
47
|
"type": "git",
|
|
30
48
|
"url": "https://github.com/1homsi/cubeforge"
|
|
31
|
-
},
|
|
32
|
-
"types": "./dist/index.d.mts",
|
|
33
|
-
"exports": {
|
|
34
|
-
".": {
|
|
35
|
-
"import": "./dist/index.js",
|
|
36
|
-
"types": "./dist/index.d.mts"
|
|
37
|
-
}
|
|
38
49
|
}
|
|
39
50
|
}
|