bevy-ts 0.1.0-alpha.5 → 0.1.0-alpha.7

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.
@@ -1,15 +1,15 @@
1
- // The arena: a player and a HUD in TSX, the enemies placed by assets/levels/arena.bsn, a camera, and
1
+ // The arena: a player, a HUD and the sun in TSX, the enemies placed by assets/levels/arena.bsn, a camera, and
2
2
  // three systems that play. `bevy-ts dev src/game.tsx`.
3
3
  import { app, type Commands, type Entity, type Local, type Mut, type Query, ref, type Res, Startup, Time, Transform, type u32, Update, type With, type Without } from "bevy-ts";
4
+ import { DirectionalLight } from "bevy-ts/bevy";
4
5
  import { Foe, Health } from "./enemy.tsx";
5
6
  import { Hud } from "./hud.tsx";
6
7
  import { Player, PlayerUnit } from "./player.tsx";
7
8
 
8
- /** The game's camera and light. The camera sits where the editor's first view does, so edit mode
9
- * opens on the same view. */
9
+ /** The game's camera. It sits where the editor's first view does, so edit mode opens on the same
10
+ * view. */
10
11
  export function stage(commands: Commands) {
11
12
  commands.spawnNative("camera3d", { position: [-6, 5, 10], lookAt: [0, 0, 0] });
12
- commands.spawnNative("directionalLight", { position: [3, 6, 2], lookAt: [0, 0, 0] });
13
13
  }
14
14
 
15
15
  /** Every 30 frames, each enemy within 10 units hurts the player by 5. */
@@ -44,6 +44,11 @@ export function cull(commands: Commands, enemies: Query<[Entity, Health], With<F
44
44
  const player = ref();
45
45
  app.scene("arena", () => (
46
46
  <>
47
+ {/* The sun is scene, not a startup's, so edit mode shows the arena lit. At (3, 6, 2), looking at the origin. */}
48
+ <entity name="sun">
49
+ <DirectionalLight shadow_maps_enabled />
50
+ <Transform translation={[3, 6, 2]} rotation={[-0.4341, 0.4107, 0.2323, 0.7674]} />
51
+ </entity>
47
52
  <PlayerUnit handle={player} />
48
53
  <Hud player={player} />
49
54
  </>
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "cube",
3
3
  "title": "Cube",
4
- "description": "One cube bobbing on a sine wave: a component, a startup system and an update system.",
4
+ "description": "One cube bobbing on a sine wave: a scene, a component, a startup system and an update system.",
5
5
  "entry": "src/game.ts"
6
6
  }
@@ -0,0 +1,19 @@
1
+ // The cube's scene: the cube and the sun, so edit mode shows them before any system runs.
2
+ // game.ts mounts it once `Mover` is defined.
3
+ import { DirectionalLight, Transform } from "bevy-ts/bevy";
4
+ import { Mover } from "./game.ts";
5
+
6
+ export const Cube = () => (
7
+ <>
8
+ {/* At (3, 6, 2), looking at the origin. */}
9
+ <entity name="sun">
10
+ <DirectionalLight shadow_maps_enabled />
11
+ <Transform translation={[3, 6, 2]} rotation={[-0.4341, 0.4107, 0.2323, 0.7674]} />
12
+ </entity>
13
+ <entity name="cube">
14
+ <Transform />
15
+ <mesh shape="cuboid" size={[1, 1, 1]} color="#ff8800" />
16
+ <Mover />
17
+ </entity>
18
+ </>
19
+ );
@@ -1,16 +1,15 @@
1
1
  import { app, Component, type f32, Startup, Time, Transform, Update } from "bevy-ts";
2
2
  import type { Commands, Mut, Query, Res } from "bevy-ts";
3
+ import { Cube } from "./cube.tsx";
3
4
 
4
5
  export class Mover extends Component {
5
6
  speed: f32 = 1;
6
7
  amplitude: f32 = 2;
7
8
  }
8
9
 
10
+ /** The game's camera; the cube and the sun are the scene's, in cube.tsx. */
9
11
  export function scene(commands: Commands) {
10
12
  commands.spawnNative("camera3d", { position: [-3, 3, 6], lookAt: [0, 0, 0] });
11
- commands.spawnNative("directionalLight", { position: [3, 6, 2], lookAt: [0, 0, 0] });
12
- const cube = commands.spawnNative("cuboid", { size: [1, 1, 1], color: "#f80" });
13
- commands.entity(cube).insert(Mover.of());
14
13
  }
15
14
 
16
15
  export function bob(time: Res<Time>, q: Query<[Mover, Mut<Transform>]>) {
@@ -19,4 +18,5 @@ export function bob(time: Res<Time>, q: Query<[Mover, Mut<Transform>]>) {
19
18
  });
20
19
  }
21
20
 
21
+ app.scene("cube", Cube);
22
22
  app.addSystems(Startup, scene).addSystems(Update, bob);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bevy-ts",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.7",
4
4
  "description": "TypeScript for Bevy: components, systems and hot reload without recompiling Rust",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {
@@ -59,11 +59,11 @@
59
59
  "examples"
60
60
  ],
61
61
  "optionalDependencies": {
62
- "@bevy-ts/darwin-arm64": "0.1.0-alpha.5",
63
- "@bevy-ts/darwin-x64": "0.1.0-alpha.5",
64
- "@bevy-ts/linux-arm64": "0.1.0-alpha.5",
65
- "@bevy-ts/linux-x64": "0.1.0-alpha.5",
66
- "@bevy-ts/win32-x64": "0.1.0-alpha.5"
62
+ "@bevy-ts/darwin-arm64": "0.1.0-alpha.7",
63
+ "@bevy-ts/darwin-x64": "0.1.0-alpha.7",
64
+ "@bevy-ts/linux-arm64": "0.1.0-alpha.7",
65
+ "@bevy-ts/linux-x64": "0.1.0-alpha.7",
66
+ "@bevy-ts/win32-x64": "0.1.0-alpha.7"
67
67
  },
68
68
  "devDependencies": {
69
69
  "json-schema-to-typescript": "^15.0.4",
package/protocol.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // @generated by packages/bevy-ts/scripts/gen-protocol.mjs from protocol/bevy-ts.openrpc.json. Do not edit.
2
2
 
3
3
  /** The protocol version these types describe. */
4
- export const PROTOCOL_VERSION: "1.17.0";
4
+ export const PROTOCOL_VERSION: "1.20.0";
5
5
 
6
6
  /**
7
7
  * An entity id: Entity::to_bits.
@@ -133,6 +133,13 @@ export type AssetLoadState = "not_loaded" | "loading" | "loaded" | "failed";
133
133
  * via the `definition` "LevelHash".
134
134
  */
135
135
  export type LevelHash = string;
136
+ /**
137
+ * Who opened a level: app.level (ts), add_level (rust), bevy-ts/level_open (editor) or a scene's sidecar.
138
+ *
139
+ * This interface was referenced by `ProtocolTypes`'s JSON-Schema
140
+ * via the `definition` "LevelOpener".
141
+ */
142
+ export type LevelOpener = "ts" | "rust" | "editor" | "sidecar";
136
143
  /**
137
144
  * A value the writer prints: a number (a float), {int}, a bool, a string, {type, lanes} for a vector or {path} for a variant or constant.
138
145
  *
@@ -307,6 +314,10 @@ export type LevelOp =
307
314
  path: string[];
308
315
  component: string;
309
316
  };
317
+ /**
318
+ * Who opened a level: app.level (ts), add_level (rust), bevy-ts/level_open (editor) or a scene's sidecar.
319
+ */
320
+ export type LevelOpener1 = "ts" | "rust" | "editor" | "sidecar";
310
321
 
311
322
  /**
312
323
  * This interface was referenced by `ProtocolTypes`'s JSON-Schema
@@ -1144,6 +1155,10 @@ export interface TouchEvent {
1144
1155
  */
1145
1156
  touches: TouchPoint[];
1146
1157
  mods?: Modifiers;
1158
+ /**
1159
+ * (1.20) When the touch happened, in ms on the viewer device's own clock. Only compared within one stream, where it mostly rises: a move sent late keeps its own time.
1160
+ */
1161
+ t?: number;
1147
1162
  }
1148
1163
  /**
1149
1164
  * One touch down.
@@ -1391,6 +1406,10 @@ export interface ViewportModeResult {
1391
1406
  ui: boolean;
1392
1407
  gamepadUnfocused: boolean;
1393
1408
  paused: boolean;
1409
+ /**
1410
+ * Whether the game's TS `Startup` systems have run in this world: false under `bevy-ts dev --edit` until the first play or step (1.18). Absent from older engines: treat the game as started.
1411
+ */
1412
+ started?: boolean;
1394
1413
  }
1395
1414
  /**
1396
1415
  * The editor camera's pose.
@@ -1900,6 +1919,7 @@ export interface LevelInfo {
1900
1919
  * The level's asset path.
1901
1920
  */
1902
1921
  path: string;
1922
+ opener: LevelOpener;
1903
1923
  /**
1904
1924
  * The root file's hash as last applied.
1905
1925
  */
@@ -1921,6 +1941,55 @@ export interface LevelInfo {
1921
1941
  export interface LevelListResult {
1922
1942
  levels: LevelInfo[];
1923
1943
  }
1944
+ /**
1945
+ * This interface was referenced by `ProtocolTypes`'s JSON-Schema
1946
+ * via the `definition` "LevelOpenParams".
1947
+ */
1948
+ export interface LevelOpenParams {
1949
+ /**
1950
+ * An asset path ending in .bsn.
1951
+ */
1952
+ file: string;
1953
+ }
1954
+ /**
1955
+ * This interface was referenced by `ProtocolTypes`'s JSON-Schema
1956
+ * via the `definition` "LevelOpenResult".
1957
+ */
1958
+ export interface LevelOpenResult {
1959
+ status: "opened" | "failed";
1960
+ /**
1961
+ * opened: the level's level_list entry.
1962
+ */
1963
+ level?: LevelInfo | null;
1964
+ /**
1965
+ * failed: invalid (not a .bsn path inside the asset root), not-found, or load (a file fails to parse or resolve).
1966
+ */
1967
+ reason?: string | null;
1968
+ /**
1969
+ * failed: each with its file, line and column where known.
1970
+ */
1971
+ diagnostics?: LevelDiagnostic[];
1972
+ }
1973
+ /**
1974
+ * This interface was referenced by `ProtocolTypes`'s JSON-Schema
1975
+ * via the `definition` "LevelCloseParams".
1976
+ */
1977
+ export interface LevelCloseParams {
1978
+ /**
1979
+ * An open level's asset path.
1980
+ */
1981
+ file: string;
1982
+ }
1983
+ /**
1984
+ * This interface was referenced by `ProtocolTypes`'s JSON-Schema
1985
+ * via the `definition` "LevelCloseResult".
1986
+ */
1987
+ export interface LevelCloseResult {
1988
+ /**
1989
+ * False when the level was not open.
1990
+ */
1991
+ closed: boolean;
1992
+ }
1924
1993
  /**
1925
1994
  * Give `entity`, or `level` and `namePath`.
1926
1995
  *
@@ -2097,7 +2166,7 @@ export interface LevelApplyResult {
2097
2166
  * via the `definition` "LevelWatchMessage".
2098
2167
  */
2099
2168
  export interface LevelWatchMessage {
2100
- event: "loaded" | "failed" | "written" | "external" | "rebased" | "conflict";
2169
+ event: "opened" | "closed" | "loaded" | "failed" | "written" | "external" | "rebased" | "conflict";
2101
2170
  /**
2102
2171
  * The file the event is about.
2103
2172
  */
@@ -2110,6 +2179,7 @@ export interface LevelWatchMessage {
2110
2179
  id?: number | null;
2111
2180
  reason?: string | null;
2112
2181
  diagnostics?: LevelDiagnostic[];
2182
+ opener?: LevelOpener1;
2113
2183
  }
2114
2184
  /**
2115
2185
  * This interface was referenced by `ProtocolTypes`'s JSON-Schema
@@ -2285,6 +2355,8 @@ export interface Methods {
2285
2355
  "bevy-ts/asset_preview_control": { params: AssetPreviewControlParams; result: AssetPreviewControlResult; crate: "bevy-ts-viewport"; watch: false };
2286
2356
  "bevy-ts/asset_preview_close": { params: AssetPreviewCloseParams; result: AssetPreviewCloseResult; crate: "bevy-ts-viewport"; watch: false };
2287
2357
  "bevy-ts/level_list": { params: undefined; result: LevelListResult; crate: "bevy-ts-levels"; watch: false };
2358
+ "bevy-ts/level_open": { params: LevelOpenParams; result: LevelOpenResult; crate: "bevy-ts-levels"; watch: false };
2359
+ "bevy-ts/level_close": { params: LevelCloseParams; result: LevelCloseResult; crate: "bevy-ts-levels"; watch: false };
2288
2360
  "bevy-ts/level_node": { params: LevelNodeParams; result: LevelNodeResult; crate: "bevy-ts-levels"; watch: false };
2289
2361
  "bevy-ts/level_catalog": { params: undefined; result: LevelCatalogResult; crate: "bevy-ts-levels"; watch: false };
2290
2362
  "bevy-ts/level_write": { params: LevelWriteParams; result: LevelWriteResult; crate: "bevy-ts-levels"; watch: false };