v4/presentation/role.go
2025-04-05 23:38:02 -07:00

59 lines
1.2 KiB
Go

package presentation
import (
"git.sapphic.engineer/roleypoly/v4/types"
"git.sapphic.engineer/roleypoly/v4/utils"
)
type InputType string
const (
InputCheckbox InputType = "checkbox"
InputRadio InputType = "radio"
)
type PresentableRole struct {
ID string
CategoryID string
Name string
Selected bool
InputType InputType
Colors PresentableRoleColors
}
func Role(category *types.Category, role *types.Role, selected bool) PresentableRole {
inputType := InputCheckbox
if category.Type == types.CategorySingle {
inputType = InputRadio
}
colors := GetColors(role.Color)
return PresentableRole{
ID: role.ID,
CategoryID: category.ID,
Name: role.Name,
Selected: selected,
InputType: inputType,
Colors: colors,
}
}
type PresentableRoleColors struct {
Main string
Alt string
IsDark bool
}
func GetColors(roleColor uint32) PresentableRoleColors {
// TODO: no color
r, g, b := utils.IntToRgb(roleColor)
altR, altG, altB := utils.AltColor(r, g, b)
return PresentableRoleColors{
Main: utils.RgbToString(r, g, b),
Alt: utils.RgbToString(altR, altG, altB),
IsDark: utils.IsDarkColor(r, g, b),
}
}