HammeritePrefab
Core: the map. Inherits Resource
A prefab containing brushes and entities.
Prefabs are reusable templates that can be instantiated in maps. Each instance tracks its source prefab via prefab_id.
Properties
| Type | Name | Default |
|---|---|---|
AABB | aabb | AABB(0, 0, 0, 0, 0, 0) |
HammeriteBrush[] | brushes | [] |
String | category | "" |
HammeriteEntity[] | entities | [] |
int | prefab_id | 0 |
String | prefab_name | "Untitled Prefab" |
Texture2D | preview_texture | |
String[] | tags | [] |
Methods
| Returns | Method |
|---|---|
HammeritePrefabPlacement | build_instance(map: HammeriteMap, at: Transform3D, layer_id: int = 0) |
Variant | generate_thumbnail(generator: Object) |
bool | has_thumbnail() |
HammeritePrefabInstance | instantiate(map: HammeriteMap, at: Transform3D, layer_id: int = 0) |
bool | is_valid() |
void | update_from_instance(instance: HammeritePrefabInstance, map: HammeriteMap) |
Signals
prefab_updated
signal prefab_updated()
Emitted by update_from_instance() once the prefab's content has been replaced.
thumbnail_generated
signal thumbnail_generated(has_thumbnail: bool)
Emitted once a generator that was still drawing when generate_thumbnail() was called has drawn, with whether preview_texture is set: what awaiting generate_thumbnail() answers.
Property descriptions
aabb
var aabb: AABB = AABB(0, 0, 0, 0, 0, 0)
Axis-aligned bounds of the prefab content in prefab-local space. Recomputed by update_from_instance(); otherwise whatever it was saved with.
brushes
var brushes: HammeriteBrush[] = []
Brushes contained in this prefab, in prefab-local space (relative to the instance transform).
category
var category: String = ""
Category for organization in the browser.
entities
var entities: HammeriteEntity[] = []
Entities contained in this prefab, their origins in prefab-local space.
prefab_id
var prefab_id: int = 0
Unique identifier for this prefab across prefab sets, nonzero once assigned (the editor draws it from ResourceUID.create_id()). Brushes and entities placed from it carry it as their prefab_id.
prefab_name
var prefab_name: String = "Untitled Prefab"
Display name of the prefab. Must be non-empty for is_valid().
preview_texture
var preview_texture: Texture2D
Preview texture for the prefab browser, set by generate_thumbnail(). Saved with the prefab.
tags
var tags: String[] = []
Words to find the prefab by: the author's, for a browser or a game to filter on. Nothing in Hammerite reads them.
Method descriptions
build_instance()
func build_instance(map: HammeriteMap, at: Transform3D, layer_id: int = 0) -> HammeritePrefabPlacement
instantiate() without adding anything to map: for a caller that adds the placement itself, as the editor does inside one undoable action. Ids are drawn from map all the same.
generate_thumbnail()
func generate_thumbnail(generator: Object) -> Variant
Generate or regenerate the preview thumbnail for this prefab, with generator - a HammeriteThumbnailGenerator, or anything else with its generate_thumbnail(prefab). Await what it answers: await prefab.generate_thumbnail(generator) is true if preview_texture was set, and false when generator is null. A generator that answers at once is answered at once; one that is a coroutine still drawing is answered with thumbnail_generated, which is emitted with the same answer once it has drawn - a native method cannot be a coroutine itself.
has_thumbnail()
func has_thumbnail() -> bool
Whether preview_texture is set.
instantiate()
func instantiate(map: HammeriteMap, at: Transform3D, layer_id: int = 0) -> HammeritePrefabInstance
Place this prefab in map at at, on layer layer_id: its brushes and entities copied with ids of map's own, carried into map space and added, with the instance that owns them. Null for a prefab that is not is_valid(). What a game calls to put one down at runtime; build_instance() is the same without adding anything.
is_valid()
func is_valid() -> bool
Whether the prefab can be placed: a nonzero prefab_id, a non-empty prefab_name and at least one brush or entity.
update_from_instance()
func update_from_instance(instance: HammeritePrefabInstance, map: HammeriteMap) -> void
Update the prefab content from a live instance. Copies all brushes and entities from the instance, transforming them to be relative to the prefab origin. instance must be of this prefab (same prefab_id), or nothing changes and an error is printed. Emits prefab_updated. Entities are carried into prefab space with HammeriteEntity.transform_by(): origin and turn.