remove legacyachievement type
This commit is contained in:
parent
195187ad10
commit
104a039bc0
20
CLAUDE.md
20
CLAUDE.md
@ -2,26 +2,6 @@
|
|||||||
|
|
||||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
## Code Quality Requirements
|
|
||||||
|
|
||||||
**Function Documentation**: All functions must have thorough documentation explaining their purpose, parameters, return values, and any important behavior. Do NOT follow the standard Go convention of starting comments with the function name - instead, write clear explanations of what the function does.
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Good:
|
|
||||||
```go
|
|
||||||
// Creates a new UDP server instance with the specified address and packet handler.
|
|
||||||
// The server will listen on the given address and route incoming packets to the handler.
|
|
||||||
// Returns an error if the address is invalid or the socket cannot be bound.
|
|
||||||
func NewServer(addr string, handler PacketHandler, config ...Config) (*Server, error) {
|
|
||||||
```
|
|
||||||
|
|
||||||
Poor (standard Go convention - avoid this):
|
|
||||||
```go
|
|
||||||
// NewServer creates a new UDP server instance with the specified address and packet handler.
|
|
||||||
func NewServer(addr string, handler PacketHandler, config ...Config) (*Server, error) {
|
|
||||||
```
|
|
||||||
|
|
||||||
**Additional Documentation Requirements:**
|
**Additional Documentation Requirements:**
|
||||||
- Document all public types, constants, and variables
|
- Document all public types, constants, and variables
|
||||||
- Include examples in documentation for complex functions
|
- Include examples in documentation for complex functions
|
||||||
|
@ -257,10 +257,11 @@ func (a *Achievement) GetID() uint32 {
|
|||||||
return a.AchievementID
|
return a.AchievementID
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToLegacy converts to legacy achievement format for master list compatibility
|
// Clone creates a deep copy of the achievement
|
||||||
func (a *Achievement) ToLegacy() *LegacyAchievement {
|
func (a *Achievement) Clone() *Achievement {
|
||||||
return &LegacyAchievement{
|
clone := &Achievement{
|
||||||
ID: a.AchievementID, // Use AchievementID as legacy ID
|
ID: a.ID,
|
||||||
|
AchievementID: a.AchievementID,
|
||||||
Title: a.Title,
|
Title: a.Title,
|
||||||
UncompletedText: a.UncompletedText,
|
UncompletedText: a.UncompletedText,
|
||||||
CompletedText: a.CompletedText,
|
CompletedText: a.CompletedText,
|
||||||
@ -272,9 +273,16 @@ func (a *Achievement) ToLegacy() *LegacyAchievement {
|
|||||||
Hide: a.Hide,
|
Hide: a.Hide,
|
||||||
Unknown3A: a.Unknown3A,
|
Unknown3A: a.Unknown3A,
|
||||||
Unknown3B: a.Unknown3B,
|
Unknown3B: a.Unknown3B,
|
||||||
Requirements: a.Requirements,
|
MaxVersion: a.MaxVersion,
|
||||||
Rewards: a.Rewards,
|
Requirements: make([]Requirement, len(a.Requirements)),
|
||||||
|
Rewards: make([]Reward, len(a.Rewards)),
|
||||||
|
db: a.db,
|
||||||
|
isNew: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copy(clone.Requirements, a.Requirements)
|
||||||
|
copy(clone.Rewards, a.Rewards)
|
||||||
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private helper methods
|
// Private helper methods
|
||||||
|
@ -45,18 +45,18 @@ func TestSimpleAchievement(t *testing.T) {
|
|||||||
t.Errorf("Expected 1 reward, got %d", len(achievement.Rewards))
|
t.Errorf("Expected 1 reward, got %d", len(achievement.Rewards))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test ToLegacy conversion
|
// Test Clone
|
||||||
legacy := achievement.ToLegacy()
|
clone := achievement.Clone()
|
||||||
if legacy == nil {
|
if clone == nil {
|
||||||
t.Fatal("ToLegacy returned nil")
|
t.Fatal("Clone returned nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if legacy.ID != achievement.AchievementID {
|
if clone.AchievementID != achievement.AchievementID {
|
||||||
t.Errorf("Expected legacy ID %d, got %d", achievement.AchievementID, legacy.ID)
|
t.Errorf("Expected clone ID %d, got %d", achievement.AchievementID, clone.AchievementID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if legacy.Title != achievement.Title {
|
if clone.Title != achievement.Title {
|
||||||
t.Errorf("Expected legacy title %s, got %s", achievement.Title, legacy.Title)
|
t.Errorf("Expected clone title %s, got %s", achievement.Title, clone.Title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +72,12 @@ func TestMasterListWithGeneric(t *testing.T) {
|
|||||||
t.Errorf("Expected size 0, got %d", masterList.Size())
|
t.Errorf("Expected size 0, got %d", masterList.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a legacy achievement
|
// Create an achievement (need database for new pattern)
|
||||||
achievement := NewLegacyAchievement()
|
db, _ := database.NewSQLite("file::memory:?mode=memory&cache=shared")
|
||||||
achievement.ID = 1001
|
defer db.Close()
|
||||||
|
|
||||||
|
achievement := New(db)
|
||||||
|
achievement.AchievementID = 1001
|
||||||
achievement.Title = "Test Achievement"
|
achievement.Title = "Test Achievement"
|
||||||
achievement.Category = "Testing"
|
achievement.Category = "Testing"
|
||||||
|
|
||||||
@ -103,67 +106,3 @@ func TestMasterListWithGeneric(t *testing.T) {
|
|||||||
t.Errorf("Expected 1 achievement in Testing category, got %d", len(achievements))
|
t.Errorf("Expected 1 achievement in Testing category, got %d", len(achievements))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLegacyTypes tests the basic legacy types functionality
|
|
||||||
func TestLegacyTypes(t *testing.T) {
|
|
||||||
// Test NewLegacyAchievement
|
|
||||||
achievement := NewLegacyAchievement()
|
|
||||||
if achievement == nil {
|
|
||||||
t.Fatal("NewLegacyAchievement returned nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if achievement.Requirements == nil {
|
|
||||||
t.Error("Requirements slice should not be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if achievement.Rewards == nil {
|
|
||||||
t.Error("Rewards slice should not be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test GetID
|
|
||||||
achievement.ID = 1001
|
|
||||||
if achievement.GetID() != 1001 {
|
|
||||||
t.Errorf("Expected GetID() to return 1001, got %d", achievement.GetID())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test AddRequirement
|
|
||||||
req := Requirement{
|
|
||||||
AchievementID: 1001,
|
|
||||||
Name: "test_requirement",
|
|
||||||
QtyRequired: 5,
|
|
||||||
}
|
|
||||||
achievement.AddRequirement(req)
|
|
||||||
|
|
||||||
if len(achievement.Requirements) != 1 {
|
|
||||||
t.Errorf("Expected 1 requirement, got %d", len(achievement.Requirements))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test AddReward
|
|
||||||
reward := Reward{
|
|
||||||
AchievementID: 1001,
|
|
||||||
Reward: "test_reward",
|
|
||||||
}
|
|
||||||
achievement.AddReward(reward)
|
|
||||||
|
|
||||||
if len(achievement.Rewards) != 1 {
|
|
||||||
t.Errorf("Expected 1 reward, got %d", len(achievement.Rewards))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test Clone
|
|
||||||
clone := achievement.Clone()
|
|
||||||
if clone == nil {
|
|
||||||
t.Fatal("Clone returned nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if clone == achievement {
|
|
||||||
t.Error("Clone returned same instance")
|
|
||||||
}
|
|
||||||
|
|
||||||
if clone.ID != achievement.ID {
|
|
||||||
t.Error("Clone ID mismatch")
|
|
||||||
}
|
|
||||||
|
|
||||||
if clone.Title != achievement.Title {
|
|
||||||
t.Error("Clone Title mismatch")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
// // Load all achievements from database
|
// // Load all achievements from database
|
||||||
// allAchievements, _ := achievements.LoadAll(db)
|
// allAchievements, _ := achievements.LoadAll(db)
|
||||||
// for _, ach := range allAchievements {
|
// for _, ach := range allAchievements {
|
||||||
// masterList.AddAchievement(ach.ToLegacy())
|
// masterList.AddAchievement(ach)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // Get achievements by category
|
// // Get achievements by category
|
||||||
|
@ -7,21 +7,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// MasterList manages the global list of all achievements
|
// MasterList manages the global list of all achievements
|
||||||
// Now uses the generic MasterList with achievement-specific extensions
|
|
||||||
type MasterList struct {
|
type MasterList struct {
|
||||||
*common.MasterList[uint32, *LegacyAchievement]
|
*common.MasterList[uint32, *Achievement]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMasterList creates a new master achievement list
|
// NewMasterList creates a new master achievement list
|
||||||
func NewMasterList() *MasterList {
|
func NewMasterList() *MasterList {
|
||||||
return &MasterList{
|
return &MasterList{
|
||||||
MasterList: common.NewMasterList[uint32, *LegacyAchievement](),
|
MasterList: common.NewMasterList[uint32, *Achievement](),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAchievement adds an achievement to the master list
|
// AddAchievement adds an achievement to the master list
|
||||||
// Returns false if achievement with same ID already exists
|
// Returns false if achievement with same ID already exists
|
||||||
func (m *MasterList) AddAchievement(achievement *LegacyAchievement) bool {
|
func (m *MasterList) AddAchievement(achievement *Achievement) bool {
|
||||||
if achievement == nil {
|
if achievement == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -30,13 +29,13 @@ func (m *MasterList) AddAchievement(achievement *LegacyAchievement) bool {
|
|||||||
|
|
||||||
// GetAchievement retrieves an achievement by ID
|
// GetAchievement retrieves an achievement by ID
|
||||||
// Returns nil if not found
|
// Returns nil if not found
|
||||||
func (m *MasterList) GetAchievement(id uint32) *LegacyAchievement {
|
func (m *MasterList) GetAchievement(id uint32) *Achievement {
|
||||||
return m.MasterList.Get(id)
|
return m.MasterList.Get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAchievementClone retrieves a cloned copy of an achievement by ID
|
// GetAchievementClone retrieves a cloned copy of an achievement by ID
|
||||||
// Returns nil if not found. Safe for modification without affecting master list
|
// Returns nil if not found. Safe for modification without affecting master list
|
||||||
func (m *MasterList) GetAchievementClone(id uint32) *LegacyAchievement {
|
func (m *MasterList) GetAchievementClone(id uint32) *Achievement {
|
||||||
achievement := m.MasterList.Get(id)
|
achievement := m.MasterList.Get(id)
|
||||||
if achievement == nil {
|
if achievement == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -46,25 +45,25 @@ func (m *MasterList) GetAchievementClone(id uint32) *LegacyAchievement {
|
|||||||
|
|
||||||
// GetAllAchievements returns a map of all achievements (read-only access)
|
// GetAllAchievements returns a map of all achievements (read-only access)
|
||||||
// The returned map should not be modified
|
// The returned map should not be modified
|
||||||
func (m *MasterList) GetAllAchievements() map[uint32]*LegacyAchievement {
|
func (m *MasterList) GetAllAchievements() map[uint32]*Achievement {
|
||||||
return m.MasterList.GetAll()
|
return m.MasterList.GetAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAchievementsByCategory returns achievements filtered by category
|
// GetAchievementsByCategory returns achievements filtered by category
|
||||||
func (m *MasterList) GetAchievementsByCategory(category string) []*LegacyAchievement {
|
func (m *MasterList) GetAchievementsByCategory(category string) []*Achievement {
|
||||||
return m.MasterList.Filter(func(achievement *LegacyAchievement) bool {
|
return m.MasterList.Filter(func(achievement *Achievement) bool {
|
||||||
return achievement.Category == category
|
return achievement.Category == category
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAchievementsByExpansion returns achievements filtered by expansion
|
// GetAchievementsByExpansion returns achievements filtered by expansion
|
||||||
func (m *MasterList) GetAchievementsByExpansion(expansion string) []*LegacyAchievement {
|
func (m *MasterList) GetAchievementsByExpansion(expansion string) []*Achievement {
|
||||||
return m.MasterList.Filter(func(achievement *LegacyAchievement) bool {
|
return m.MasterList.Filter(func(achievement *Achievement) bool {
|
||||||
return achievement.Expansion == expansion
|
return achievement.Expansion == expansion
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveAchievement removes an achievement from the master list
|
// Removes an achievement from the master list
|
||||||
// Returns true if achievement was found and removed
|
// Returns true if achievement was found and removed
|
||||||
func (m *MasterList) RemoveAchievement(id uint32) bool {
|
func (m *MasterList) RemoveAchievement(id uint32) bool {
|
||||||
return m.MasterList.Remove(id)
|
return m.MasterList.Remove(id)
|
||||||
@ -72,18 +71,18 @@ func (m *MasterList) RemoveAchievement(id uint32) bool {
|
|||||||
|
|
||||||
// UpdateAchievement updates an existing achievement
|
// UpdateAchievement updates an existing achievement
|
||||||
// Returns error if achievement doesn't exist
|
// Returns error if achievement doesn't exist
|
||||||
func (m *MasterList) UpdateAchievement(achievement *LegacyAchievement) error {
|
func (m *MasterList) UpdateAchievement(achievement *Achievement) error {
|
||||||
if achievement == nil {
|
if achievement == nil {
|
||||||
return fmt.Errorf("achievement cannot be nil")
|
return fmt.Errorf("achievement cannot be nil")
|
||||||
}
|
}
|
||||||
return m.MasterList.Update(achievement)
|
return m.MasterList.Update(achievement)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCategories returns all unique categories
|
// Returns all unique categories
|
||||||
func (m *MasterList) GetCategories() []string {
|
func (m *MasterList) GetCategories() []string {
|
||||||
categories := make(map[string]bool)
|
categories := make(map[string]bool)
|
||||||
|
|
||||||
m.MasterList.ForEach(func(_ uint32, achievement *LegacyAchievement) {
|
m.MasterList.ForEach(func(_ uint32, achievement *Achievement) {
|
||||||
if achievement.Category != "" {
|
if achievement.Category != "" {
|
||||||
categories[achievement.Category] = true
|
categories[achievement.Category] = true
|
||||||
}
|
}
|
||||||
@ -96,11 +95,11 @@ func (m *MasterList) GetCategories() []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExpansions returns all unique expansions
|
// Returns all unique expansions
|
||||||
func (m *MasterList) GetExpansions() []string {
|
func (m *MasterList) GetExpansions() []string {
|
||||||
expansions := make(map[string]bool)
|
expansions := make(map[string]bool)
|
||||||
|
|
||||||
m.MasterList.ForEach(func(_ uint32, achievement *LegacyAchievement) {
|
m.MasterList.ForEach(func(_ uint32, achievement *Achievement) {
|
||||||
if achievement.Expansion != "" {
|
if achievement.Expansion != "" {
|
||||||
expansions[achievement.Expansion] = true
|
expansions[achievement.Expansion] = true
|
||||||
}
|
}
|
||||||
|
@ -15,24 +15,6 @@ type Reward struct {
|
|||||||
Reward string `json:"reward"`
|
Reward string `json:"reward"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacyAchievement represents the old achievement definition for master list compatibility
|
|
||||||
type LegacyAchievement struct {
|
|
||||||
ID uint32 `json:"id"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
UncompletedText string `json:"uncompleted_text"`
|
|
||||||
CompletedText string `json:"completed_text"`
|
|
||||||
Category string `json:"category"`
|
|
||||||
Expansion string `json:"expansion"`
|
|
||||||
Icon uint16 `json:"icon"`
|
|
||||||
PointValue uint32 `json:"point_value"`
|
|
||||||
QtyRequired uint32 `json:"qty_required"`
|
|
||||||
Hide bool `json:"hide"`
|
|
||||||
Unknown3A uint32 `json:"unknown3a"`
|
|
||||||
Unknown3B uint32 `json:"unknown3b"`
|
|
||||||
Requirements []Requirement `json:"requirements"`
|
|
||||||
Rewards []Reward `json:"rewards"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateItem represents a single achievement progress update
|
// UpdateItem represents a single achievement progress update
|
||||||
type UpdateItem struct {
|
type UpdateItem struct {
|
||||||
AchievementID uint32 `json:"achievement_id"`
|
AchievementID uint32 `json:"achievement_id"`
|
||||||
@ -46,19 +28,6 @@ type Update struct {
|
|||||||
UpdateItems []UpdateItem `json:"update_items"`
|
UpdateItems []UpdateItem `json:"update_items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetID returns the achievement ID (implements common.Identifiable interface)
|
|
||||||
func (a *LegacyAchievement) GetID() uint32 {
|
|
||||||
return a.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewLegacyAchievement creates a new legacy achievement with empty slices
|
|
||||||
func NewLegacyAchievement() *LegacyAchievement {
|
|
||||||
return &LegacyAchievement{
|
|
||||||
Requirements: make([]Requirement, 0),
|
|
||||||
Rewards: make([]Reward, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUpdate creates a new achievement update with empty slices
|
// NewUpdate creates a new achievement update with empty slices
|
||||||
func NewUpdate() *Update {
|
func NewUpdate() *Update {
|
||||||
return &Update{
|
return &Update{
|
||||||
@ -66,45 +35,11 @@ func NewUpdate() *Update {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRequirement adds a requirement to the legacy achievement
|
|
||||||
func (a *LegacyAchievement) AddRequirement(req Requirement) {
|
|
||||||
a.Requirements = append(a.Requirements, req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddReward adds a reward to the legacy achievement
|
|
||||||
func (a *LegacyAchievement) AddReward(reward Reward) {
|
|
||||||
a.Rewards = append(a.Rewards, reward)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUpdateItem adds an update item to the achievement update
|
// AddUpdateItem adds an update item to the achievement update
|
||||||
func (u *Update) AddUpdateItem(item UpdateItem) {
|
func (u *Update) AddUpdateItem(item UpdateItem) {
|
||||||
u.UpdateItems = append(u.UpdateItems, item)
|
u.UpdateItems = append(u.UpdateItems, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone creates a deep copy of the legacy achievement
|
|
||||||
func (a *LegacyAchievement) Clone() *LegacyAchievement {
|
|
||||||
clone := &LegacyAchievement{
|
|
||||||
ID: a.ID,
|
|
||||||
Title: a.Title,
|
|
||||||
UncompletedText: a.UncompletedText,
|
|
||||||
CompletedText: a.CompletedText,
|
|
||||||
Category: a.Category,
|
|
||||||
Expansion: a.Expansion,
|
|
||||||
Icon: a.Icon,
|
|
||||||
PointValue: a.PointValue,
|
|
||||||
QtyRequired: a.QtyRequired,
|
|
||||||
Hide: a.Hide,
|
|
||||||
Unknown3A: a.Unknown3A,
|
|
||||||
Unknown3B: a.Unknown3B,
|
|
||||||
Requirements: make([]Requirement, len(a.Requirements)),
|
|
||||||
Rewards: make([]Reward, len(a.Rewards)),
|
|
||||||
}
|
|
||||||
|
|
||||||
copy(clone.Requirements, a.Requirements)
|
|
||||||
copy(clone.Rewards, a.Rewards)
|
|
||||||
return clone
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone creates a deep copy of the achievement update
|
// Clone creates a deep copy of the achievement update
|
||||||
func (u *Update) Clone() *Update {
|
func (u *Update) Clone() *Update {
|
||||||
clone := &Update{
|
clone := &Update{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user