Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ members = [
"runtime/export",
"runtime/live",
"runtime/page",
"runtime/appscreen",
"runtime/sound",
"runtime/look",
"runtime/scene",
Expand Down
11 changes: 1 addition & 10 deletions apps/game/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ pub fn export(args: &[String]) -> R<String> {
gather(&mut bundle, &dir, &game, &mut got)?;
std::fs::write(&js, &bundle).map_err(|e| e.to_string())?;

// an app screen needs a player with the surface runtime (the `surfaces` feature), which the size-built one leaves out
if got.files.iter().any(|(rel, _)| rel.ends_with(raea_runtime_page::screen::BUNDLED)) && !player_has_surfaces(&player)? {
return Err(format!("this game has an app screen (<Screen app>), and the player {} can't run one: build it with them (cargo build --profile game -p raea-app-game --bin raea-game --features player,surfaces) and export again", player.display()));
}
// an app screen (<Screen app>) draws on the player's own Blitz page (raea-runtime-appscreen): every player has one

// 3. what play works out at open, worked out now from the package itself (so the package is known to load)
let src = std::fs::read_to_string(&tsx).unwrap_or_default();
Expand Down Expand Up @@ -255,12 +252,6 @@ pub(crate) fn imported(dir: &Path, file: &Path) -> bool {
false
}

/// Whether the player at `bin` was built with the surface runtime (app screens): its shim's text is in it.
pub(crate) fn player_has_surfaces(bin: &Path) -> R<bool> {
let bytes = std::fs::read(bin).map_err(|e| format!("{}: {e}", bin.display()))?;
Ok(bytes.windows(14).any(|w| w == b"__surfaceFrame"))
}

pub(crate) fn default_name(tsx: &Path) -> String {
let stem = tsx.file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_default();
let base = if stem == "edit" { tsx.parent().and_then(|p| p.file_name()).map(|s| s.to_string_lossy().to_string()).unwrap_or(stem) } else { stem };
Expand Down
18 changes: 13 additions & 5 deletions apps/game/src/gather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,21 @@ pub(crate) fn gather(bundle: &mut String, dir: &Path, game: &Path, got: &mut Gat
let ext = file.extension().and_then(|x| x.to_str()).unwrap_or("").to_ascii_lowercase();
if SOURCE_EXTS.contains(&ext.as_str()) || file.file_name().is_some_and(|n| n == MANIFEST) {
// an app screen's module (`<Screen app="chat.tsx">`, a component on react-dom): bundled now with its npm
// packages beside where it was, as `chat.tsx.surface.js`, which the player opens (it bundles nothing)
// packages beside where it was, as `chat.tsx.surface.js` and its CSS `chat.tsx.surface.css`, which the
// player opens (it bundles nothing; raea-runtime-appscreen code_of)
if matches!(ext.as_str(), "tsx" | "jsx") && std::fs::read_to_string(&file).is_ok_and(|t| t.contains("export default") && !t.contains("registerRoot(")) && !imported(dir, &file) {
if let Some(rel) = inside(&file) {
let rel = format!("{rel}{}", raea_runtime_page::screen::BUNDLED);
if !got.has(&rel) {
raea_runtime_react::scene::bundle_surface(&file, &game.join(&rel))?;
got.files.push((rel, file.clone()));
let (js_rel, css_rel) = (format!("{rel}{}", raea_runtime_page::screen::BUNDLED), format!("{rel}{}", raea_runtime_page::screen::BUNDLED_CSS));
if !got.has(&js_rel) {
let (js, css) = raea_runtime_page::screen::build_app(&file)?;
for (r, text) in [(&js_rel, js), (&css_rel, css)] {
let out = game.join(r);
if let Some(d) = out.parent() {
std::fs::create_dir_all(d).map_err(|e| format!("{}: {e}", d.display()))?;
}
std::fs::write(&out, text).map_err(|e| format!("{}: {e}", out.display()))?;
got.files.push((r.clone(), file.clone()));
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions apps/play/src/offscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ pub(crate) fn offscreen(mut run: Run, json: Option<String>, flat_out: bool, snap
if let Some((x, y, down)) = run.pointer {
e["pointer"] = serde_json::json!({"x": x, "y": y, "down": down});
}
// what reached its app screens (the keys they took aren't the page's above), given them again in a render
if let Some(apps) = live.app_input() {
e["apps"] = apps;
}
// the session's seed and start with its first frame: a render of the log draws the same Math.random and Date
if logged.is_empty() {
e["session"] = live.session();
Expand Down
2 changes: 1 addition & 1 deletion apps/targets/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn host(args: &[String]) -> Result<String, String> {
let p = Path::new(a);
if p.extension().is_some_and(|x| x == "tsx" || x == "ts" || x == "jsx") && p.is_file() {
std::fs::create_dir_all(&work).map_err(|e| format!("{}: {e}", work.display()))?;
let (js, css) = raea_runtime_bundle::inproc::app::bundle(p, &raea_io_home::home())?;
let (js, css) = raea_runtime_bundle::inproc::app::bundle(p, &raea_io_home::home(), raea_runtime_bundle::inproc::app::WINDOW)?;
let script = work.join(format!("{}.js", p.file_stem().unwrap_or_default().to_string_lossy()));
std::fs::write(&script, js).map_err(|e| format!("{}: {e}", script.display()))?;
handed.push(script.display().to_string());
Expand Down
2 changes: 1 addition & 1 deletion apps/targets/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Built {
pub fn build(app: &Path, dir: &Path) -> Result<Built, String> {
let app = raea_io_home::plain(app.canonicalize().map_err(|e| format!("{}: {e}", app.display()))?);
std::fs::create_dir_all(dir).map_err(|e| format!("{}: {e}", dir.display()))?;
let (js, imported) = raea_runtime_bundle::inproc::app::bundle(&app, &raea_io_home::home())?;
let (js, imported) = raea_runtime_bundle::inproc::app::bundle(&app, &raea_io_home::home(), raea_runtime_bundle::inproc::app::WINDOW)?;
let folder = app.parent().unwrap_or(Path::new("."));
let tw = raea_runtime_bundle::styles::tailwind(folder)?;
let built = Built { js: dir.join("app.js"), css: dir.join("app.css") };
Expand Down
7 changes: 7 additions & 0 deletions bench/render-play/appscreen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"0": ["Pointer:480:60"],
"6": ["Pointer:480:260"],
"10": ["Pointer:480:260:down"],
"12": ["Pointer:480:260"],
"21": ["Pointer:480:60"]
}
4 changes: 3 additions & 1 deletion bench/render-play/rows.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# React on the page with 3D in the world, picking and input replay are all here: the games (pong and platformer on
# the page, arena3d's 3D drawn live), bevy-ts' live cases (keys, the pointer, a gamepad, the window and the World's
# components through useQuery), the bridge's Engine reads (engine3d: a cube the World moves, React's marker reading it)
# and pick3d (on* on 3D parts: hover, press, leave); an <R3F>'s own pointer events and <OrbitControls> (r3f live/pointer)
# and pick3d (on* on 3D parts: hover, press, leave); an <R3F>'s own pointer events and <OrbitControls> (r3f live/pointer);
# an app screen's button clicked through the 3D, its own timer on the frame's clock (appscreen: blitz-bevy H12)
sdk/react/bench/games/pong/edit.tsx keys:ArrowUp,ArrowDown,,ArrowUp 0.25 0.75 1.25 1.75
sdk/react/bench/games/platformer/edit.tsx keys:ArrowRight,ArrowRight+ArrowUp,ArrowRight, 0.25 0.75 1.25 1.75
sdk/react/bench/games/arena3d/edit.tsx keys:ArrowRight,ArrowUp,ArrowLeft+ArrowUp,ArrowDown, 0.25 0.75 1.25 1.75
Expand All @@ -22,3 +23,4 @@ sdk/raea/bench/bevy-ts/cases/text3d-readback.tsx script:sdk/raea/bench/bevy-ts/c
bench/bridge/engine3d.tsx - 0.3 0.9 1.25
sdk/raea/bench/bevy/pick3d/edit.tsx script:bench/render-play/pick3d.json 0.1 0.2 0.3 0.4 0.6 0.9
sdk/r3f/test/live/pointer.tsx script:sdk/r3f/test/live/pointer.json 0.2 0.4 0.6 0.9
sdk/raea/bench/bevy/appscreen/edit.tsx script:bench/render-play/appscreen.json 0.2 0.4 0.6 0.9
2 changes: 1 addition & 1 deletion docs/manual/reference/sdk/3d.md
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,7 @@ The props of [`Screen`](#screen), tabled there.
| `background` | `string` | behind the picture ("#000000"). A see-through one ("#ffffff00", "transparent", rgba(..., 0.5)) makes the screen see-through where its page paints nothing, so what's behind it in the scene shows (a flat screen: a layer of a page pulled apart in 3D); an opaque one keeps the screen opaque, which writes depth for DepthOfField |
| `brightness` | `number` | a flat screen's (`crt={false}`) light: 1, the default, draws its page at the page's own colours, unlit (scene lights don't touch it); above 1 it glows, and blooms under a <Bloom>. A tone curve on the camera bends it like the rest of the frame: give the scene <ToneMapping mode="none" /> to keep the page's colours exact. A CRT's is `crt.brightness` |
| `src` | `string` | a video to show instead of children: staticFile("clip.mp4"), filling the picture |
| `app` | `string` | an app to show instead of children: a module's path from the composition's folder ("chat.tsx"), its default export a React component given {width, height}. It runs on real react-dom in a document of its own, so npm's React libraries work on it (assistant-ui, Radix; installed with `raea add`). In play the pointer reaches it through the 3D, where it lands on the picture, and a press on it gives it the keys (the game doesn't get them) until a press elsewhere or Escape; in a render it runs on the frame's clock, so the render repeats |
| `app` | `string` | an app to show instead of children: a module's path from the composition's folder ("chat.tsx"), its default export a React component given {width, height}. It runs on react-dom (@raea/ui's) in a Blitz document of its own, so npm's React libraries work on it (assistant-ui, Radix; installed with `raea add`). In play the pointer reaches it through the 3D, where it lands on the picture, and a press on it gives it the keys (the game doesn't get them) until a press elsewhere or Escape; in a render it runs on the frame's clock, so the render repeats |
| `children` | `ReactNode` | the nested composition or game |

### `Section`
Expand Down
2 changes: 1 addition & 1 deletion engine/rune/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn home() -> PathBuf {

/// `file`'s script
pub fn script(file: &Path) -> String {
raea_runtime_bundle_lib::app::bundle(file, &home()).unwrap().0
raea_runtime_bundle_lib::app::bundle(file, &home(), raea_runtime_bundle_lib::app::WINDOW).unwrap().0
}

/// tests/apps/`name`
Expand Down
21 changes: 21 additions & 0 deletions runtime/appscreen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "raea-runtime-appscreen"
version = "0.1.0"
edition = "2024"
license = "FSL-1.1-ALv2"
publish = false
description = "App screens (<Screen app>): a module on @raea/ui's react-dom in a Blitz document of its own at the screen's size, stepped once a frame on the frame's clock with the input routed to it"

[dependencies]
bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "bevy_render", "bevy_window"] }
blitz-traits = "=0.3.0-beta.4"
keyboard-types = "0.8"
serde_json = "1"
raea-page = { path = "../../engine/page" }
raea-runtime-dom = { path = "../dom" }
raea-runtime-js = { path = "../js" }
raea-runtime-jsengine = { path = "../jsengine" }
raea-runtime-bundle = { path = "../bundle" }
raea-sys-page = { path = "../../systems/page" }
raea-sys-fonts = { path = "../../systems/fonts" }
raea-io-home = { path = "../../io/home" }
Loading
Loading