incanto 0.7.1 → 0.8.0

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.
Files changed (47) hide show
  1. package/bin/incanto-check.mjs +6 -4
  2. package/dist/2d.d.ts +91 -3
  3. package/dist/2d.js +4 -4
  4. package/dist/3d.d.ts +43 -4
  5. package/dist/3d.js +4 -4
  6. package/dist/{audio-player-C3bH_eZ5.d.ts → audio-player-Dyjg5k92.d.ts} +1 -1
  7. package/dist/audit-C6rMyict.js +58 -0
  8. package/dist/{behavior-q3cejJgs.d.ts → behavior-Bod1AyJS.d.ts} +31 -1
  9. package/dist/{create-game-rFulaS3s.js → create-game-66c4iYJE.js} +4 -5
  10. package/dist/{create-game-DuDkqnjl.js → create-game-BNDSbhy-.js} +4 -5
  11. package/dist/debug.d.ts +1 -1
  12. package/dist/{errors-BMFaY68Q.d.ts → errors-1dXlIwoR.d.ts} +7 -1
  13. package/dist/{gameplay-CDFgSG6z.js → gameplay-DPMgZk9W.js} +108 -1
  14. package/dist/gameplay.d.ts +44 -3
  15. package/dist/gameplay.js +2 -2
  16. package/dist/index.d.ts +151 -9
  17. package/dist/index.js +189 -4
  18. package/dist/{loader-DnLMMRy8.d.ts → loader-BcUDfNHn.d.ts} +1 -1
  19. package/dist/net.d.ts +46 -2
  20. package/dist/net.js +54 -2
  21. package/dist/particle-sim-CyUU7HVU.js +281 -0
  22. package/dist/{physics-2d-CZM5Y90X.js → physics-2d-q2N362ph.js} +45 -4
  23. package/dist/{physics-3d-DT5e8izo.js → physics-3d-CvHr31d4.js} +1 -1
  24. package/dist/react.d.ts +1 -1
  25. package/dist/react.js +1 -1
  26. package/dist/{register-CpXcMiEk.js → register-Cbs7QxoV.js} +139 -4
  27. package/dist/{register-Cl3pAxX-.js → register-Cqjxrfq0.js} +254 -4
  28. package/dist/{register-C35HDZpm.js → register-CxmuI9FL.js} +1 -1
  29. package/dist/{particle-sim-m3CdTGSl.js → register-DRPIjrKG.js} +1178 -278
  30. package/dist/test.d.ts +4 -10
  31. package/dist/test.js +11 -16
  32. package/editor/assets/{agent8-N4bwVH7C.js → agent8-B8QnWCeP.js} +1 -1
  33. package/editor/assets/{index-CXFNanuR.js → index-CVhnNkb3.js} +81 -81
  34. package/editor/index.html +1 -1
  35. package/package.json +1 -1
  36. package/schemas/scene.schema.json +427 -0
  37. package/skills/incanto-3d-character.md +14 -0
  38. package/skills/incanto-audio.md +23 -0
  39. package/skills/incanto-building-2d-games.md +31 -0
  40. package/skills/incanto-building-3d-games.md +21 -0
  41. package/skills/incanto-gameplay-behaviors.md +28 -0
  42. package/skills/incanto-hud.md +24 -0
  43. package/skills/incanto-multiplayer.md +27 -0
  44. package/skills/incanto-node-reference.md +73 -0
  45. package/skills/incanto-physics-and-input.md +9 -0
  46. package/skills/incanto-verifying-your-game.md +31 -0
  47. package/dist/register-Dl_ixIJe.js +0 -834
@@ -1,10 +1,10 @@
1
1
  import { f as Node } from "./loader-B4OEXDZ8.js";
2
- import { i as applyParticlePreset, o as effectiveOrder, r as PARTICLE_PRESET_NAMES, t as ParticleSim } from "./particle-sim-m3CdTGSl.js";
2
+ import { t as registerCoreNodes } from "./register-DRPIjrKG.js";
3
3
  import { t as IncantoError } from "./errors-BpWbnbb_.js";
4
4
  import { t as Rng } from "./rng-DP-SR7eg.js";
5
- import { t as registerCoreNodes } from "./register-Dl_ixIJe.js";
6
5
  import { i as getNodeSchema, l as registerNode } from "./registry-BVJ2HbCn.js";
7
- import { AdditiveBlending, CanvasTexture, Color, DynamicDrawUsage, Group, InstancedMesh, MathUtils, Matrix4, Mesh, MeshBasicMaterial, NormalBlending, Object3D, PlaneGeometry } from "three";
6
+ import { i as applyParticlePreset, o as effectiveOrder, r as PARTICLE_PRESET_NAMES, t as ParticleSim } from "./particle-sim-CyUU7HVU.js";
7
+ import { AdditiveBlending, BufferAttribute, BufferGeometry, CanvasTexture, Color, DynamicDrawUsage, Group, InstancedMesh, MathUtils, Matrix4, Mesh, MeshBasicMaterial, NearestFilter, NormalBlending, Object3D, PlaneGeometry } from "three";
8
8
  //#region src/2d/physics/collider-validate.ts
9
9
  /**
10
10
  * Hard-validate a 2D collider prop — called at LOAD time (via the loader's
@@ -15,6 +15,7 @@ import { AdditiveBlending, CanvasTexture, Color, DynamicDrawUsage, Group, Instan
15
15
  function validateCollider2D(collider, nodeName) {
16
16
  const shape = collider.shape;
17
17
  if (shape === void 0) return;
18
+ if (collider.oneWay !== void 0 && typeof collider.oneWay !== "boolean") throw new IncantoError("BAD_FORMAT", `Collider on '${nodeName}': "oneWay" must be a boolean (platforms you jump up through), got ${JSON.stringify(collider.oneWay)}.`);
18
19
  if (shape === "rect") {
19
20
  const size = collider.size;
20
21
  if (!Array.isArray(size) || size.length !== 2 || size.some((v) => typeof v !== "number")) throw new IncantoError("BAD_FORMAT", `Collider on '${nodeName}': rect needs "size": [width, height].`);
@@ -874,6 +875,254 @@ const colorScratchA = new Color();
874
875
  const colorScratchB = new Color();
875
876
  const colorScratchC = new Color();
876
877
  //#endregion
878
+ //#region src/2d/tilemap-grid.ts
879
+ /**
880
+ * Normalize the `cells` prop into an index grid. Two author formats:
881
+ * - string rows: `"." `/`" "` = empty, digits `0-9` = tile index, anything
882
+ * else must be in `legend` (char → index). Unknown chars HARD-fail.
883
+ * - number rows: passed through (`-1` = empty).
884
+ * Ragged rows are right-padded with empty.
885
+ */
886
+ function parseCells(cells, legend) {
887
+ const rows = [];
888
+ let width = 0;
889
+ for (const row of cells) {
890
+ const out = [];
891
+ if (typeof row === "string") for (const ch of row) {
892
+ const mapped = legend[ch];
893
+ if (mapped !== void 0) out.push(mapped);
894
+ else if (ch === "." || ch === " ") out.push(-1);
895
+ else if (ch >= "0" && ch <= "9") out.push(ch.charCodeAt(0) - 48);
896
+ else throw new IncantoError("BAD_FORMAT", `TileMap2D: unknown tile char '${ch}' — add it to "legend" (char → tile index), or use '.'/' ' for empty and digits 0-9.`);
897
+ }
898
+ else for (const v of row) out.push(v);
899
+ width = Math.max(width, out.length);
900
+ rows.push(out);
901
+ }
902
+ for (const row of rows) while (row.length < width) row.push(-1);
903
+ return rows;
904
+ }
905
+ /**
906
+ * Greedy rectangle merge over the solid cells: maximal horizontal runs,
907
+ * extended downward while the identical run repeats. A platform level's
908
+ * hundreds of solid tiles collapse to a handful of colliders.
909
+ */
910
+ function mergeSolidRects(grid, solid) {
911
+ const h = grid.length;
912
+ const w = h > 0 ? grid[0].length : 0;
913
+ const used = grid.map((row) => row.map(() => false));
914
+ const isSolid = (x, y) => solid.has(grid[y][x]);
915
+ const rects = [];
916
+ for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {
917
+ if (!isSolid(x, y) || used[y][x]) continue;
918
+ let runW = 1;
919
+ while (x + runW < w && isSolid(x + runW, y) && !used[y][x + runW]) runW++;
920
+ let runH = 1;
921
+ grow: while (y + runH < h) {
922
+ for (let i = 0; i < runW; i++) if (!isSolid(x + i, y + runH) || used[y + runH][x + i]) break grow;
923
+ runH++;
924
+ }
925
+ for (let dy = 0; dy < runH; dy++) for (let i = 0; i < runW; i++) used[y + dy][x + i] = true;
926
+ rects.push({
927
+ x,
928
+ y,
929
+ w: runW,
930
+ h: runH
931
+ });
932
+ }
933
+ return rects;
934
+ }
935
+ //#endregion
936
+ //#region src/2d/nodes/tile-map-2d.ts
937
+ /**
938
+ * A whole tile level as ONE node — grid render in a single draw call plus
939
+ * greedy-merged static colliders. Author the level as rows of characters:
940
+ *
941
+ * { "name": "Level", "type": "TileMap2D", "props": {
942
+ * "texture": "$tiles", "tileSize": 32,
943
+ * "cells": [
944
+ * "..................",
945
+ * "......111.........",
946
+ * "000000000000000000"
947
+ * ],
948
+ * "solid": [0, 1] } }
949
+ *
950
+ * `.` / space = empty, digits 0-9 = atlas tile index, other chars map through
951
+ * `legend` (e.g. `{"G": 12}`). The atlas is read left-to-right, top-to-bottom
952
+ * in `tileSize` squares. Tiles listed in `solid` become static colliders,
953
+ * greedy-merged into a few rectangles (hundreds of cells → a handful of
954
+ * bodies). Cell (0,0) renders with its TOP-LEFT on this node's origin.
955
+ */
956
+ var TileMap2D = class extends Node2D {
957
+ static typeName = "TileMap2D";
958
+ static props = {
959
+ /** Atlas texture asset ref; tiles are tileSize×tileSize squares in it. */
960
+ texture: { default: "" },
961
+ tileSize: { default: 32 },
962
+ /** Atlas columns; 0 = derive from the texture width. */
963
+ columns: { default: 0 },
964
+ /** Rows of chars (or number arrays, -1 empty). */
965
+ cells: { default: [] },
966
+ /** char → atlas tile index for non-digit chars. */
967
+ legend: { default: {} },
968
+ /** Tile indices that get merged static colliders. */
969
+ solid: { default: [] },
970
+ opacity: { default: 1 }
971
+ };
972
+ texture = "";
973
+ tileSize = 32;
974
+ columns = 0;
975
+ _cells = [];
976
+ _legend = {};
977
+ _solid = [];
978
+ /** Rebuild flags — raised when the map-shaping props are REPLACED. */
979
+ geometryDirty = true;
980
+ collidersDirty = true;
981
+ /** Replace the whole array to change the map (mutations are not watched). */
982
+ get cells() {
983
+ return this._cells;
984
+ }
985
+ set cells(value) {
986
+ this._cells = value;
987
+ this.geometryDirty = true;
988
+ this.collidersDirty = true;
989
+ }
990
+ get legend() {
991
+ return this._legend;
992
+ }
993
+ set legend(value) {
994
+ this._legend = value;
995
+ this.geometryDirty = true;
996
+ this.collidersDirty = true;
997
+ }
998
+ get solid() {
999
+ return this._solid;
1000
+ }
1001
+ set solid(value) {
1002
+ this._solid = value;
1003
+ this.collidersDirty = true;
1004
+ }
1005
+ opacity = 1;
1006
+ tileMesh = null;
1007
+ builtColumns = 0;
1008
+ builtRows = 0;
1009
+ /** Loader hook: bad cells fail at LOAD (unknown chars), not at render. */
1010
+ static validateJson(node) {
1011
+ const map = node;
1012
+ parseCells(map._cells, map._legend);
1013
+ }
1014
+ /** The parsed index grid (test/tooling hook). */
1015
+ grid() {
1016
+ return parseCells(this._cells, this._legend);
1017
+ }
1018
+ onReady() {
1019
+ this.rebuildColliders();
1020
+ }
1021
+ update(_dt) {
1022
+ if (this.collidersDirty) this.rebuildColliders();
1023
+ }
1024
+ rebuildColliders() {
1025
+ this.collidersDirty = false;
1026
+ for (const child of [...this.children]) if (child.name.startsWith("__tileSolid")) child.free();
1027
+ if (this._solid.length === 0) return;
1028
+ const ts = this.tileSize;
1029
+ mergeSolidRects(this.grid(), new Set(this._solid)).forEach((r, i) => {
1030
+ const body = new StaticBody2D(`__tileSolid${i}`);
1031
+ body.position = [(r.x + r.w / 2) * ts, (r.y + r.h / 2) * ts];
1032
+ body.collider = {
1033
+ shape: "rect",
1034
+ size: [r.w * ts, r.h * ts]
1035
+ };
1036
+ this.addChild(body);
1037
+ });
1038
+ }
1039
+ /** @internal The drawable mesh (lazily created under the backing object). */
1040
+ _mesh() {
1041
+ if (!this.tileMesh) {
1042
+ this.tileMesh = new Mesh(new BufferGeometry(), new MeshBasicMaterial({
1043
+ transparent: true,
1044
+ depthWrite: false
1045
+ }));
1046
+ this._ensureObject2D().add(this.tileMesh);
1047
+ }
1048
+ return this.tileMesh;
1049
+ }
1050
+ _syncObject2D(assets) {
1051
+ super._syncObject2D(assets);
1052
+ const mesh = this._mesh();
1053
+ const mat = mesh.material;
1054
+ if (!this.texture || !assets) {
1055
+ mesh.visible = false;
1056
+ return;
1057
+ }
1058
+ const texture = assets.getTexture(this.texture);
1059
+ const image = texture.image;
1060
+ if (!image?.width || !image.height) {
1061
+ mesh.visible = false;
1062
+ return;
1063
+ }
1064
+ mesh.visible = this.opacity > 0;
1065
+ mesh.renderOrder = this.effectiveRenderOrder;
1066
+ mat.opacity = this.opacity;
1067
+ if (mat.map !== texture) {
1068
+ texture.magFilter = NearestFilter;
1069
+ mat.map = texture;
1070
+ mat.needsUpdate = true;
1071
+ this.geometryDirty = true;
1072
+ }
1073
+ const columns = this.columns > 0 ? this.columns : Math.max(1, Math.floor(image.width / this.tileSize));
1074
+ const atlasRows = Math.max(1, Math.floor(image.height / this.tileSize));
1075
+ if (columns !== this.builtColumns || atlasRows !== this.builtRows) this.geometryDirty = true;
1076
+ if (!this.geometryDirty) return;
1077
+ this.geometryDirty = false;
1078
+ this.builtColumns = columns;
1079
+ this.builtRows = atlasRows;
1080
+ this.buildGeometry(mesh.geometry, columns, atlasRows);
1081
+ }
1082
+ /** One quad per visible tile, atlas UVs — a single draw call for the level. */
1083
+ buildGeometry(geometry, columns, atlasRows) {
1084
+ const grid = this.grid();
1085
+ const ts = this.tileSize;
1086
+ const positions = [];
1087
+ const uvs = [];
1088
+ const indices = [];
1089
+ for (let y = 0; y < grid.length; y++) {
1090
+ const row = grid[y];
1091
+ for (let x = 0; x < row.length; x++) {
1092
+ const tile = row[x];
1093
+ if (tile < 0) continue;
1094
+ const x0 = x * ts;
1095
+ const x1 = x0 + ts;
1096
+ const y0 = -(y * ts);
1097
+ const y1 = -((y + 1) * ts);
1098
+ const base = positions.length / 3;
1099
+ positions.push(x0, y0, 0, x1, y0, 0, x1, y1, 0, x0, y1, 0);
1100
+ const col = tile % columns;
1101
+ const rowIdx = Math.floor(tile / columns);
1102
+ const u0 = col / columns;
1103
+ const u1 = (col + 1) / columns;
1104
+ const v0 = 1 - rowIdx / atlasRows;
1105
+ const v1 = 1 - (rowIdx + 1) / atlasRows;
1106
+ uvs.push(u0, v0, u1, v0, u1, v1, u0, v1);
1107
+ indices.push(base, base + 2, base + 1, base, base + 3, base + 2);
1108
+ }
1109
+ }
1110
+ geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
1111
+ geometry.setAttribute("uv", new BufferAttribute(new Float32Array(uvs), 2));
1112
+ geometry.setIndex(indices);
1113
+ geometry.computeBoundingSphere();
1114
+ }
1115
+ /** Test hook: rendered tile count (quads in the built geometry). */
1116
+ get renderedTileCount() {
1117
+ const pos = this.tileMesh?.geometry.getAttribute("position");
1118
+ return pos ? pos.count / 4 : 0;
1119
+ }
1120
+ free() {
1121
+ this.tileMesh?.geometry.dispose();
1122
+ super.free();
1123
+ }
1124
+ };
1125
+ //#endregion
877
1126
  //#region src/2d/nodes/ui-layer.ts
878
1127
  const ANCHORS = [
879
1128
  "top-left",
@@ -949,6 +1198,7 @@ function registerNodes2D() {
949
1198
  registerNode(CharacterBody2D);
950
1199
  registerNode(CharacterController2D);
951
1200
  registerNode(Joint2D);
1201
+ registerNode(TileMap2D);
952
1202
  }
953
1203
  //#endregion
954
- export { validateCollider2D as _, ColorRect2D as a, AnimatedSprite2D as c, Area2D as d, CharacterBody2D as f, Node2D as g, StaticBody2D as h, Label as i, Sprite2D as l, RigidBody2D as m, UILayer as n, CharacterController2D as o, PhysicsBody2D as p, Particles2D as r, Camera2D as s, registerNodes2D as t, Joint2D as u };
1204
+ export { RigidBody2D as _, parseCells as a, validateCollider2D as b, ColorRect2D as c, AnimatedSprite2D as d, Sprite2D as f, PhysicsBody2D as g, CharacterBody2D as h, mergeSolidRects as i, CharacterController2D as l, Area2D as m, UILayer as n, Particles2D as o, Joint2D as p, TileMap2D as r, Label as s, registerNodes2D as t, Camera2D as u, StaticBody2D as v, Node2D as y };
@@ -1,6 +1,6 @@
1
1
  import { f as Node, t as buildNodeJson, y as Signal } from "./loader-B4OEXDZ8.js";
2
+ import { t as registerCoreNodes } from "./register-DRPIjrKG.js";
2
3
  import { t as IncantoError } from "./errors-BpWbnbb_.js";
3
- import { t as registerCoreNodes } from "./register-Dl_ixIJe.js";
4
4
  import { n as jsonEquals, t as jsonClone } from "./json-BLk7H2Qa.js";
5
5
  import { l as registerNode } from "./registry-BVJ2HbCn.js";
6
6
  //#region src/net/network-manager.ts