mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package userdata
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"lunar-tear/server/internal/store"
|
||||
)
|
||||
|
||||
type Projector func(user store.UserState) string
|
||||
|
||||
var projectors = make(map[string]Projector)
|
||||
|
||||
func register(tableName string, fn Projector) {
|
||||
projectors[tableName] = fn
|
||||
}
|
||||
|
||||
func registerStatic(tableNames ...string) {
|
||||
for _, name := range tableNames {
|
||||
projectors[name] = func(_ store.UserState) string { return "[]" }
|
||||
}
|
||||
}
|
||||
|
||||
func projectTable(tableName string, user store.UserState) string {
|
||||
fn, ok := projectors[tableName]
|
||||
if !ok {
|
||||
return "[]"
|
||||
}
|
||||
s := fn(user)
|
||||
if s == "" {
|
||||
return "[]"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func sortedStringKeys[T any](rows map[string]T) []string {
|
||||
keys := make([]string, 0, len(rows))
|
||||
for key := range rows {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
func compareGimmickKey(a, b store.GimmickKey) int {
|
||||
if a.GimmickSequenceScheduleId != b.GimmickSequenceScheduleId {
|
||||
if a.GimmickSequenceScheduleId < b.GimmickSequenceScheduleId {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if a.GimmickSequenceId != b.GimmickSequenceId {
|
||||
if a.GimmickSequenceId < b.GimmickSequenceId {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if a.GimmickId < b.GimmickId {
|
||||
return -1
|
||||
}
|
||||
if a.GimmickId > b.GimmickId {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func compareGimmickOrnamentKey(a, b store.GimmickOrnamentKey) int {
|
||||
if cmp := compareGimmickKey(
|
||||
store.GimmickKey{
|
||||
GimmickSequenceScheduleId: a.GimmickSequenceScheduleId,
|
||||
GimmickSequenceId: a.GimmickSequenceId,
|
||||
GimmickId: a.GimmickId,
|
||||
},
|
||||
store.GimmickKey{
|
||||
GimmickSequenceScheduleId: b.GimmickSequenceScheduleId,
|
||||
GimmickSequenceId: b.GimmickSequenceId,
|
||||
GimmickId: b.GimmickId,
|
||||
},
|
||||
); cmp != 0 {
|
||||
return cmp
|
||||
}
|
||||
if a.GimmickOrnamentIndex < b.GimmickOrnamentIndex {
|
||||
return -1
|
||||
}
|
||||
if a.GimmickOrnamentIndex > b.GimmickOrnamentIndex {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user