-
Notifications
You must be signed in to change notification settings - Fork 4
/
turf.go
200 lines (155 loc) · 4.36 KB
/
turf.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package omp
// #include "include/turf.h"
import "C"
import (
"errors"
"unsafe"
)
type TurfPosition struct {
Min Vector2
Max Vector2
}
type Turf struct {
handle unsafe.Pointer
}
func NewTurf(pos TurfPosition) (*Turf, error) {
cTurf := C.turf_create(C.float(pos.Min.X), C.float(pos.Min.Y), C.float(pos.Max.X), C.float(pos.Max.Y))
if cTurf == nil {
return nil, errors.New("turf limit was reached")
}
return &Turf{handle: cTurf}, nil
}
func FreeTurf(turf *Turf) {
C.turf_release(turf.handle)
}
func EnableTurfCheck(turf *Turf) {
C.turf_useCheck(turf.handle, 1)
}
func DisableTurfCheck(turf *Turf) {
C.turf_useCheck(turf.handle, 0)
}
func (t *Turf) IsShownFor(plr *Player) bool {
return C.turf_isShownForPlayer(t.handle, plr.handle) != 0
}
func (t *Turf) IsFlashingFor(plr *Player) bool {
return C.turf_isFlashingForPlayer(t.handle, plr.handle) != 0
}
func (t *Turf) ShowFor(plr *Player, clr Color) {
C.turf_showForPlayer(t.handle, plr.handle, C.uint(clr))
}
func (t *Turf) ShowForAll(clr Color) {
C.turf_showForAll(t.handle, C.uint(clr))
}
func (t *Turf) HideFor(plr *Player) {
C.turf_hideForPlayer(t.handle, plr.handle)
}
func (t *Turf) HideForAll() {
C.turf_hideForAll(t.handle)
}
func (t *Turf) FlashFor(plr *Player, clr Color) {
C.turf_flashForPlayer(t.handle, plr.handle, C.uint(clr))
}
func (t *Turf) FlashForAll(clr Color) {
C.turf_flashForAll(t.handle, C.uint(clr))
}
func (t *Turf) StopFlashFor(plr *Player) {
C.turf_stopFlashForPlayer(t.handle, plr.handle)
}
func (t *Turf) StopFlashForAll() {
C.turf_stopFlashForAll(t.handle)
}
func (t *Turf) Position() TurfPosition {
cPos := C.turf_getPosition(t.handle)
return TurfPosition{
Min: Vector2{
X: float32(cPos.min.x),
Y: float32(cPos.min.y),
},
Max: Vector2{
X: float32(cPos.max.x),
Y: float32(cPos.max.y),
},
}
}
func (t *Turf) SetPosition(pos TurfPosition) {
C.turf_setPosition(t.handle, C.float(pos.Min.X), C.float(pos.Min.Y), C.float(pos.Max.X), C.float(pos.Max.Y))
}
func (t *Turf) IsPlayerInside(plr *Player) bool {
return C.turf_isPlayerInside(t.handle, plr.handle) != 0
}
func (t *Turf) FlashingColorFor(plr *Player) Color {
return Color(C.turf_getFlashingColourForPlayer(t.handle, plr.handle))
}
func (t *Turf) ColorFor(plr *Player) Color {
return Color(C.turf_getColourForPlayer(t.handle, plr.handle))
}
type PlayerTurf struct {
handle unsafe.Pointer
player *Player
}
func NewPlayerTurf(plr *Player, pos TurfPosition) (*PlayerTurf, error) {
cTurf := C.playerTurf_create(plr.handle, C.float(pos.Min.X), C.float(pos.Min.Y), C.float(pos.Max.X), C.float(pos.Max.Y))
if cTurf == nil {
return nil, errors.New("player turf limit was reached")
}
turf := &PlayerTurf{
handle: cTurf,
player: plr,
}
return turf, nil
}
func FreePlayerTurf(turf *PlayerTurf) {
C.playerTurf_release(turf.handle, turf.player.handle)
}
func EnablePlayerTurfCheck(turf *PlayerTurf) {
C.turf_useCheck(turf.handle, 1)
}
func DisablePlayerTurfCheck(turf *PlayerTurf) {
C.turf_useCheck(turf.handle, 0)
}
func (t *PlayerTurf) Player() *Player {
return t.player
}
func (t *PlayerTurf) IsShown() bool {
return C.turf_isShownForPlayer(t.handle, t.player.handle) != 0
}
func (t *PlayerTurf) IsFlashing() bool {
return C.turf_isFlashingForPlayer(t.handle, t.player.handle) != 0
}
func (t *PlayerTurf) Show(clr Color) {
C.turf_showForPlayer(t.handle, t.player.handle, C.uint(clr))
}
func (t *PlayerTurf) Hide() {
C.turf_hideForPlayer(t.handle, t.player.handle)
}
func (t *PlayerTurf) Flash(clr Color) {
C.turf_flashForPlayer(t.handle, t.player.handle, C.uint(clr))
}
func (t *PlayerTurf) StopFlash() {
C.turf_stopFlashForPlayer(t.handle, t.player.handle)
}
func (t *PlayerTurf) Position() TurfPosition {
cPos := C.turf_getPosition(t.handle)
return TurfPosition{
Min: Vector2{
X: float32(cPos.min.x),
Y: float32(cPos.min.y),
},
Max: Vector2{
X: float32(cPos.max.x),
Y: float32(cPos.max.y),
},
}
}
func (t *PlayerTurf) SetPosition(pos TurfPosition) {
C.turf_setPosition(t.handle, C.float(pos.Min.X), C.float(pos.Min.Y), C.float(pos.Max.X), C.float(pos.Max.Y))
}
func (t *PlayerTurf) IsPlayerInside() bool {
return C.turf_isPlayerInside(t.handle, t.player.handle) != 0
}
func (t *PlayerTurf) FlashingColor() Color {
return Color(C.turf_getFlashingColourForPlayer(t.handle, t.player.handle))
}
func (t *PlayerTurf) Color() Color {
return Color(C.turf_getColourForPlayer(t.handle, t.player.handle))
}