Files
go-nkode/core/keypad_dimension.go
2024-10-14 13:29:05 -05:00

55 lines
1.2 KiB
Go

package core
import (
py "go-nkode/py-builtin"
)
type KeypadDimension struct {
AttrsPerKey int `json:"attrs_per_key"`
NumbOfKeys int `json:"numb_of_keys"`
}
func (kp *KeypadDimension) TotalAttrs() int {
return kp.AttrsPerKey * kp.NumbOfKeys
}
func (kp *KeypadDimension) IsDispersable() bool {
return kp.AttrsPerKey <= kp.NumbOfKeys
}
func (kp *KeypadDimension) IsValidKeypadDimension() error {
if KeypadMin.AttrsPerKey > kp.AttrsPerKey || KeypadMax.AttrsPerKey < kp.AttrsPerKey || KeypadMin.NumbOfKeys > kp.NumbOfKeys || KeypadMax.NumbOfKeys < kp.NumbOfKeys {
return ErrInvalidKeypadDimensions
}
return nil
}
func (kp *KeypadDimension) ValidKeySelections(selectedKeys []int) bool {
return py.All[int](selectedKeys, func(idx int) bool {
return 0 <= idx && idx < kp.NumbOfKeys
})
}
func (kp *KeypadDimension) ValidateAttributeIndices(attrIndicies []int) bool {
return py.All[int](attrIndicies, func(i int) bool {
return i >= 0 && i < kp.TotalAttrs()
})
}
var (
KeypadMax = KeypadDimension{
AttrsPerKey: 16,
NumbOfKeys: 15,
}
KeypadMin = KeypadDimension{
AttrsPerKey: 5,
NumbOfKeys: 4,
}
KeypadDefault = KeypadDimension{
AttrsPerKey: 14,
NumbOfKeys: 7,
}
)