Browse Source

Fixed SpinRiteMsg when msg > Length.

If the message len was > the bars, it would show part.
Now, we fill from the middle.
Steve Thielemann 2 years ago
parent
commit
b73270a4dc
1 changed files with 81 additions and 21 deletions
  1. 81 21
      door/spinrite.go

+ 81 - 21
door/spinrite.go

@@ -14,6 +14,34 @@ type SpinRite struct {
 	Index     uint8   // Index of current iteration
 }
 
+/*
+Other center character options: · ∞
+
+We default to ∞
+
+[    █████    ]
+[   ▄▄███▀▀   ]
+[  ▄▄▄▄█▀▀▀▀  ]
+[ ▄▄▄▄▄•▀▀▀▀▀ ]
+[▄▄▄▄▄ • ▀▀▀▀▀]
+[█▄▄▄  •  ▀▀▀█]
+[██▄   •   ▀██]
+[██▀   •   ▄██]
+[█▀▀▀  •  ▄▄▄█]
+[█▀▀▀▀ • ▄▄▄▄█]
+[ ▀▀▀▀▀•▄▄▄▄▄ ]
+[  ▀▀▀▀█▄▄▄▄  ]
+[   ▀▀███▄▄   ]
+*/
+
+/*
+0 = Blank
+1 = Center Character
+2 = Top
+3 = Bottom
+4 = Full Block
+*/
+
 func SpinRiteInit(width uint8, length uint8, color string) SpinRite {
 	if color == "" {
 		color = ColorText("CYAN ON BLUE")
@@ -190,20 +218,69 @@ func (sr *SpinRiteMsg) Output() string {
 	}
 	// Place message
 	var msg string = sr.Messages[sr.MsgIndex]
-	var pos int = int(sr.CenterPos) - (len(msg) / 2)
+	var pos int = int(sr.CenterPos)
+
+	// Bug:  If we're changing to next message (sr.Next == True) ... but the
+	// message is > SpinRite.Length, it shows the text beyond what it should.
 
-	for i := 0; i < len(msg); i++ {
+	var texthalf int
+	if Unicode {
+		texthalf = len([]rune(msg)) / 2
+	} else {
+		texthalf = len(msg) / 2
+	}
+
+	// Place text center, outwards.  Stopping if there's no space.
+
+	for i := 0; i < texthalf+1; i++ {
 		if Unicode {
 			if sr.OutputR[pos+i] == ' ' {
-				sr.OutputR[pos+i] = []rune(msg)[i]
+				if texthalf+i < len(msg) {
+					sr.OutputR[pos+i] = []rune(msg)[texthalf+i]
+				}
+			} else {
+				break
+			}
+			if i != 0 {
+				if sr.OutputR[pos-i] == ' ' {
+					sr.OutputR[pos-i] = []rune(msg)[texthalf-i]
+				} else {
+					break
+				}
 			}
 		} else {
 			if sr.OutputB[pos+i] == ' ' {
-				sr.OutputB[pos+i] = byte(msg[i])
+				if texthalf+i < len(msg) {
+					sr.OutputB[pos+i] = byte(msg[texthalf+i])
+				}
+			} else {
+				break
+			}
+			if i != 0 {
+				if sr.OutputB[pos-1] == ' ' {
+					sr.OutputB[pos-1] = byte(msg[texthalf-i])
+				} else {
+					break
+				}
+
 			}
 		}
 	}
 
+	/*
+		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 {
@@ -213,20 +290,3 @@ func (sr *SpinRiteMsg) Output() string {
 
 	return sr.Color + result
 }
-
-/*
-Or possibly: · ∞
-[    █████    ]
-[   ▄▄███▀▀   ]
-[  ▄▄▄▄█▀▀▀▀  ]
-[ ▄▄▄▄▄•▀▀▀▀▀ ]
-[▄▄▄▄▄ • ▀▀▀▀▀]
-[█▄▄▄  •  ▀▀▀█]
-[██▄   •   ▀██]
-[██▀   •   ▄██]
-[█▀▀▀  •  ▄▄▄█]
-[█▀▀▀▀ • ▄▄▄▄█]
-[ ▀▀▀▀▀•▄▄▄▄▄ ]
-[  ▀▀▀▀█▄▄▄▄  ]
-[   ▀▀███▄▄   ]
-*/