simplify constructing skill container

This commit is contained in:
2026-01-16 23:56:28 -05:00
parent e712263d13
commit 2aebd0144b

View File

@@ -13,53 +13,37 @@ func RenderSkill(id horse.SkillID, all map[horse.SkillID]horse.Skill, groups map
if !ok {
return discord.NewContainer(discord.NewTextDisplayf("invalid skill ID %v made it to RenderSkill", id))
}
skilltype := discord.TextDisplayComponent{
ID: 4,
Content: "Skill Issue",
}
r := discord.ContainerComponent{
ID: 1, // specify ids so we guarantee we don't get collisions with related skill buttons
Components: []discord.ContainerSubComponent{
discord.SectionComponent{
ID: 2,
Components: []discord.SectionSubComponent{
discord.TextDisplayComponent{
ID: 3,
Content: "## " + s.Name + "\n" + s.Description,
},
&skilltype, // doing something evil :)
},
Accessory: discord.NewThumbnail(fmt.Sprintf("https://gametora.com/images/umamusume/skill_icons/utx_ico_skill_%d.png", s.IconID)),
},
},
}
thumburl := fmt.Sprintf("https://gametora.com/images/umamusume/skill_icons/utx_ico_skill_%d.png", s.IconID)
r := discord.NewContainer(discord.NewSection(discord.NewTextDisplayf("## %s\n%s", s.Name, s.Description)).WithAccessory(discord.NewThumbnail(thumburl)))
var skilltype string
switch {
case s.Rarity == 3, s.Rarity == 4, s.Rarity == 5:
// unique of various star levels
r.AccentColor = 0xaca4d4
skilltype.Content = "Unique Skill"
skilltype = "Unique Skill"
case s.Rarity == 2:
// rare (gold)
r.AccentColor = 0xd7c25b
skilltype.Content = "Rare Skill"
skilltype = "Rare Skill"
case s.GroupRate == -1:
// negative (purple) skill
r.AccentColor = 0x9151d4
skilltype.Content = "Negative Skill"
skilltype = "Negative Skill"
case !s.WitCheck:
// should be passive (green)
r.AccentColor = 0x66ae1c
skilltype.Content = "Passive Skill"
skilltype = "Passive Skill"
// TODO(zeph): debuff (red)
case s.Rarity == 1:
// common (white)
r.AccentColor = 0xcccccc
skilltype.Content = "Common Skill"
skilltype = "Common Skill"
}
r.Components = append(r.Components, discord.SeparatorComponent{ID: 5, Spacing: discord.SeparatorSpacingSizeSmall})
r.Components = append(r.Components, discord.NewSmallSeparator())
text := make([]string, 0, 3)
abils := make([]string, 0, 3)
for i, act := range s.Activations {
for _, act := range s.Activations {
text, abils = text[:0], abils[:0]
if act.Precondition != "" {
text = append(text, "Precondition: "+formatCondition(act.Precondition))
@@ -74,7 +58,7 @@ func RenderSkill(id horse.SkillID, all map[horse.SkillID]horse.Skill, groups map
case act.Duration >= 500e4:
t = "Permanent "
default:
t = act.Duration.String() + "s "
t = "For " + act.Duration.String() + "s, "
}
for _, a := range act.Abilities {
abils = append(abils, a.String())
@@ -84,16 +68,9 @@ func RenderSkill(id horse.SkillID, all map[horse.SkillID]horse.Skill, groups map
t += " on " + act.Cooldown.String() + "s cooldown"
}
text = append(text, t)
r.Components = append(r.Components, discord.TextDisplayComponent{
ID: 10 + i,
Content: strings.Join(text, "\n"),
})
r.Components = append(r.Components, discord.NewTextDisplay(strings.Join(text, "\n")))
}
r.Components = append(r.Components, discord.SeparatorComponent{ID: 50, Spacing: discord.SeparatorSpacingSizeSmall})
r.Components = append(r.Components, discord.TextDisplayComponent{
ID: 51,
Content: fmt.Sprintf("SP cost %d. Grade value %d.", s.SPCost, s.GradeValue),
})
r.Components = append(r.Components, discord.NewSmallSeparator(), discord.NewTextDisplayf("%s ・ SP cost %d ・ Grade value %d", skilltype, s.SPCost, s.GradeValue))
rel := make([]horse.Skill, 0, 4)
for _, id := range groups[s.Group] {
if id != 0 {
@@ -103,7 +80,7 @@ func RenderSkill(id horse.SkillID, all map[horse.SkillID]horse.Skill, groups map
if len(rel) > 1 {
buttons := make([]discord.InteractiveComponent, 0, 4)
for _, rs := range rel {
b := discord.NewButton(discord.ButtonStyleSecondary, rs.Name, fmt.Sprintf("/skill/%d", rs.ID), "", 0)
b := discord.NewSecondaryButton(rs.Name, fmt.Sprintf("/skill/%d", rs.ID))
if rs.ID == id {
b = b.AsDisabled()
}