mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 13:53:41 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
package userdata
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"lunar-tear/server/internal/model"
|
||||
"lunar-tear/server/internal/store"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register("IUserDeck", func(user store.UserState) string {
|
||||
s, _ := encodeJSONMaps(sortedDeckRecords(user)...)
|
||||
return s
|
||||
})
|
||||
register("IUserDeckCharacter", func(user store.UserState) string {
|
||||
s, _ := encodeJSONMaps(sortedDeckCharacterRecords(user)...)
|
||||
return s
|
||||
})
|
||||
register("IUserDeckSubWeaponGroup", func(user store.UserState) string {
|
||||
s, _ := encodeJSONMaps(sortedDeckSubWeaponGroupRecords(user)...)
|
||||
return s
|
||||
})
|
||||
register("IUserDeckTypeNote", func(user store.UserState) string {
|
||||
s, _ := encodeJSONMaps(sortedDeckTypeNoteRecords(user)...)
|
||||
return s
|
||||
})
|
||||
register("IUserDeckPartsGroup", func(user store.UserState) string {
|
||||
s, _ := encodeJSONMaps(sortedDeckPartsGroupRecords(user)...)
|
||||
return s
|
||||
})
|
||||
register("IUserDeckCharacterDressupCostume", func(user store.UserState) string {
|
||||
s, _ := encodeJSONMaps(sortedDeckDressupCostumeRecords(user)...)
|
||||
return s
|
||||
})
|
||||
registerStatic(
|
||||
"IUserDeckLimitContentRestricted",
|
||||
)
|
||||
}
|
||||
|
||||
func sortedDeckRecords(user store.UserState) []map[string]any {
|
||||
keys := make([]store.DeckKey, 0, len(user.Decks))
|
||||
for key := range user.Decks {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
if keys[i].DeckType != keys[j].DeckType {
|
||||
return keys[i].DeckType < keys[j].DeckType
|
||||
}
|
||||
return keys[i].UserDeckNumber < keys[j].UserDeckNumber
|
||||
})
|
||||
|
||||
records := make([]map[string]any, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
row := user.Decks[key]
|
||||
records = append(records, map[string]any{
|
||||
"userId": user.UserId,
|
||||
"deckType": row.DeckType,
|
||||
"userDeckNumber": row.UserDeckNumber,
|
||||
"userDeckCharacterUuid01": row.UserDeckCharacterUuid01,
|
||||
"userDeckCharacterUuid02": row.UserDeckCharacterUuid02,
|
||||
"userDeckCharacterUuid03": row.UserDeckCharacterUuid03,
|
||||
"name": row.Name,
|
||||
"power": row.Power,
|
||||
"latestVersion": row.LatestVersion,
|
||||
})
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
||||
func sortedDeckCharacterRecords(user store.UserState) []map[string]any {
|
||||
keys := sortedStringKeys(user.DeckCharacters)
|
||||
records := make([]map[string]any, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
row := user.DeckCharacters[key]
|
||||
records = append(records, map[string]any{
|
||||
"userId": user.UserId,
|
||||
"userDeckCharacterUuid": row.UserDeckCharacterUuid,
|
||||
"userCostumeUuid": row.UserCostumeUuid,
|
||||
"mainUserWeaponUuid": row.MainUserWeaponUuid,
|
||||
"userCompanionUuid": row.UserCompanionUuid,
|
||||
"power": row.Power,
|
||||
"userThoughtUuid": row.UserThoughtUuid,
|
||||
"latestVersion": row.LatestVersion,
|
||||
})
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
||||
func sortedDeckSubWeaponGroupRecords(user store.UserState) []map[string]any {
|
||||
keys := sortedStringKeys(user.DeckSubWeapons)
|
||||
records := make([]map[string]any, 0)
|
||||
for _, dcUuid := range keys {
|
||||
weapons := user.DeckSubWeapons[dcUuid]
|
||||
var lv int64
|
||||
if dc, ok := user.DeckCharacters[dcUuid]; ok {
|
||||
lv = dc.LatestVersion
|
||||
}
|
||||
for idx, weaponUuid := range weapons {
|
||||
records = append(records, map[string]any{
|
||||
"userId": user.UserId,
|
||||
"userDeckCharacterUuid": dcUuid,
|
||||
"userWeaponUuid": weaponUuid,
|
||||
"sortOrder": int32(idx + 1),
|
||||
"latestVersion": lv,
|
||||
})
|
||||
}
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
||||
func sortedDeckTypeNoteRecords(user store.UserState) []map[string]any {
|
||||
ids := make([]int, 0, len(user.DeckTypeNotes))
|
||||
for id := range user.DeckTypeNotes {
|
||||
ids = append(ids, int(id))
|
||||
}
|
||||
sort.Ints(ids)
|
||||
|
||||
records := make([]map[string]any, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
row := user.DeckTypeNotes[model.DeckType(id)]
|
||||
records = append(records, map[string]any{
|
||||
"userId": user.UserId,
|
||||
"deckType": row.DeckType,
|
||||
"maxDeckPower": row.MaxDeckPower,
|
||||
"latestVersion": row.LatestVersion,
|
||||
})
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
||||
func sortedDeckPartsGroupRecords(user store.UserState) []map[string]any {
|
||||
keys := sortedStringKeys(user.DeckParts)
|
||||
records := make([]map[string]any, 0)
|
||||
for _, dcUuid := range keys {
|
||||
parts := user.DeckParts[dcUuid]
|
||||
var lv int64
|
||||
if dc, ok := user.DeckCharacters[dcUuid]; ok {
|
||||
lv = dc.LatestVersion
|
||||
}
|
||||
for idx, partsUuid := range parts {
|
||||
records = append(records, map[string]any{
|
||||
"userId": user.UserId,
|
||||
"userDeckCharacterUuid": dcUuid,
|
||||
"userPartsUuid": partsUuid,
|
||||
"sortOrder": int32(idx + 1),
|
||||
"latestVersion": lv,
|
||||
})
|
||||
}
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
||||
func DeckSubWeaponRecords(user store.UserState) []map[string]any {
|
||||
return sortedDeckSubWeaponGroupRecords(user)
|
||||
}
|
||||
|
||||
func DeckPartsGroupRecords(user store.UserState) []map[string]any {
|
||||
return sortedDeckPartsGroupRecords(user)
|
||||
}
|
||||
|
||||
func sortedDeckDressupCostumeRecords(user store.UserState) []map[string]any {
|
||||
keys := sortedStringKeys(user.DeckCharacters)
|
||||
records := make([]map[string]any, 0)
|
||||
for _, key := range keys {
|
||||
row := user.DeckCharacters[key]
|
||||
if row.DressupCostumeId == 0 {
|
||||
continue
|
||||
}
|
||||
records = append(records, map[string]any{
|
||||
"userId": user.UserId,
|
||||
"userDeckCharacterUuid": row.UserDeckCharacterUuid,
|
||||
"dressupCostumeId": row.DressupCostumeId,
|
||||
"latestVersion": row.LatestVersion,
|
||||
})
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
||||
func DeckDressupCostumeRecords(user store.UserState) []map[string]any {
|
||||
return sortedDeckDressupCostumeRecords(user)
|
||||
}
|
||||
Reference in New Issue
Block a user