@@ -505,7 +505,7 @@ type TooltipAST struct {
505505 Values * []ComplexValue `parser:"@@*"`
506506}
507507
508- var ternParser = regexp .MustCompile (`^\$(\d*)([gl ])(.+):$` )
508+ var ternParser = regexp .MustCompile (`^\$(\d*)([glLG ])(.+):$` )
509509
510510func (d DescriptionRef ) String (ctx * TooltipContext ) string {
511511 desc := ctx .DataProvider .GetSpellDescription (d .SpellId )
@@ -545,12 +545,16 @@ func (s ShortTernary) String(ctx *TooltipContext) string {
545545 t := match [2 ]
546546 left := match [3 ]
547547 switch t {
548+ case "G" :
549+ fallthrough
548550 case "g" :
549551 if ctx .DataProvider .IsMaleGender () {
550552 return left
551553 }
552554
553555 return s .Right
556+ case "L" :
557+ fallthrough
554558 case "l" :
555559 if ctx .LastEval <= 1 {
556560 return left
@@ -635,7 +639,7 @@ func (s SimpleSpellValue) Eval(ctx *TooltipContext) float64 {
635639 case "h" :
636640 return ctx .DataProvider .GetSpellProcChance (s .getSpellId (ctx ))
637641 case "d" :
638- return float64 (ctx .DataProvider .GetSpellDuration (s .getSpellId (ctx )))
642+ return float64 (ctx .DataProvider .GetSpellDuration (s .getSpellId (ctx ))) / float64 ( time . Second )
639643 case "w" :
640644 // This does not properly evaluate in client for Spell Descriptions. In theory it seems to refer to the specific extra values of a buff
641645 // i.E. the actual stamina buffed by a priester to display it correctly client side
@@ -713,7 +717,15 @@ func (s SimpleSpellValue) String(ctx *TooltipContext) string {
713717 case "D" :
714718 fallthrough
715719 case "d" :
720+ // value is returned in seconds, normalize to time value
721+ value *= float64 (time .Second )
716722 duration := time .Duration (value )
723+ if value > float64 (time .Hour * 2 ) {
724+ return fmt .Sprintf ("%dhrs" , duration / time .Hour )
725+ }
726+ if value >= float64 (time .Hour ) {
727+ return fmt .Sprintf ("%dhr" , duration / time .Hour )
728+ }
717729 if value >= float64 (time .Minute ) {
718730 return fmt .Sprintf ("%dmin" , duration / time .Minute )
719731 }
@@ -883,10 +895,12 @@ var fixes = []tooltipFix{
883895 {Regex : regexp .MustCompile (`\(\<\$` ), Replace : "($<" },
884896 {Regex : regexp .MustCompile (`,\<\$` ), Replace : ",$<" },
885897 {Regex : regexp .MustCompile (`\]\]` ), Replace : "]" },
886- {Regex : regexp .MustCompile (`\$[bB]([^\d])` ), Replace : "\n $1 " },
898+ {Regex : regexp .MustCompile (`(.) \$[bB]([^\d])` ), Replace : "$1 \n $2 " },
887899 {Regex : regexp .MustCompile (`\)\r\n\[` ), Replace : ")[" },
888900 {Regex : regexp .MustCompile (`\]\$\[` ), Replace : "][" },
889901 {Regex : regexp .MustCompile (`\{(\d+[a-zA-Z]\d)` ), Replace : "{$$$1" },
902+ {Regex : regexp .MustCompile (`(\$\?[^\[$]+)\$\?` ), Replace : "$1" },
903+ {Regex : regexp .MustCompile (`([\(|&?][ap]\d+)[a-z]\d` ), Replace : "$1" },
890904}
891905
892906func applyFixes (tooltip string ) string {
@@ -900,6 +914,7 @@ func applyFixes(tooltip string) string {
900914func getLexer () * lexer.StatefulDefinition {
901915 return lexer .MustStateful (lexer.Rules {
902916 "Root" : {
917+ {Name : "CommentStart" , Pattern : `--` , Action : lexer .Push ("Comment" )},
903918 {Name : "TernStart" , Pattern : `(\$|\])\?` , Action : lexer .Push ("Ternary" )},
904919 {Name : "DescLookup" , Pattern : `\$@(spelldesc|spelltooltip)` , Action : nil },
905920 {Name : "SpellLookup" , Pattern : `\$@spellname` , Action : nil },
@@ -910,6 +925,9 @@ func getLexer() *lexer.StatefulDefinition {
910925 {Name : "Punct" , Pattern : `[.,:\!?%;\]\r\n]` },
911926 {Name : "SpellCond2" , Pattern : `\?[aspc]\d{2,}` , Action : nil },
912927 },
928+ "Comment" : {
929+ {Name : "Comment" , Pattern : ".+?\n " , Action : lexer .Pop ()},
930+ },
913931 "Boolean" : {
914932 {Name : "BEND" , Pattern : `\)` , Action : nil },
915933 {Name : "BSTART" , Pattern : `\(` , Action : nil },
@@ -927,7 +945,7 @@ func getLexer() *lexer.StatefulDefinition {
927945 "Shared" : {
928946 {Name : `Whitespace` , Pattern : `[ \t]+` , Action : nil },
929947 {Name : "MathStart" , Pattern : `\$\{` , Action : lexer .Push ("Math" )},
930- {Name : "ShortTern" , Pattern : `\$\d*[lg ][a-zA-Z0-9 ]+:` , Action : lexer .Push ("ShortTern" )},
948+ {Name : "ShortTern" , Pattern : `\$\d*[lgLG ][a-zA-Z0-9 ]+:` , Action : lexer .Push ("ShortTern" )},
931949 {Name : "Float" , Pattern : `-?(\d+)?\.\d+` , Action : nil },
932950 {Name : "Int" , Pattern : `-?\d+` , Action : nil },
933951 {Name : "VarRef" , Pattern : `\$\<` , Action : lexer .Push ("VarRef" )},
@@ -978,7 +996,7 @@ func (t Tooltip) String() string {
978996
979997func ParseTooltip (tooltip string , dataProvider TooltipDataProvider , spellId int64 ) (* Tooltip , error ) {
980998 def := getLexer ()
981- parser , error := participle .Build [TooltipAST ](participle .Lexer (def ), participle .Elide ("Whitespace" ), participle .UseLookahead (- 1 ))
999+ parser , error := participle .Build [TooltipAST ](participle .Lexer (def ), participle .Elide ("Whitespace" , "Comment" , "CommentStart" ), participle .UseLookahead (- 1 ))
9821000 if error != nil {
9831001 panic (error )
9841002 }
0 commit comments