(promptStr string)
| 85 | } |
| 86 | |
| 87 | func (u *UserRecord) ProcessPromptString(promptStr string) string { |
| 88 | |
| 89 | promptOut := strings.Builder{} |
| 90 | |
| 91 | var currentXP, tnlXP int = -1, -1 |
| 92 | var hpPct, mpPct int = -1, -1 |
| 93 | var hpClass, mpClass string |
| 94 | |
| 95 | promptLen := len(promptStr) |
| 96 | tagStartPos := -1 |
| 97 | |
| 98 | for i := 0; i < promptLen; i++ { |
| 99 | if promptStr[i] == '{' { |
| 100 | tagStartPos = i |
| 101 | continue |
| 102 | } |
| 103 | if promptStr[i] == '}' { |
| 104 | |
| 105 | switch promptStr[tagStartPos : i+1] { |
| 106 | |
| 107 | case `{\n}`: |
| 108 | promptOut.WriteString("\n") |
| 109 | |
| 110 | case `{hp}`: |
| 111 | if len(hpClass) == 0 { |
| 112 | hpClass = fmt.Sprintf(`health-%d`, util.QuantizeTens(u.Character.Health, u.Character.HealthMax.Value)) |
| 113 | } |
| 114 | promptOut.WriteString(fmt.Sprintf(`<ansi fg="%s">%d</ansi>`, hpClass, u.Character.Health)) |
| 115 | |
| 116 | case `{hp:-}`: |
| 117 | promptOut.WriteString(strconv.Itoa(u.Character.Health)) |
| 118 | case `{HP}`: |
| 119 | if len(hpClass) == 0 { |
| 120 | hpClass = fmt.Sprintf(`health-%d`, util.QuantizeTens(u.Character.Health, u.Character.HealthMax.Value)) |
| 121 | } |
| 122 | promptOut.WriteString(fmt.Sprintf(`<ansi fg="%s">%d</ansi>`, hpClass, u.Character.HealthMax.Value)) |
| 123 | case `{HP:-}`: |
| 124 | promptOut.WriteString(strconv.Itoa(u.Character.HealthMax.Value)) |
| 125 | case `{hp%}`: |
| 126 | if hpPct == -1 { |
| 127 | hpPct = int(math.Floor(float64(u.Character.Health) / float64(u.Character.HealthMax.Value) * 100)) |
| 128 | } |
| 129 | if len(hpClass) == 0 { |
| 130 | hpClass = fmt.Sprintf(`health-%d`, util.QuantizeTens(u.Character.Health, u.Character.HealthMax.Value)) |
| 131 | } |
| 132 | promptOut.WriteString(fmt.Sprintf(`<ansi fg="%s">%d%%</ansi>`, hpClass, hpPct)) |
| 133 | |
| 134 | case `{hp%:-}`: |
| 135 | if hpPct == -1 { |
| 136 | hpPct = int(math.Floor(float64(u.Character.Health) / float64(u.Character.HealthMax.Value) * 100)) |
| 137 | } |
| 138 | promptOut.WriteString(strconv.Itoa(hpPct)) |
| 139 | promptOut.WriteString(`%`) |
| 140 | |
| 141 | case `{mp}`: |
| 142 | if len(mpClass) == 0 { |
| 143 | mpClass = fmt.Sprintf(`mana-%d`, util.QuantizeTens(u.Character.Mana, u.Character.ManaMax.Value)) |
| 144 | } |
no test coverage detected