feat: room 包新增房间创建事件
This commit is contained in:
parent
cee067e246
commit
87c66954a3
|
@ -21,6 +21,8 @@ type (
|
|||
PlayerSeatSetEventHandle[PID comparable, P game.Player[PID], R Room] func(room R, player P, seat int)
|
||||
// PlayerSeatCancelEventHandle 玩家座位取消事件处理函数
|
||||
PlayerSeatCancelEventHandle[PID comparable, P game.Player[PID], R Room] func(room R, player P, seat int)
|
||||
// RoomCreateEventHandle 房间创建事件处理函数
|
||||
RoomCreateEventHandle[PID comparable, P game.Player[PID], R Room] func(room R, helper *Helper[PID, P, R])
|
||||
)
|
||||
|
||||
func newEvent[PID comparable, P game.Player[PID], R Room]() *event[PID, P, R] {
|
||||
|
@ -55,6 +57,7 @@ type event[PID comparable, P game.Player[PID], R Room] struct {
|
|||
playerSeatSetEventRoomHandles map[int64][]PlayerSeatSetEventHandle[PID, P, R]
|
||||
playerSeatCancelEventHandles []PlayerSeatCancelEventHandle[PID, P, R]
|
||||
playerSeatCancelEventRoomHandles map[int64][]PlayerSeatCancelEventHandle[PID, P, R]
|
||||
roomCreateEventHandles []RoomCreateEventHandle[PID, P, R]
|
||||
}
|
||||
|
||||
func (slf *event[PID, P, R]) unReg(guid int64) {
|
||||
|
@ -249,3 +252,15 @@ func (slf *event[PID, P, R]) OnPlayerSeatCancelEvent(room R, player P, seat int)
|
|||
handle(room, player, seat)
|
||||
}
|
||||
}
|
||||
|
||||
// RegRoomCreateEvent 房间创建时将立即执行被注册的事件处理函数
|
||||
func (slf *event[PID, P, R]) RegRoomCreateEvent(handle RoomCreateEventHandle[PID, P, R]) {
|
||||
slf.roomCreateEventHandles = append(slf.roomCreateEventHandles, handle)
|
||||
}
|
||||
|
||||
// OnRoomCreateEvent 房间创建时将立即执行被注册的事件处理函数
|
||||
func (slf *event[PID, P, R]) OnRoomCreateEvent(room R, helper *Helper[PID, P, R]) {
|
||||
for _, handle := range slf.roomCreateEventHandles {
|
||||
handle(room, helper)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ func (slf *Manager[PID, P, R]) CreateRoom(room R, options ...Option[PID, P, R])
|
|||
option(roomInfo)
|
||||
}
|
||||
slf.rooms.Set(room.GetGuid(), roomInfo)
|
||||
slf.OnRoomCreateEvent(room, slf.GetHelper(room))
|
||||
}
|
||||
|
||||
// ReleaseRoom 释放房间
|
||||
|
|
Loading…
Reference in New Issue