-
Notifications
You must be signed in to change notification settings - Fork 7
/
TileCoordinates.go
48 lines (41 loc) · 1.14 KB
/
TileCoordinates.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
package levels
import (
"github.com/inkyblackness/hacked/editor/event"
)
type tileCoordinates struct {
list []MapPosition
}
func (coords tileCoordinates) contains(pos MapPosition) bool {
for _, entry := range coords.list {
if entry == pos {
return true
}
}
return false
}
func (coords *tileCoordinates) registerAt(registry event.Registry) {
registry.RegisterHandler(coords.onTileSelectionSetEvent)
registry.RegisterHandler(coords.onTileSelectionAddEvent)
registry.RegisterHandler(coords.onTileSelectionRemoveEvent)
}
func (coords *tileCoordinates) onTileSelectionSetEvent(evt TileSelectionSetEvent) {
coords.list = evt.tiles
}
func (coords *tileCoordinates) onTileSelectionAddEvent(evt TileSelectionAddEvent) {
coords.list = append(coords.list, evt.tiles...)
}
func (coords *tileCoordinates) onTileSelectionRemoveEvent(evt TileSelectionRemoveEvent) {
newList := make([]MapPosition, 0, len(coords.list))
for _, oldEntry := range coords.list {
keep := true
for _, removedEntry := range evt.tiles {
if oldEntry == removedEntry {
keep = false
}
}
if keep {
newList = append(newList, oldEntry)
}
}
coords.list = newList
}