82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
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
|
|
townList, err := user.GetKnownTowns()
|
|
if err != nil {
|
|
fmt.Printf("User town list error: %s\n", err.Error())
|
|
}
|
|
data["_towns"] = townList
|
|
|
|
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()
|
|
|
|
if user.Level == 1 {
|
|
data["_exp_display"] = user.Exp
|
|
data["_exp_needed"] = helpers.ExpAtLevel(2)
|
|
} else {
|
|
currentLevelExp := helpers.ExpAtLevel(user.Level)
|
|
nextLevelExp := helpers.ExpAtLevel(user.Level + 1)
|
|
data["_exp_display"] = user.Exp - currentLevelExp
|
|
data["_exp_needed"] = nextLevelExp - currentLevelExp
|
|
}
|
|
|
|
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
|
|
healingSpells, err := user.GetHealingSpells()
|
|
if err != nil {
|
|
fmt.Printf("User healing spells list error: %s\n", err.Error())
|
|
}
|
|
data["_spells"] = healingSpells
|
|
|
|
return data
|
|
}
|