57 lines
1.1 KiB
Go
57 lines
1.1 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
|
|
}
|
|
|
|
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),
|
|
}
|
|
}
|