|
@@ -1,8 +1,4 @@
|
|
|
-package main
|
|
|
-
|
|
|
-import (
|
|
|
- "red-green/door"
|
|
|
-)
|
|
|
+package door
|
|
|
|
|
|
type SpinRite struct {
|
|
|
Width uint8 // Width of the animation (must be odd)
|
|
@@ -20,7 +16,7 @@ type SpinRite struct {
|
|
|
|
|
|
func SpinRiteInit(width uint8, length uint8, color string) SpinRite {
|
|
|
if color == "" {
|
|
|
- color = door.ColorText("CYAN ON BLUE")
|
|
|
+ color = ColorText("CYAN ON BLUE")
|
|
|
}
|
|
|
var center uint8 = ((width - 1) / 2)
|
|
|
var start uint8 = ((length - 1) / 2)
|
|
@@ -31,7 +27,7 @@ func SpinRiteInit(width uint8, length uint8, color string) SpinRite {
|
|
|
StartPos: start,
|
|
|
Buffer: make([]uint8, width),
|
|
|
Index: 0}
|
|
|
- if door.Unicode {
|
|
|
+ if Unicode {
|
|
|
result.OutputR = make([]rune, width)
|
|
|
result.Runes = []rune{' ', '\u221e', '\u2580', '\u2584', '\u2588'}
|
|
|
} else {
|
|
@@ -101,7 +97,7 @@ func (sr *SpinRite) Calculate() {
|
|
|
var reset bool = true
|
|
|
|
|
|
// Convert from buffer to output
|
|
|
- if door.Unicode {
|
|
|
+ if Unicode {
|
|
|
for l = 0; l < int8(sr.Width); l++ {
|
|
|
switch sr.Buffer[l] {
|
|
|
case 0:
|
|
@@ -149,7 +145,66 @@ func (sr *SpinRite) Output() string {
|
|
|
var result string
|
|
|
|
|
|
sr.Calculate()
|
|
|
- if door.Unicode {
|
|
|
+ if Unicode {
|
|
|
+ result = string(sr.OutputR)
|
|
|
+ } else {
|
|
|
+ result = string(sr.OutputB)
|
|
|
+ }
|
|
|
+ sr.Index++
|
|
|
+
|
|
|
+ return sr.Color + result
|
|
|
+}
|
|
|
+
|
|
|
+type SpinRiteMsg struct {
|
|
|
+ SpinRite
|
|
|
+ Messages []string
|
|
|
+ MsgIndex int
|
|
|
+ Next bool
|
|
|
+}
|
|
|
+
|
|
|
+func SpinRiteMsgInit(width uint8, length uint8, color string, messages []string) SpinRiteMsg {
|
|
|
+ var result SpinRiteMsg = SpinRiteMsg{SpinRite: SpinRiteInit(width, length, color)}
|
|
|
+ if Unicode {
|
|
|
+ result.Runes[1] = result.Runes[0]
|
|
|
+ } else {
|
|
|
+ result.SpinRite.Bytes[1] = result.SpinRite.Bytes[0]
|
|
|
+ }
|
|
|
+ result.Messages = messages
|
|
|
+ result.MsgIndex = 0
|
|
|
+ result.Next = false
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+func (sr *SpinRiteMsg) Output() string {
|
|
|
+ var result string
|
|
|
+
|
|
|
+ sr.Calculate()
|
|
|
+ if sr.Next && sr.Index == 0 {
|
|
|
+ sr.MsgIndex++
|
|
|
+ if sr.MsgIndex == len(sr.Messages) {
|
|
|
+ sr.MsgIndex = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if sr.Index != 0 {
|
|
|
+ sr.Next = true
|
|
|
+ }
|
|
|
+ // Place message
|
|
|
+ var msg string = sr.Messages[sr.MsgIndex]
|
|
|
+ var pos int = int(sr.CenterPos) - (len(msg) / 2)
|
|
|
+
|
|
|
+ for i := 0; i < len(msg); i++ {
|
|
|
+ if Unicode {
|
|
|
+ if sr.OutputR[pos+i] == ' ' {
|
|
|
+ sr.OutputR[pos+i] = []rune(msg)[i]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if sr.OutputB[pos+i] == ' ' {
|
|
|
+ sr.OutputB[pos+i] = byte(msg[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if Unicode {
|
|
|
result = string(sr.OutputR)
|
|
|
} else {
|
|
|
result = string(sr.OutputB)
|