feat: complete M2 content workspace and inspector

This commit is contained in:
Rbanh committed 2026-07-17 23:40:49 -04:00
1 parent 931f561e7f
commit cf6eaba534
438 files changed
+59749 -19043

No files matched your search

+184
View File
@@ -0,0 +1,184 @@
#!/usr/bin/env bash
set -u
readonly REPO="/home/Rbanh/Documents/Bevy"
readonly TARGET_DIR="$REPO/target"
readonly EDITOR_BINARY="$TARGET_DIR/debug/editor"
readonly LAUNCHER_BINARY="$TARGET_DIR/debug/project_launcher"
readonly STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/blacksite-editor"
readonly LOG_FILE="$STATE_DIR/launch.log"
readonly STATUS_FILE="$STATE_DIR/splash.status"
readonly SPLASH="$REPO/scripts/editor/splash.py"
readonly CARGO_LANE="$REPO/scripts/codex/cargo_lane.py"
build_only=false
project_browser=false
gpu_validation=0
sdr_fallback=false
splash_pid=""
keep_splash=false
case "${1:-}" in
--build-only) build_only=true ;;
--launcher) project_browser=true ;;
--gpu-validation) gpu_validation=1 ;;
--sdr) sdr_fallback=true ;;
"") ;;
*)
printf 'Unknown option: %s\n' "$1" >&2
exit 2
;;
esac
if $project_browser; then
binary="$LAUNCHER_BINARY"
process_name="project_launcher"
service_description="Blacksite Project Browser"
else
binary="$EDITOR_BINARY"
process_name="editor"
service_description="Blacksite Editor"
fi
if ! $build_only && [[ "${BLACKSITE_EDITOR_SERVICE:-0}" != 1 ]]; then
service_environment=(--setenv=BLACKSITE_EDITOR_SERVICE=1 --setenv=PATH)
for variable in \
WAYLAND_DISPLAY DISPLAY XAUTHORITY XDG_RUNTIME_DIR \
HYPRLAND_INSTANCE_SIGNATURE DBUS_SESSION_BUS_ADDRESS \
XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE \
XDG_DATA_HOME XDG_CONFIG_HOME XDG_STATE_HOME GDK_BACKEND; do
if [[ -v "$variable" ]]; then
service_environment+=(--setenv="$variable")
fi
done
launcher_arguments=()
[[ $# -gt 0 ]] && launcher_arguments+=("$1")
exec systemd-run --user --collect --quiet --service-type=exec \
--description="$service_description" \
"${service_environment[@]}" \
"$0" "${launcher_arguments[@]}"
fi
write_status() {
local phase="$1"
local detail="$2"
local progress="$3"
local state="${4:-running}"
local crate_count="${5:-}"
printf '%s\n%s\n%s\n%s\n%s\n' \
"$phase" "$detail" "$progress" "$state" "$crate_count" >"$STATUS_FILE.tmp"
mv "$STATUS_FILE.tmp" "$STATUS_FILE"
}
close_splash() {
if [[ -n "$splash_pid" ]] && ! $keep_splash; then
write_status "Editor ready" "Opening workspace" 100 close
fi
}
trap close_splash EXIT
focus_existing() {
local pid executable
while read -r pid; do
[[ -n "$pid" ]] || continue
executable="$(readlink -f "/proc/$pid/exe" 2>/dev/null || true)"
if [[ "$executable" == "$binary" ]]; then
if command -v hyprctl >/dev/null 2>&1; then
hyprctl dispatch focuswindow "pid:$pid" >/dev/null 2>&1 || true
fi
return 0
fi
done < <(pgrep -x "$process_name" 2>/dev/null || true)
return 1
}
if ! $build_only && focus_existing; then
exit 0
fi
mkdir -p "$STATE_DIR"
exec 9>"$STATE_DIR/launch.lock"
if ! flock -n 9; then
exit 0
fi
: >"$LOG_FILE"
write_status "Preparing workspace" "Reading project configuration" 5
if ! $build_only; then
GSK_RENDERER=gl python3 "$SPLASH" "$STATUS_FILE" "$LOG_FILE" &
splash_pid=$!
fi
if ! cd "$REPO"; then
write_status "Project unavailable" "$REPO could not be opened" 100 error
keep_splash=true
exit 1
fi
if $build_only; then
exec python3 "$CARGO_LANE" exec dev -- cargo build -p editor --bin editor
fi
if [[ ! -x "$binary" ]]; then
write_status "Editor build unavailable" \
"Run blacksite-editor --build-only from a terminal" 100 error
keep_splash=true
exit 1
fi
export RUST_BACKTRACE=1
export WGPU_VALIDATION="$gpu_validation"
if $sdr_fallback; then
export BEVY_FPS_HDR=0
fi
export LD_LIBRARY_PATH="$TARGET_DIR/debug/deps${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
write_status "Starting editor" "Opening the current development build" 82
watch_editor_window() {
local editor_pid="$1"
trap - EXIT
if command -v hyprctl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
for ((attempt = 0; attempt < 300; attempt++)); do
if ! kill -0 "$editor_pid" 2>/dev/null; then
write_status "Editor stopped during startup" \
"Open the launch log for runtime details" 100 error
return
fi
if hyprctl clients -j 2>/dev/null | jq -e --argjson pid "$editor_pid" \
'any(.[]; .pid == $pid and .mapped == true)' >/dev/null; then
write_status "Editor ready" "Opening workspace" 100
sleep 0.4
write_status "Editor ready" "Opening workspace" 100 close
return
fi
if ((attempt == 10)); then
write_status "Initializing renderer" "Connecting to the graphics device" 88
elif ((attempt == 35)); then
write_status "Loading editor scene" "Preparing the workspace" 94
fi
sleep 0.1
done
else
write_status "Loading editor scene" "Preparing the workspace" 94
sleep 5
if kill -0 "$editor_pid" 2>/dev/null; then
write_status "Editor ready" "Opening workspace" 100
sleep 0.4
write_status "Editor ready" "Opening workspace" 100 close
return
fi
fi
write_status "Editor is taking longer than expected" \
"The process is still running; check the launch log" 100 error
}
watch_editor_window "$$" &
exec "$binary" >>"$LOG_FILE" 2>&1
write_status "Editor could not be started" \
"Open the launch log for runtime details" 100 error
keep_splash=true
exit 1
+200
View File
@@ -0,0 +1,200 @@
#!/usr/bin/env python3
"""Build the Blacksite editor while publishing exact crate progress."""
from __future__ import annotations
import argparse
import json
import os
from pathlib import Path
import subprocess
from typing import Iterable
def write_status(
path: Path,
phase: str,
detail: str,
progress: int,
state: str = "running",
crate_count: str = "",
) -> None:
temporary = path.with_suffix(path.suffix + ".tmp")
temporary.write_text(
f"{phase}\n{detail}\n{progress}\n{state}\n{crate_count}\n",
encoding="utf-8",
)
os.replace(temporary, path)
def unique_crates(tree_output: str) -> set[str]:
return {line.strip() for line in tree_output.splitlines() if line.strip()}
def completed_crate(
message: object, completed_package_ids: set[str]
) -> tuple[bool, str]:
if not isinstance(message, dict) or message.get("reason") != "compiler-artifact":
return False, ""
package_id = message.get("package_id")
if not isinstance(package_id, str) or package_id in completed_package_ids:
return False, ""
completed_package_ids.add(package_id)
target = message.get("target")
if isinstance(target, dict) and isinstance(target.get("name"), str):
return True, target["name"]
return True, package_id.rsplit("#", 1)[-1]
def cargo_tree(cargo: str) -> list[str]:
return [
cargo,
"tree",
"-p",
"editor",
"--features",
"dev",
"--edges",
"normal,build",
"--prefix",
"none",
"--format",
"{p}",
"--no-dedupe",
"--color",
"never",
]
def cargo_build(cargo: str) -> list[str]:
return [
cargo,
"build",
"-p",
"editor",
"--bins",
"--features",
"dev",
"--message-format=json-render-diagnostics",
"--color",
"never",
]
def rendered_lines(message: object, raw_line: str) -> Iterable[str]:
if not isinstance(message, dict):
yield raw_line
return
if message.get("reason") == "compiler-message":
diagnostic = message.get("message")
if isinstance(diagnostic, dict):
rendered = diagnostic.get("rendered")
if isinstance(rendered, str) and rendered:
yield rendered.rstrip("\n")
def run(status_path: Path, log_path: Path, cargo: str) -> int:
write_status(
status_path,
"Preparing build",
"Resolving editor crate graph",
8,
)
tree = subprocess.run(
cargo_tree(cargo),
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
crates = unique_crates(tree.stdout) if tree.returncode == 0 else set()
if not crates:
with log_path.open("a", encoding="utf-8") as log:
log.write(tree.stdout)
log.write(tree.stderr)
write_status(
status_path,
"Build graph failed",
"Open the launch log for Cargo details",
8,
"error",
)
return tree.returncode or 1
total = len(crates)
write_status(
status_path,
"Compiling project",
"Preparing editor crates",
12,
crate_count=f"0/{total}",
)
process = subprocess.Popen(
cargo_build(cargo),
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1,
)
assert process.stdout is not None
completed_package_ids: set[str] = set()
with log_path.open("a", encoding="utf-8") as log:
for raw_line in process.stdout:
stripped = raw_line.rstrip("\n")
try:
message: object = json.loads(stripped)
except json.JSONDecodeError:
message = stripped
for rendered in rendered_lines(message, stripped):
log.write(rendered + "\n")
log.flush()
changed, crate_name = completed_crate(message, completed_package_ids)
if not changed:
continue
completed = min(len(completed_package_ids), total)
progress = min(78, 12 + (66 * completed // total))
write_status(
status_path,
"Compiling project",
f"{crate_name} ready",
progress,
crate_count=f"{completed}/{total}",
)
return_code = process.wait()
completed = min(len(completed_package_ids), total)
if return_code != 0:
write_status(
status_path,
"Build failed",
"Open the launch log for compiler details",
max(12, min(78, 12 + (66 * completed // total))),
"error",
f"{completed}/{total}",
)
return return_code
write_status(
status_path,
"Build complete",
"Preparing engine process",
78,
crate_count=f"{total}/{total}",
)
return 0
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("status_path", type=Path)
parser.add_argument("log_path", type=Path)
parser.add_argument("--cargo", default="/usr/bin/cargo")
arguments = parser.parse_args()
return run(arguments.status_path, arguments.log_path, arguments.cargo)
if __name__ == "__main__":
raise SystemExit(main())
+217
View File
@@ -0,0 +1,217 @@
#!/usr/bin/env python3
import pathlib
import subprocess
import sys
import gi
gi.require_version("Gtk", "4.0")
gi.require_version("Gdk", "4.0")
from gi.repository import Gdk, GLib, Gtk # noqa: E402
CSS = """
window#blacksite-splash {
background: #111418;
color: #edf0f2;
border: 1px solid #4b535c;
}
.top-rule { background: #d7a83c; min-height: 4px; }
.eyebrow { color: #d7a83c; font-family: monospace; font-size: 11px; font-weight: 700; }
.brand { color: #f4f5f6; font-family: sans-serif; font-size: 48px; font-weight: 800; }
.edition { color: #9da6ae; font-family: monospace; font-size: 12px; }
.monogram { color: #313840; font-family: monospace; font-size: 88px; font-weight: 800; }
.build-chip {
background: #242a30; color: #c7cdd2; border: 1px solid #3e464e;
border-radius: 2px; font-family: monospace; font-size: 10px; padding: 5px 9px;
}
.footer { background: #1a1f24; border-top: 1px solid #353d45; }
.phase { color: #f0f2f4; font-size: 14px; font-weight: 700; }
.detail { color: #9da6ae; font-family: monospace; font-size: 11px; }
.crate-count {
color: #c7cdd2; font-family: monospace; font-size: 12px; font-weight: 700;
min-width: 74px;
}
.percentage { color: #d7a83c; font-family: monospace; font-size: 12px; font-weight: 700; }
progressbar trough { background: #30373e; border: 0; border-radius: 0; min-height: 5px; }
progressbar progress { background: #d7a83c; border: 0; border-radius: 0; min-height: 5px; }
progressbar.error progress { background: #d55b55; }
.error-text { color: #ef8b84; }
button {
background: #293038; color: #eef0f2; border: 1px solid #4a535c;
border-radius: 3px; padding: 6px 14px; font-weight: 600;
}
button:hover { background: #343d45; }
button.suggested-action { background: #b98b2f; color: #101317; border-color: #d7a83c; }
"""
class BlacksiteSplash(Gtk.Application):
def __init__(self, status_path: pathlib.Path, log_path: pathlib.Path) -> None:
super().__init__(application_id="com.fallingmetal.BlacksiteSplash")
self.status_path = status_path
self.log_path = log_path
self.last_status = None
def do_activate(self) -> None:
provider = Gtk.CssProvider()
provider.load_from_data(CSS.encode("utf-8"))
Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
self.window = Gtk.ApplicationWindow(application=self)
self.window.set_name("blacksite-splash")
self.window.set_title("Blacksite Editor")
self.window.set_decorated(False)
self.window.set_resizable(False)
self.window.set_default_size(760, 410)
root = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.window.set_child(root)
top_rule = Gtk.Box()
top_rule.add_css_class("top-rule")
root.append(top_rule)
content = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
content.set_margin_top(34)
content.set_margin_start(44)
content.set_margin_end(44)
content.set_vexpand(True)
root.append(content)
header = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
content.append(header)
brand_stack = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=7)
brand_stack.set_hexpand(True)
header.append(brand_stack)
eyebrow = Gtk.Label(label="FALLING METAL INTERACTIVE")
eyebrow.set_halign(Gtk.Align.START)
eyebrow.add_css_class("eyebrow")
brand_stack.append(eyebrow)
brand = Gtk.Label()
brand.set_markup("<span letter_spacing='4300'>BLACKSITE</span>")
brand.set_halign(Gtk.Align.START)
brand.add_css_class("brand")
brand_stack.append(brand)
edition = Gtk.Label(label="PROJECT EDITOR / DEVELOPMENT BUILD")
edition.set_halign(Gtk.Align.START)
edition.add_css_class("edition")
brand_stack.append(edition)
monogram = Gtk.Label(label="B/S")
monogram.set_halign(Gtk.Align.END)
monogram.add_css_class("monogram")
header.append(monogram)
spacer = Gtk.Box()
spacer.set_vexpand(True)
content.append(spacer)
chip = Gtk.Label(label="BEVY ENGINE / EDITOR RUNTIME")
chip.set_halign(Gtk.Align.START)
chip.add_css_class("build-chip")
content.append(chip)
footer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=9)
footer.set_margin_top(25)
footer.set_margin_bottom(26)
footer.set_margin_start(44)
footer.set_margin_end(44)
footer.add_css_class("footer")
root.append(footer)
status_row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
status_row.set_margin_top(20)
footer.append(status_row)
labels = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
labels.set_hexpand(True)
status_row.append(labels)
self.phase = Gtk.Label(label="Preparing workspace")
self.phase.set_halign(Gtk.Align.START)
self.phase.add_css_class("phase")
labels.append(self.phase)
self.detail = Gtk.Label(label="Reading project configuration")
self.detail.set_halign(Gtk.Align.START)
self.detail.set_ellipsize(3)
self.detail.add_css_class("detail")
labels.append(self.detail)
self.crate_count = Gtk.Label(label="")
self.crate_count.set_valign(Gtk.Align.CENTER)
self.crate_count.add_css_class("crate-count")
self.crate_count.set_visible(False)
status_row.append(self.crate_count)
self.percentage = Gtk.Label(label="05%")
self.percentage.set_valign(Gtk.Align.CENTER)
self.percentage.add_css_class("percentage")
status_row.append(self.percentage)
self.actions = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
self.actions.set_visible(False)
status_row.append(self.actions)
open_log = Gtk.Button(label="Open Log")
open_log.connect("clicked", self.open_log)
self.actions.append(open_log)
close = Gtk.Button(label="Close")
close.add_css_class("suggested-action")
close.connect("clicked", lambda _button: self.quit())
self.actions.append(close)
self.progress = Gtk.ProgressBar()
self.progress.set_fraction(0.05)
footer.append(self.progress)
GLib.timeout_add(100, self.poll_status)
self.window.present()
def open_log(self, _button: Gtk.Button) -> None:
if not self.log_path.exists():
return
try:
subprocess.Popen(
["xdg-open", str(self.log_path)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
except OSError:
pass
def poll_status(self) -> bool:
try:
raw_status = self.status_path.read_text(encoding="utf-8")
except OSError:
return GLib.SOURCE_CONTINUE
if raw_status == self.last_status:
return GLib.SOURCE_CONTINUE
self.last_status = raw_status
lines = raw_status.splitlines()
if len(lines) < 4:
return GLib.SOURCE_CONTINUE
phase, detail, progress_text, state = lines[:4]
crate_count = lines[4] if len(lines) >= 5 else ""
try:
progress = max(0, min(100, int(progress_text)))
except ValueError:
progress = 0
if state == "close":
self.quit()
return GLib.SOURCE_REMOVE
self.phase.set_label(phase)
self.detail.set_label(detail)
self.progress.set_fraction(progress / 100.0)
self.percentage.set_label(f"{progress:02d}%")
self.crate_count.set_label(f"({crate_count})" if crate_count else "")
self.crate_count.set_visible(bool(crate_count))
if state == "error":
self.phase.add_css_class("error-text")
self.progress.add_css_class("error")
self.percentage.set_visible(False)
self.actions.set_visible(True)
return GLib.SOURCE_CONTINUE
def main() -> int:
if len(sys.argv) != 3:
print("usage: splash.py STATUS_FILE LOG_FILE", file=sys.stderr)
return 2
app = BlacksiteSplash(pathlib.Path(sys.argv[1]), pathlib.Path(sys.argv[2]))
return app.run([sys.argv[0]])
if __name__ == "__main__":
raise SystemExit(main())
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
import importlib.util
from pathlib import Path
import unittest
MODULE_PATH = Path(__file__).with_name("build_progress.py")
SPEC = importlib.util.spec_from_file_location("build_progress", MODULE_PATH)
assert SPEC is not None and SPEC.loader is not None
BUILD_PROGRESS = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(BUILD_PROGRESS)
class BuildProgressTests(unittest.TestCase):
def test_unique_crates_deduplicates_repeated_tree_entries(self) -> None:
output = "editor v0.1.0\nserde v1.0.0\nserde v1.0.0\n"
self.assertEqual(
BUILD_PROGRESS.unique_crates(output),
{"editor v0.1.0", "serde v1.0.0"},
)
def test_completed_crate_counts_each_package_once(self) -> None:
completed: set[str] = set()
message = {
"reason": "compiler-artifact",
"package_id": "path+file:///workspace#editor@0.1.0",
"target": {"name": "editor"},
}
self.assertEqual(
BUILD_PROGRESS.completed_crate(message, completed), (True, "editor")
)
self.assertEqual(
BUILD_PROGRESS.completed_crate(message, completed), (False, "")
)
def test_non_artifact_does_not_advance_progress(self) -> None:
completed: set[str] = set()
self.assertEqual(
BUILD_PROGRESS.completed_crate({"reason": "build-script-executed"}, completed),
(False, ""),
)
self.assertFalse(completed)
if __name__ == "__main__":
unittest.main()