Drawingtool
Overview
The DrawingTool component provides functionality for an entity to "draw" or display the image of another item (the "source") onto a target entity. It handles the logic for finding a suitable source item, extracting its visual information (image, atlas, background image), and then instructing the target entity's drawable component to display this information. This component is typically used for items like signs or frames that display other items.
Dependencies & Tags
This component relies on other components being present on the target or source entities:
- Target Entity: Requires the
drawablecomponent to actually display the image. - Source Entity:
- Requires the
inventoryitemcomponent to retrieveimagenameandatlasname. - May have
drawimageoverrideanddrawatlasoverridefunctions/values to customize its displayed image. - May have
inv_image_bgtable for background image details.
- Requires the
The global helper function FindEntityToDraw which is used by this component, filters entities based on the following tags:
- Must include:
_inventoryitem - Cannot include:
INLIMBO,notdrawable
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
self.inst | Entity | inst | The entity instance this component is attached to. |
ondrawfn | function | nil | An optional callback function to be invoked when drawing occurs. |
Main Functions
SetOnDrawFn(fn)
- Description: Sets a callback function that will be executed after the drawing operation is completed by the target entity.
- Parameters:
fn: (function) The function to call, which will receive(tool_inst, target, image, src, atlas, bgimage, bgatlas)as arguments.
GetImageToDraw(target, doer)
- Description: Identifies a suitable entity to draw based on a given target and retrieves its visual assets (image, atlas, background image). This function leverages the global
FindEntityToDrawto find a source entity. - Parameters:
target: (Entity) The primary target entity, often the one being interacted with.doer: (Entity) The entity performing the action (e.g., the player).
- Returns:
image,src_entity,atlas,bgimage,bgatlas.image: (string) The name of the image to draw (e.g., "inventory/imagename.tex").src_entity: (Entity) The actual entity from which the image data was sourced.atlas: (string) The atlas path forimage.bgimage: (string) The name of a background image to draw (if any).bgatlas: (string) The atlas path forbgimage.
Draw(target, image, src, atlas, bgimage, bgatlas)
- Description: Instructs the
drawablecomponent of thetargetentity to display the provided image information. If anondrawfnis set, it is invoked after thedrawablecomponent handles the drawing. - Parameters:
target: (Entity) The entity whosedrawablecomponent will perform the drawing.image: (string) The image filename (e.g., "item.tex").src: (Entity) The source entity from which the image was obtained.atlas: (string, optional) The atlas path for the image.bgimage: (string, optional) The background image filename.bgatlas: (string, optional) The atlas path for the background image.