activity

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEntityData added in v0.3.2

func LoadEntityData(handler func(activityType, activityId, entityId, data any))

LoadEntityData 加载所有活动实体数据

func LoadGlobalData added in v0.3.2

func LoadGlobalData(handler func(activityType, activityId, data any))

LoadGlobalData 加载所有活动全局数据

func LoadOrRefreshActivity added in v0.3.2

func LoadOrRefreshActivity[Type, ID generic.Basic](activityType Type, activityId ID, options ...*Options) error

LoadOrRefreshActivity 加载或刷新活动

  • 通常在活动配置刷新时候将活动通过该方法注册或刷新

func OnEndedEvent added in v0.3.2

func OnEndedEvent[Type, ID generic.Basic](activity *Activity[Type, ID])

OnEndedEvent 活动结束事件

func OnExtendedShowEndedEvent added in v0.3.2

func OnExtendedShowEndedEvent[Type, ID generic.Basic](activity *Activity[Type, ID])

OnExtendedShowEndedEvent 活动结束后延长展示结束事件

func OnExtendedShowStartedEvent added in v0.3.2

func OnExtendedShowStartedEvent[Type, ID generic.Basic](activity *Activity[Type, ID])

OnExtendedShowStartedEvent 活动结束后延长展示开始事件

func OnNewDayEvent added in v0.3.2

func OnNewDayEvent[Type, ID generic.Basic](activity *Activity[Type, ID])

OnNewDayEvent 新的一天事件

func OnStartedEvent added in v0.3.2

func OnStartedEvent[Type, ID generic.Basic](activity *Activity[Type, ID])

OnStartedEvent 活动开始事件

func OnUpcomingEvent added in v0.3.2

func OnUpcomingEvent[Type, ID generic.Basic](activity *Activity[Type, ID])

OnUpcomingEvent 即将开始的活动事件

func RegEndedEvent added in v0.3.2

func RegEndedEvent[Type, ID generic.Basic](activityType Type, handler EndedEventHandler[ID], priority ...int)

RegEndedEvent 注册活动结束事件处理器

func RegExtendedShowEndedEvent added in v0.3.2

func RegExtendedShowEndedEvent[Type, ID generic.Basic](activityType Type, handler ExtendedShowEndedEventHandler[ID], priority ...int)

RegExtendedShowEndedEvent 注册活动结束后延长展示结束事件处理器

func RegExtendedShowStartedEvent added in v0.3.2

func RegExtendedShowStartedEvent[Type, ID generic.Basic](activityType Type, handler ExtendedShowStartedEventHandler[ID], priority ...int)

RegExtendedShowStartedEvent 注册活动结束后延长展示开始事件处理器

func RegNewDayEvent added in v0.3.2

func RegNewDayEvent[Type, ID generic.Basic](activityType Type, handler NewDayEventHandler[ID], priority ...int)

RegNewDayEvent 注册新的一天事件处理器

func RegStartedEvent added in v0.3.2

func RegStartedEvent[Type, ID generic.Basic](activityType Type, handler StartedEventHandler[ID], priority ...int)

RegStartedEvent 注册活动开始事件处理器

func RegUpcomingEvent added in v0.3.2

func RegUpcomingEvent[Type, ID generic.Basic](activityType Type, handler UpcomingEventHandler[ID], priority ...int)

RegUpcomingEvent 注册即将开始的活动事件处理器

func SetTicker added in v0.0.3

func SetTicker(size int, options ...timer.Option)

SetTicker 设置自定义定时器,该方法必须在使用活动系统前调用,且只能调用一次

Types

type Activity

type Activity[Type, ID generic.Basic] struct {
	// contains filtered or unexported fields
}

Activity 活动描述

type BasicActivityController added in v0.3.2

type BasicActivityController[Type, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any] interface {
	// IsOpen 活动是否开启
	IsOpen(activityId ID) bool
	// IsShow 活动是否展示
	IsShow(activityId ID) bool
	// IsOpenOrShow 活动是否开启或展示
	IsOpenOrShow(activityId ID) bool
	// Refresh 刷新活动
	Refresh(activityId ID)
}

type Controller added in v0.3.2

type Controller[Type, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any] struct {
	// contains filtered or unexported fields
}

Controller 活动控制器

func (*Controller[Type, ID, Data, EntityID, EntityData]) GetEntityData added in v0.3.2

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) GetEntityData(activityId ID, entityId EntityID) EntityData

GetEntityData 获取特定活动实体数据

func (*Controller[Type, ID, Data, EntityID, EntityData]) GetGlobalData added in v0.3.2

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) GetGlobalData(activityId ID) Data

GetGlobalData 获取特定活动全局数据

func (*Controller[Type, ID, Data, EntityID, EntityData]) InitializeEntityData added in v0.3.3

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) InitializeEntityData(handler func(activityId ID, entityId EntityID, data *EntityDataMeta[EntityData])) EntityDataActivityController[Type, ID, Data, EntityID, EntityData]

func (*Controller[Type, ID, Data, EntityID, EntityData]) InitializeGlobalAndEntityData added in v0.3.3

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) InitializeGlobalAndEntityData(handler func(activityId ID, data *DataMeta[Data]), entityHandler func(activityId ID, entityId EntityID, data *EntityDataMeta[EntityData])) GlobalAndEntityDataActivityController[Type, ID, Data, EntityID, EntityData]

func (*Controller[Type, ID, Data, EntityID, EntityData]) InitializeGlobalData added in v0.3.3

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) InitializeGlobalData(handler func(activityId ID, data *DataMeta[Data])) GlobalDataActivityController[Type, ID, Data, EntityID, EntityData]

func (*Controller[Type, ID, Data, EntityID, EntityData]) InitializeNoneData added in v0.3.3

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) InitializeNoneData(handler func(activityId ID, data *DataMeta[Data])) NoneDataActivityController[Type, ID, Data, EntityID, EntityData]

func (*Controller[Type, ID, Data, EntityID, EntityData]) IsOpen added in v0.3.2

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) IsOpen(activityId ID) bool

IsOpen 活动是否开启

func (*Controller[Type, ID, Data, EntityID, EntityData]) IsOpenOrShow added in v0.3.2

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) IsOpenOrShow(activityId ID) bool

IsOpenOrShow 活动是否开启或展示

func (*Controller[Type, ID, Data, EntityID, EntityData]) IsShow added in v0.3.2

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) IsShow(activityId ID) bool

IsShow 活动是否展示

func (*Controller[Type, ID, Data, EntityID, EntityData]) Refresh added in v0.3.2

func (slf *Controller[Type, ID, Data, EntityID, EntityData]) Refresh(activityId ID)

Refresh 刷新活动

type DataMeta added in v0.3.2

type DataMeta[Data any] struct {
	Data       Data      `json:"data,omitempty"`         // 活动数据
	LastNewDay time.Time `json:"last_new_day,omitempty"` // 上次跨天时间
	// contains filtered or unexported fields
}

DataMeta 全局活动数据

type EndedEventHandler added in v0.3.2

type EndedEventHandler[ID generic.Basic] func(activityId ID) // 活动结束事件处理器

type EntityDataActivityController added in v0.3.2

type EntityDataActivityController[Type, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any] interface {
	BasicActivityController[Type, ID, Data, EntityID, EntityData]
	// GetEntityData 获取实体数据
	GetEntityData(activityId ID, entityId EntityID) EntityData
	// InitializeEntityData 初始化活动
	//  - 该函数提供了一个操作活动数据的入口,可以在该函数中对传入的活动数据进行初始化
	InitializeEntityData(handler func(activityId ID, entityId EntityID, data *EntityDataMeta[EntityData])) EntityDataActivityController[Type, ID, Data, EntityID, EntityData]
}

EntityDataActivityController 实体数据活动控制器

func DefineEntityDataActivity added in v0.3.2

func DefineEntityDataActivity[Type, ID, EntityID generic.Basic, EntityData any](activityType Type) EntityDataActivityController[Type, ID, *none, EntityID, EntityData]

DefineEntityDataActivity 声明拥有实体数据的活动类型

type EntityDataMeta added in v0.3.2

type EntityDataMeta[Data any] struct {
	Data       Data      `json:"data,omitempty"`         // 活动数据
	LastNewDay time.Time `json:"last_new_day,omitempty"` // 上次跨天时间
	// contains filtered or unexported fields
}

EntityDataMeta 活动实体数据

type ExtendedShowEndedEventHandler added in v0.3.2

type ExtendedShowEndedEventHandler[ID generic.Basic] func(activityId ID) // 活动结束后延长展示结束事件处理器

type ExtendedShowStartedEventHandler added in v0.3.2

type ExtendedShowStartedEventHandler[ID generic.Basic] func(activityId ID) // 活动结束后延长展示开始事件处理器

type GlobalAndEntityDataActivityController added in v0.3.2

type GlobalAndEntityDataActivityController[Type, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any] interface {
	BasicActivityController[Type, ID, Data, EntityID, EntityData]
	// GetGlobalData 获取全局数据
	GetGlobalData(activityId ID) Data
	// GetEntityData 获取实体数据
	GetEntityData(activityId ID, entityId EntityID) EntityData
	// InitializeGlobalAndEntityData 初始化活动
	//  - 该函数提供了一个操作活动数据的入口,可以在该函数中对传入的活动数据进行初始化
	InitializeGlobalAndEntityData(handler func(activityId ID, data *DataMeta[Data]), entityHandler func(activityId ID, entityId EntityID, data *EntityDataMeta[EntityData])) GlobalAndEntityDataActivityController[Type, ID, Data, EntityID, EntityData]
}

GlobalAndEntityDataActivityController 全局数据和实体数据活动控制器

func DefineGlobalAndEntityDataActivity added in v0.3.2

func DefineGlobalAndEntityDataActivity[Type, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any](activityType Type) GlobalAndEntityDataActivityController[Type, ID, Data, EntityID, EntityData]

DefineGlobalAndEntityDataActivity 声明拥有全局数据和实体数据的活动类型

type GlobalDataActivityController added in v0.3.2

type GlobalDataActivityController[Type, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any] interface {
	BasicActivityController[Type, ID, Data, EntityID, EntityData]
	// GetGlobalData 获取全局数据
	GetGlobalData(activityId ID) Data
	// InitializeGlobalData 初始化活动
	//  - 该函数提供了一个操作活动数据的入口,可以在该函数中对传入的活动数据进行初始化
	InitializeGlobalData(handler func(activityId ID, data *DataMeta[Data])) GlobalDataActivityController[Type, ID, Data, EntityID, EntityData]
}

GlobalDataActivityController 全局数据活动控制器

func DefineGlobalDataActivity added in v0.3.2

func DefineGlobalDataActivity[Type, ID generic.Basic, Data any](activityType Type) GlobalDataActivityController[Type, ID, Data, none, *none]

DefineGlobalDataActivity 声明拥有全局数据的活动类型

type NewDayEventHandler added in v0.3.2

type NewDayEventHandler[ID generic.Basic] func(activityId ID) // 新的一天事件处理器

type NoneDataActivityController added in v0.3.2

type NoneDataActivityController[Type, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any] interface {
	BasicActivityController[Type, ID, Data, EntityID, EntityData]
	// InitializeNoneData 初始化活动
	//  - 该函数提供了一个操作活动数据的入口,可以在该函数中对传入的活动数据进行初始化
	//
	// 对于无数据活动,该函数的意义在于,可以在该函数中对活动进行初始化,比如设置活动的状态等,虽然为无数据活动,但是例如活动本身携带的状态数据也是需要加载的
	InitializeNoneData(handler func(activityId ID, data *DataMeta[Data])) NoneDataActivityController[Type, ID, Data, EntityID, EntityData]
}

NoneDataActivityController 无数据活动控制器

func DefineNoneDataActivity added in v0.3.2

func DefineNoneDataActivity[Type, ID generic.Basic](activityType Type) NoneDataActivityController[Type, ID, *none, none, *none]

DefineNoneDataActivity 声明无数据的活动类型

type Options added in v0.3.3

type Options struct {
	Tl   *times.StateLine[byte] // 活动时间线
	Loop time.Duration          // 活动循环,时间间隔小于等于 0 表示不循环
}

Options 活动选项

func NewOptions added in v0.3.3

func NewOptions() *Options

NewOptions 创建活动选项

func (*Options) WithEndTime added in v0.3.3

func (slf *Options) WithEndTime(t time.Time) *Options

WithEndTime 设置活动结束时间

func (*Options) WithExtendedShowTime added in v0.3.3

func (slf *Options) WithExtendedShowTime(t time.Time) *Options

WithExtendedShowTime 设置延长展示时间

func (*Options) WithLoop added in v0.3.3

func (slf *Options) WithLoop(interval time.Duration) *Options

WithLoop 设置活动循环,时间间隔小于等于 0 表示不循环

  • 当活动状态展示结束后,会根据该选项设置的时间间隔重新开始

func (*Options) WithStartTime added in v0.3.3

func (slf *Options) WithStartTime(t time.Time) *Options

WithStartTime 设置活动开始时间

func (*Options) WithUpcomingTime added in v0.3.3

func (slf *Options) WithUpcomingTime(t time.Time) *Options

WithUpcomingTime 设置活动预告时间

type StartedEventHandler added in v0.3.2

type StartedEventHandler[ID generic.Basic] func(activityId ID) // 活动开始事件处理器

type UpcomingEventHandler added in v0.3.2

type UpcomingEventHandler[ID generic.Basic] func(activityId ID) // 即将开始的活动事件处理器

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL