Bundler
Overview
The Bundler component manages the state and logic for an entity that is in the process of wrapping items into a bundle (e.g., using wrapping paper). It facilitates the creation of a temporary container, handles the transfer of items into it, and ultimately spawns the final wrapped product. This component works in tandem with the entity's stategraph (sg) to transition through various bundling states like bundle, bundling, and bundle_pst.
Dependencies & Tags
This component relies on the presence of other components on various entities:
inventory(on self): Used to give items back to the entity if bundling is canceled or finished.bundlemaker(on the item used to start bundling): Provides the prefabs for the temporary container and the final wrapped item.container(on the temporary bundling instance): Manages the items being placed into the bundle.unwrappable(on the final wrapped item): Used to store the contents of the bundle.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
bundlinginst | Entity | nil | The temporary container entity spawned to hold items during the bundling process. |
itemprefab | string | nil | The prefab name of the item used to initiate bundling (e.g., "wrappingpaper"). |
wrappedprefab | string | nil | The prefab name of the final bundled item that will be created. |
itemskinname | string | nil | The skin name of the item used to initiate bundling. |
wrappedskinname | string | nil | The skin name to be applied to the final bundled item. |
wrappedskin_id | string | nil | The skin ID to be applied to the final bundled item. |
Main Functions
CanStartBundling()
- Description: Checks if the entity is in a state where it can begin the bundling process. This requires the entity to be in the "bundle" state and not already in the middle of bundling something.
- Parameters: None.
IsBundling(bundlinginst)
- Description: Determines if the entity is currently in the "bundling" state with a specific temporary container instance.
- Parameters:
bundlinginst(Entity): The temporary container entity to check against.
StartBundling(item)
- Description: Initiates the bundling process using a specified item (e.g., wrapping paper). It spawns a temporary container, sets internal properties based on the
bundlemakercomponent of the item, and transitions the entity's stategraph to the "bundling" state. - Parameters:
item(Entity): The item entity being used to start the bundling, which must have abundlemakercomponent.
StopBundling()
- Description: Aborts the current bundling process. It removes the temporary container, returns all items from it to the entity's inventory (or drops them), and gives back the original item used to start the process. This function is also used for cleanup when the component is removed.
- Parameters: None.
FinishBundling()
- Description: Transitions the entity from the active "bundling" state to the final "bundle_pst" (post) state, preparing for the creation of the final wrapped item. This can only be called if the temporary container is not empty.
- Parameters: None.
OnFinishBundling()
- Description: Called at the end of the bundling animation/state. It creates the final wrapped item, transfers the contents from the temporary container into the new item's
unwrappablecomponent, cleans up the temporary container, and gives the final wrapped item to the entity. - Parameters: None.
OnSave()
- Description: Serializes the component's state for game saving. It saves the prefabs, skins, and the contents of the temporary container.
- Parameters: None.
OnLoad(data)
- Description: Deserializes the component's state from save data, restoring any in-progress bundling.
- Parameters:
data(table): The saved data table generated byOnSave.