-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.go
52 lines (40 loc) · 1.19 KB
/
misc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package mipix
import "github.com/hajimehoshi/ebiten/v2"
import "github.com/tinne26/mipix/internal"
// Helper type used for fades and durations of some effects.
type TicksDuration = internal.TicksDuration
const ZeroTicks TicksDuration = 0
// Quick alias to the control key for use with [AccessorDebug.Printfk]().
const Ctrl = ebiten.KeyControl
// internal usage
const maxUint32 = 0xFFFF_FFFF
// --- helpers ---
func setAt[T any](slice []T, element T, index int) []T {
// base case: element index already in range
if index < len(slice) {
slice[index] = element
return slice
}
// append case: element index is the next
if index == len(slice) {
return append(slice, element)
}
// within capacity: element can be set by expanding capacity
if index < cap(slice) {
slice = slice[ : index + 1]
slice[index] = element
return slice
}
// more capacity needed: expand capacity
slice = slice[ : cap(slice)]
growth := (index + 1) - len(slice)
if growth == 1 {
return append(slice, element)
} else {
slice = append(slice, make([]T, growth)...)
slice[index] = element
return slice
}
}
// --- errors ---
const mixedShakerChans = "can't mix shaker.ChanAll with other explicit channels"