Skip to content

Add graphic! and font! via ply-macros to make embedding default #74

Description

@TheRedDeveloper

Summary

Introduce graphic! and font! procedural macros via a new ply-macros sub-crate to make asset embedding the ergonomic default.

Motivation

Users frequently report runtime issues because their assets are missing from the execution path. Embedding assets directly into the binary is much safer, but currently requires verbose boilerplate and brittle, module-relative paths (e.g., ../assets/...). Moving string-splitting and path-resolution logic into a compile-time procedural macro allows us to enforce embedding seamlessly without ruining ergonomics.

Proposed API

static LOGO: GraphicAsset = graphic!("assets/images/logo.png");
static FONT: FontAsset = font!("assets/fonts/lexend.ttf");

Currently, developers have to do this:

static LOGO: GraphicAsset = GraphicAsset::Bytes {
    file_name: "logo.png",
    data: include_bytes!("../assets/images/logo.png"),
};

Behavior

  • Introduce a new ply-macros procedural macro crate inside the root directory.
  • Re-export the graphic! and font! macros cleanly inside ply_engine::prelude.
  • Parse the input string literal at compile time to automatically extract the file name.
  • Resolve asset paths relative to the workspace root using CARGO_MANIFEST_DIR so that macros function reliably regardless of which deeply nested source module invokes them.
  • Verify file existence inside the macro and emit a clear compile-time error if an asset path is missing.
  • GraphicAsset::Path and FontAsset::Path should be marked as #[deprecated]

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedA feature that has been approvedfeatNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions