Skip to content

Commit f1a9109

Browse files
author
Marcel Ellermann
committed
[Tooltip] Add comment parsing and improve some time parsing
1 parent ce9bf41 commit f1a9109

4 files changed

Lines changed: 107 additions & 7 deletions

File tree

tools/tooltip/tooltip_parser.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

510510
func (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

892906
func applyFixes(tooltip string) string {
@@ -900,6 +914,7 @@ func applyFixes(tooltip string) string {
900914
func 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

979997
func 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
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package tooltip
2+
3+
import (
4+
"testing"
5+
6+
"github.com/wowsims/mop/tools/database/dbc"
7+
)
8+
9+
var db = dbc.GetDBC()
10+
11+
func Test_WhenInvalidTernaryGiven_ThenProperlyApplyFixes(t *testing.T) {
12+
tp, error := ParseTooltip("$<dam> damage every ${$16914d3/10}.2 seconds$?$w1!=0[ and movement slowed by $w1%][].",
13+
NewTestDataProvider(CharacterConfig{SpellPower: 1000}),
14+
16914,
15+
)
16+
17+
if error != nil {
18+
t.Fatal()
19+
}
20+
21+
if _, ok := tp.Context.Variables["dam"]; !ok {
22+
t.Fail()
23+
}
24+
25+
if tp.String() != "6624 damage every 1.00 seconds." {
26+
t.Fail()
27+
}
28+
}
29+
30+
func Test_WhenLConditionGiven_ThenProperlyEvaluate(t *testing.T) {
31+
SimpleTooltipTest(55685, "The first charge of your Prayer of Mending heals for an additional 60% but your Prayer of Mending has 1 fewer charge.", t)
32+
}
33+
34+
func Test_WhenGivenDurationShorter60_ThenRenderSeconds(t *testing.T) {
35+
SimpleTooltipTest(54810,
36+
"For 6s after activating Frenzied Regeneration, healing effects on you are 40% more powerful. However, your Frenzied Regeneration now always costs 50 Rage and no longer converts Rage into health.",
37+
t,
38+
)
39+
}
40+
41+
func Test_WhenGivenDurationLongerThan2Hours_ThenRnderHrs(t *testing.T) {
42+
SimpleTooltipTest(56382, "When cast on critters, your Polymorph spells now last 24hrs and can be cast on multiple targets.", t)
43+
}
44+
45+
func SimpleTooltipTest(spellId int, expectedDescription string, t *testing.T) {
46+
spell := db.Spells[spellId]
47+
tp, error := ParseTooltip(spell.Description,
48+
NewTestDataProvider(CharacterConfig{}),
49+
int64(spellId),
50+
)
51+
52+
if error != nil {
53+
t.Fatal()
54+
}
55+
56+
if tp.String() != expectedDescription {
57+
t.Fail()
58+
}
59+
}
60+
61+
func NewTestDataProvider(config CharacterConfig) *TestDataProvider {
62+
return &TestDataProvider{
63+
DBCTooltipDataProvider: &DBCTooltipDataProvider{
64+
DBC: db,
65+
},
66+
Character: &config,
67+
}
68+
}
69+
70+
// add here over time to overwrite fixed values for tests
71+
type CharacterConfig struct {
72+
SpellPower float64
73+
}
74+
75+
type TestDataProvider struct {
76+
*DBCTooltipDataProvider
77+
Character *CharacterConfig
78+
}
79+
80+
func (t TestDataProvider) GetSpellPower() float64 {
81+
return t.Character.SpellPower
82+
}

ui/core/talents/mage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const mageGlyphsConfig: GlyphsConfig = {
129129
},
130130
[MageMinorGlyph.GlyphOfCrittermorph]: {
131131
name: "Glyph of Crittermorph",
132-
description: "When cast on critters, your Polymorph spells now last 1440min and can be cast on multiple targets.",
132+
description: "When cast on critters, your Polymorph spells now last 24hrs and can be cast on multiple targets.",
133133
iconUrl: "https://wow.zamimg.com/images/wow/icons/large/spell_nature_doublepolymorph2.jpg",
134134
},
135135
[MageMinorGlyph.GlyphOfThePorcupine]: {

ui/core/talents/priest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const priestGlyphsConfig: GlyphsConfig = {
107107
},
108108
[PriestMajorGlyph.GlyphOfPrayerOfMending]: {
109109
name: "Glyph of Prayer of Mending",
110-
description: "The first charge of your Prayer of Mending heals for an additional 100% but your Prayer of Mending has 1 fewer 0: charges;.",
110+
description: "The first charge of your Prayer of Mending heals for an additional 60% but your Prayer of Mending has 1 fewer charge.",
111111
iconUrl: "https://wow.zamimg.com/images/wow/icons/large/spell_holy_prayerofmendingtga.jpg",
112112
},
113113
[PriestMajorGlyph.GlyphOfLevitate]: {

0 commit comments

Comments
 (0)