refactor(blazing): 重构任务系统并优化相关功能
- 重构了任务系统的数据结构和执行逻辑 - 优化了地图加载和怪物刷新机制 - 改进了宠物系统的基础架构 - 调整了玩家信息和背包的处理方式 - 统一了数据访问层的接口和实现
This commit is contained in:
22
common/utils/tomap.go
Normal file
22
common/utils/tomap.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
// ToMap converts a slice to a map with the keyFunc determining what the key of a value should be.
|
||||
// Will override any double values.
|
||||
func ToMap[T any, K comparable](slice []T, keyFunc func(T) K) map[K]T {
|
||||
m := make(map[K]T, len(slice))
|
||||
for _, v := range slice {
|
||||
m[keyFunc(v)] = v
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// ToSliceMap converts a slice to a map with the keyFunc determining what the key of a value should be.
|
||||
// Will append to the slice if the key already exists.
|
||||
func ToSliceMap[T any, K comparable](slice []T, keyFunc func(T) K) map[K][]T {
|
||||
m := make(map[K][]T, len(slice))
|
||||
for _, v := range slice {
|
||||
key := keyFunc(v)
|
||||
m[key] = append(m[key], v)
|
||||
}
|
||||
return m
|
||||
}
|
||||
Reference in New Issue
Block a user