khora_data/ecs/components/prefab.rs
1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8
9use khora_macros::Component;
10use serde::{Deserialize, Serialize};
11
12/// Marks an entity as having been instantiated from a `.kprefab` asset
13/// in the project's VFS. The `source` field stores the forward-slash
14/// relative path under `<project>/assets/` so the editor can offer
15/// "open prefab", "revert overrides" and "spawn another" actions.
16///
17/// Phase 5 entry — full instance overrides + nested prefab linking is
18/// scheduled for a follow-up. Today the component is purely informative:
19/// the recipe stored in the .kprefab file is what actually shapes the
20/// instantiated subtree.
21#[derive(Debug, Clone, PartialEq, Eq, Component, Default, Serialize, Deserialize)]
22#[component(provenance = ToolAuthored)]
23pub struct Prefab {
24 /// Forward-slash relative path of the source `.kprefab` asset.
25 /// Example: `prefabs/crate.kprefab`.
26 pub source: String,
27}
28
29impl Prefab {
30 /// Creates a new `Prefab` from a relative source path.
31 pub fn new(source: impl Into<String>) -> Self {
32 Self {
33 source: source.into(),
34 }
35 }
36}