package components import ( "dk/internal/helpers" "dk/internal/models/towns" "dk/internal/models/users" "fmt" sushi "git.sharkk.net/Sharkk/Sushi" ) // LeftAside generates the data map for the left sidebar. // Returns an empty map when not auth'd. func LeftAside(ctx sushi.Ctx) map[string]any { data := map[string]any{} if !ctx.IsAuthenticated() { return data } user := ctx.UserValue("user").(*users.User) if user.Currently == "In Town" { data["town"], _ = towns.ByCoords(user.X, user.Y) } // Build owned town maps list if user.Towns != "" { townMap := helpers.NewOrderedMap[int, *towns.Town]() for _, id := range user.GetTownIDs() { if town, err := towns.Find(id); err == nil { townMap.Set(id, town) } } 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 sushi.Ctx) map[string]any { data := map[string]any{} if !ctx.IsAuthenticated() { return data } user := ctx.GetCurrentUser().(*users.User) data["_class"] = user.Class() data["_expprog"] = fmt.Sprintf("%.1f", user.ExpProgress()) 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 userSpells, err := user.GetSpells() if err == nil { spellMap := helpers.NewOrderedMap[int, string]() for _, spell := range userSpells { if spell.IsHeal() { spellMap.Set(spell.ID, spell.Name) } } data["_spells"] = spellMap.ToSlice() } return data }