Nightshade Editor API
API for creating plugins for the Nightshade Editor.
Note: Plugins are only supported on native builds (Windows, macOS, Linux).
Quick Start
[package]
name = "my-plugin"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
[dependencies]
nightshade-editor-api = { version = "0.6", default-features = false, features = ["guest"] }
use nightshade_editor_api::{
drain_events, drain_inspector_requests, log, register_inspector,
respond_inspector_ui, send_mod_info, EditorEvent, InspectorRequest,
ModInfo, UiElement,
};
#[unsafe(no_mangle)]
pub extern "C" fn on_init() {
send_mod_info(&ModInfo {
id: "my-plugin".to_string(),
name: "My Plugin".to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
});
log("[My Plugin] Initialized");
register_inspector("My Data", "my_data");
}
#[unsafe(no_mangle)]
pub extern "C" fn on_frame() {
for event in drain_events() {
match event {
EditorEvent::EntitySelected { entity_id } => {
log(&format!("Entity {} selected", entity_id));
}
_ => {}
}
}
for request in drain_inspector_requests() {
if let InspectorRequest::RenderUi { inspector_id, entity_id } = request {
if inspector_id == "my_data" {
respond_inspector_ui(vec![
UiElement::Label { text: format!("Entity: {}", entity_id) },
UiElement::Button { text: "Click Me".to_string(), id: "btn".to_string() },
]);
}
}
}
}
Building
rustup target add wasm32-wasip1
cargo build --target wasm32-wasip1 --release
cp target/wasm32-wasip1/release/my_plugin.wasm /path/to/editor/plugins/
Features
guest - For plugins (WASM). Provides the plugin API functions.
host - For the editor. Re-exports egui types.
API
Lifecycle
| Function |
Description |
on_init() |
Called once when plugin loads |
on_frame() |
Called every frame |
Commands
| Function |
Description |
send_mod_info(&ModInfo) |
Register plugin name and version |
log(&str) |
Print to editor console |
register_inspector(name, id) |
Add custom inspector panel |
register_menu_item(path, id) |
Add menu item (e.g. "Tools/My Plugin") |
Events
| Function |
Description |
drain_events() |
Get pending EditorEvents |
drain_inspector_requests() |
Get pending InspectorRequests |
drain_ui_responses() |
Get pending UiResponses (button clicks, etc.) |
UI Response
| Function |
Description |
respond_inspector_ui(Vec<UiElement>) |
Send UI for inspector panel |
respond_menu_ui(Vec<UiElement>) |
Send UI for menu |
UiElement Types
Label { text } - Text label
Button { text, id } - Clickable button
TextEdit { value, id } - Text input field
Separator - Horizontal line
Spacing { amount } - Vertical space
Horizontal { children } - Horizontal layout
Vertical { children } - Vertical layout
Group { children } - Grouped elements
Collapsing { header, default_open, children } - Collapsible section
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.