Giftreceiver
Overview
The GiftReceiver component tracks the number of gifts available for a player and manages communication with a GiftMachine component when the player opens or clears gifts. It ensures that the player’s classified UI state (e.g., "has gifts") and the gift machine's internal list of eligible receivers are kept in sync.
Dependencies & Tags
- Components used: Relies on
inst.player_classified(assumed to havehasgiftandhasgiftmachineproperties) andTheInventory:GetClientGiftCount(). - Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
giftcount | number | 0 | Current number of gifts available to the player (synchronized via TheInventory). Triggers UI updates when changed. |
giftmachine | `Entity | nil` | nil |
Main Functions
RefreshGiftCount()
- Description: Fetches the current gift count from
TheInventoryand updates the local state. If the count changes and a gift machine is assigned, notifies the machine by pushingms_addgiftreceiverorms_removegiftreceiverevents. - Parameters: None.
SetGiftMachine(inst)
- Description: Assigns a new
GiftMachineentity as the receiver’s associated machine. Updates both the old and new machines (if applicable) by pushingms_removegiftreceiverorms_addgiftreceiverevents to manage the machine’s internal list of eligible receivers. - Parameters:
inst: The newGiftMachineentity to associate, ornilto clear the association.
OpenNextGift()
- Description: Initiates the gift-opening process if the player has gifts and a valid gift machine is assigned. Pushes the
ms_opengiftevent to signal intent. - Parameters: None.
OnStartOpenGift()
- Description: Notifies the assigned gift machine that a gift is beginning to be opened by pushing the
ms_giftopenedevent. - Parameters: None.
OnStopOpenGift(usewardrobe)
- Description: Signals completion of the gift-opening interaction. Pushes
ms_doneopengiftwith optionalwardrobedata ifusewardrobeis true. - Parameters:
usewardrobe:booleanindicating whether the wardrobe window should be opened after opening the gift.
HasGift()
- Description: Returns whether the player currently has any gifts available.
- Parameters: None.
- Returns:
boolean—trueifgiftcount > 0, otherwisefalse.
Events & Listeners
- Listens for
ms_closepopup→ Triggersonclosepopuphandler, which callsOnStopOpenGiftif the closed popup isPOPUPS.GIFTITEM. - Listens for
ms_updategiftitems(viaOnInitcallback) → CallsOnUpdateGiftItems, which in turn callsRefreshGiftCount. - Pushes
ms_opengiftinOpenNextGift(). - Pushes
ms_addgiftreceiver/ms_removegiftreceiverto the assignedgiftmachinewhengiftcountorgiftmachinechanges. - Pushes
ms_giftopenedto the assignedgiftmachineinOnStartOpenGift(). - Pushes
ms_doneopengiftinOnStopOpenGift().