-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.go
59 lines (46 loc) · 1.15 KB
/
env.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
package spin
import (
"time"
"github.com/drop-target-pinball/coroutine"
)
type ScriptEnv struct {
Config Config
eng *Engine
co *coroutine.C
}
func newScriptEnv(eng *Engine, co *coroutine.C) *ScriptEnv {
return &ScriptEnv{
Config: eng.Config,
eng: eng,
co: co,
}
}
func (e *ScriptEnv) Do(act Action) {
e.eng.Do(act)
}
func (e *ScriptEnv) Post(evt Event) {
e.eng.Post(evt)
}
func (e *ScriptEnv) Sleep(ms int) bool {
return e.co.Sleep(time.Duration(ms) * time.Millisecond)
}
func (e *ScriptEnv) WaitFor(events ...coroutine.Event) (coroutine.Event, bool) {
return e.co.WaitFor(events...)
}
func (e *ScriptEnv) WaitForUntil(ms int, s ...coroutine.Event) (coroutine.Event, bool) {
return e.co.WaitForUntil(time.Duration(ms)*time.Millisecond, s...)
}
func (e *ScriptEnv) Display(id string) Display {
return e.eng.Display(id)
}
func (e *ScriptEnv) NewCoroutine(fn ScriptFn) {
e.co.New(func(co *coroutine.C) {
fn(newScriptEnv(e.eng, co))
})
}
func (e *ScriptEnv) RegisterVars(name string, vars interface{}) {
e.eng.RegisterVars(name, vars)
}
func (e *ScriptEnv) GetVars(name string) (interface{}, bool) {
return e.eng.GetVars(name)
}