refactor errors

This commit is contained in:
2024-10-14 13:29:05 -05:00
parent 1e33a81a2c
commit 39d4a1e7f0
20 changed files with 398 additions and 444 deletions

View File

@@ -1,6 +1,8 @@
package core
import "errors"
import (
py "go-nkode/py-builtin"
)
type KeypadDimension struct {
AttrsPerKey int `json:"attrs_per_key"`
@@ -17,11 +19,23 @@ func (kp *KeypadDimension) IsDispersable() bool {
func (kp *KeypadDimension) IsValidKeypadDimension() error {
if KeypadMin.AttrsPerKey > kp.AttrsPerKey || KeypadMax.AttrsPerKey < kp.AttrsPerKey || KeypadMin.NumbOfKeys > kp.NumbOfKeys || KeypadMax.NumbOfKeys < kp.NumbOfKeys {
return errors.New("keypad dimensions out of range")
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,