package components import ( "dk/internal/helpers" "dk/internal/middleware" "dk/internal/router" "dk/internal/spells" "dk/internal/towns" ) // LeftAside generates the data map for the left sidebar. // Returns an empty map when not auth'd. func LeftAside(ctx router.Ctx) map[string]any { data := map[string]any{} user := middleware.GetCurrentUser(ctx) if user == nil { return data } // Build owned town maps list if user.Towns != "" { townMap := helpers.NewOrderedMap[int, string]() for _, id := range user.GetTownIDs() { if town, err := towns.Find(id); err == nil { townMap.Set(id, town.Name) } } data["_towns"] = townMap.ToSlice() } return data } // RightAside generates the data map for the right sidebar. // Returns an empty map when not auth'd. func RightAside(ctx router.Ctx) map[string]any { data := map[string]any{} user := middleware.GetCurrentUser(ctx) if user == nil { return data } hpPct := helpers.ClampPct(float64(user.HP), float64(user.MaxHP), 0, 100) data["hpPct"] = hpPct data["mpPct"] = helpers.ClampPct(float64(user.MP), float64(user.MaxMP), 0, 100) data["tpPct"] = helpers.ClampPct(float64(user.TP), float64(user.MaxTP), 0, 100) data["hpColor"] = "" if hpPct < 35 { data["hpColor"] = "danger" } else if hpPct < 75 { data["hpColor"] = "warning" } // Build known healing spells list if user.Spells != "" { spellMap := helpers.NewOrderedMap[int, string]() for _, id := range user.GetSpellIDs() { if spell, err := spells.Find(id); err == nil { spellMap.Set(id, spell.Name) } } data["_spells"] = spellMap.ToSlice() } return data }