Skip to content

Commit

Permalink
Additional inventory config source hook. (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro authored Feb 4, 2025
1 parent 13e186a commit 23695db
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type InventoryConfig struct {
Items map[string]*InventoryConfigItem `json:"items,omitempty"`
Limits *InventoryConfigLimits `json:"limits,omitempty"`
ItemSets map[string]map[string]bool `json:"-"` // Auto-computed when the config is read or personalized.

ConfigSource ConfigSource[*InventoryConfigItem] `json:"-"` // Not included in serialization, set dynamically.
}

type InventoryConfigItem struct {
Expand Down Expand Up @@ -69,4 +71,10 @@ type InventorySystem interface {

// SetOnConsumeReward sets a custom reward function which will run after an inventory items' consume reward is rolled.
SetOnConsumeReward(fn OnReward[*InventoryConfigItem])

// SetConfigSource sets a custom additional config lookup function.
SetConfigSource(fn ConfigSource[*InventoryConfigItem])
}

// ConfigSource is a function which can be used to provide additional on-demand configuration data to a requesting system.
type ConfigSource[T any] func(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, configID string) (T, error)

0 comments on commit 23695db

Please sign in to comment.