Skip to content

feat: redesign Python API with direct handles, Vec2 math, attribute input, and proxy caching - #19

Merged
mkh-user merged 1 commit into
mainfrom
feat/api-redesign
Nov 2, 2026
Merged

mkh-user merged 1 commit into
mainfrom
feat/api-redesign

Conversation

@mkh-user

@mkh-user mkh-user commented Nov 2, 2026

Copy link
Copy Markdown
Member

Overview

This PR redesigns Pite's Python scripting API and engine runtime integration based on our architectural proposal and expert review:

  1. Vec2 PyClass & Direct Struct-Backed Transform Handles:

    • Vec2 supports vector arithmetic (+, -, *, /), in-place mutation (+=, -=, *=, /=), indexing [0], [1], unpacking x, y = self.position, tuple assignment self.position = (x, y), and .length() / .normalized().
    • Node transform getters and setters directly target ScriptHost (self.position.x += 10.0 writes straight to engine tree state).
    • Removed the redundant end-of-frame getattr / mutex lock / string allocation sync pass in GameSession::update.
  2. Attribute-Based Input API with Deprecation Cut:

    • pite.held.<key>, pite.pressed.<key>, and pite.released.<key> (e.g. pite.held.right, pite.pressed.space).
    • Hard cut throws TypeError when invoking with strings (e.g., pite.held("Space")).
  3. Declarative Descriptors:

    • pite.child("Name") (PyChildDescriptor) and pite.node("../Path") (PyNodeDescriptor).
    • Caches resolved NodeProxy instances in _descriptor_cache on first access to avoid repeated lookups.
  4. NodeProxy Caching & Hybrid Signals:

    • ScriptHost::proxy_cache caches resolved NodeProxy objects by (caller, path).
    • BoundSignal supports arbitrary Python callables (lambdas, functions, bound methods), while built-in engine signals (Button.pressed, Timer.timeout, Area2D entry/exit) remain engine-dispatched.
  5. Enhanced Error Handling & Pause-On-Error:

    • GameSession::pause_on_error captures formatted stack traces and script locations.
    • Editor automatically pauses gameplay (self.playing = false), logs formatted tracebacks, and opens the offending script.

Verification

  • cargo fmt --all -- --check passed.
  • cargo build --workspace --locked passed.
  • cargo test --workspace --locked passed (all crates including pite-runtime, pite-script, pite-core, pite-editor).
  • cargo run --locked -p pite-cli -- check passed.

@mkh-user mkh-user self-assigned this Nov 2, 2026
@mkh-user
mkh-user merged commit 397202d into main Nov 2, 2026
6 checks passed
@mkh-user
mkh-user deleted the feat/api-redesign branch November 2, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant