-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy patheventlog.go
99 lines (78 loc) · 1.94 KB
/
eventlog.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
package main
import (
"fmt"
"log"
"time"
"github.com/tanema/gween"
"github.com/tanema/gween/ease"
)
type Event struct {
Text string
Time string
Multiplier int
Y float32
Tween *gween.Sequence
}
func (event *Event) Done() bool {
_, _, done := event.Tween.Update(0)
return done
}
type EventLog struct {
On bool
Events []*Event
}
func NewEventLog() *EventLog {
return &EventLog{Events: []*Event{}, On: true}
}
func (eventLog *EventLog) Log(text string, force bool, variables ...interface{}) {
if !force && (!eventLog.On || !globals.Settings.Get(SettingsDisplayMessages).AsBool()) {
return
}
output := text
if len(variables) > 0 {
output = fmt.Sprintf(text, variables...)
}
var pastEvent *Event
if len(eventLog.Events) > 0 {
if pe := eventLog.Events[len(eventLog.Events)-1]; pe.Text == output {
pastEvent = pe
if pastEvent.Tween.Index() >= 1 {
pastEvent.Tween.SetIndex(1)
pastEvent.Tween.Tweens[pastEvent.Tween.Index()].Reset()
}
pastEvent.Multiplier++
}
}
// Log the event so that it goes to the log file in addition to the messages at the bottom-left
log.Println(output)
if pastEvent == nil {
eventLog.Events = append(eventLog.Events, &Event{
Text: output,
Time: time.Now().Format("15:04:05"),
Tween: gween.NewSequence(
gween.New(0, 1, 0.5, ease.Linear),
gween.New(1, 1, float32(len(output))*0.05, ease.Linear),
gween.New(1, 0, 0.5, ease.Linear),
),
// Texture: globals.TextRenderer.RenderText(output, Point{}, AlignLeft),
Y: globals.ScreenSize.Y,
})
}
}
func (eventLog *EventLog) CleanUpDeadEvents() {
events := append([]*Event{}, eventLog.Events...)
for _, e := range events {
if e.Done() {
eventLog.Remove(e)
}
}
}
func (eventLog *EventLog) Remove(event *Event) {
for i, e := range eventLog.Events {
if e == event {
eventLog.Events[i] = nil
eventLog.Events = append(eventLog.Events[:i], eventLog.Events[i+1:]...)
return
}
}
}