Skip to content

Commit

Permalink
Merge branch 'refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
moxar committed Jan 1, 2016
2 parents f70bff4 + b37eff4 commit b79b7af
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 69 deletions.
5 changes: 5 additions & 0 deletions aptitude.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ func (a Aptitude) Apply(character *Character, upgrade Upgrade) error {
}
return nil
}

// DefaultName returns the default upgrade name.
func (a Aptitude) DefaultName() string {
return string(a)
}
129 changes: 63 additions & 66 deletions character.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,60 +210,73 @@ func (c *Character) Print() {
}

// Print the gauges
fmt.Printf("\n%s\n", theme.Title("Gauges"))

gauges := []Gauge{}
for _, gauge := range c.Gauges {
gauges = append(gauges, gauge)
}
if len(c.Gauges) != 0 {

slice.Sort(gauges, func(i, j int) bool {
return gauges[i].Name < gauges[j].Name
})
fmt.Printf("\n%s\n", theme.Title("Gauges"))

for _, gauge := range gauges {
fmt.Printf("%s\t%s\n", gauge.Name, theme.Value(gauge.Value))
}
gauges := []Gauge{}
for _, gauge := range c.Gauges {
gauges = append(gauges, gauge)
}

// Print the skills using a tabwriter
fmt.Printf("\n%s\n", theme.Title("Skills"))
slice.Sort(gauges, func(i, j int) bool {
return gauges[i].Name < gauges[j].Name
})

skills := []Skill{}
for _, skill := range c.Skills {
skills = append(skills, skill)
for _, gauge := range gauges {
fmt.Printf("%s\t%s\n", gauge.Name, theme.Value(gauge.Value))
}
}

slice.Sort(skills, func(i, j int) bool {
return skills[i].FullName() < skills[j].FullName()
})
// Print the skills

w := tabwriter.NewWriter(os.Stdout, 10, 1, 2, ' ', 0)
for _, skill := range skills {
fmt.Fprintf(w, "%s\t+%s\n", strings.Title(skill.FullName()), theme.Value((skill.Tier-1)*10))
if len(c.Skills) != 0 {

// Print the skills using a tabwriter
fmt.Printf("\n%s\n", theme.Title("Skills"))

skills := []Skill{}
for _, skill := range c.Skills {
skills = append(skills, skill)
}

slice.Sort(skills, func(i, j int) bool {
return skills[i].FullName() < skills[j].FullName()
})

w := tabwriter.NewWriter(os.Stdout, 10, 1, 2, ' ', 0)
for _, skill := range skills {
fmt.Fprintf(w, "%s\t+%s\n", strings.Title(skill.FullName()), theme.Value((skill.Tier-1)*10))
}
w.Flush()
}
w.Flush()

// Print the talents
fmt.Printf("\n%s\n", theme.Title("Talents"))

talents := []Talent{}
for _, talent := range c.Talents {
talents = append(talents, talent)
}
if len(c.Talents) != 0 {

slice.Sort(talents, func(i, j int) bool {
return talents[i].FullName() < talents[j].FullName()
})
fmt.Printf("\n%s\n", theme.Title("Talents"))

w = tabwriter.NewWriter(os.Stdout, 10, 1, 2, ' ', 0)
for _, talent := range talents {
if talent.Value != 1 {
fmt.Fprintf(w, "%s (%d)\t%s\n", strings.Title(talent.FullName()), talent.Value, talent.Description)
} else {
fmt.Fprintf(w, "%s\t%s\n", strings.Title(talent.FullName()), talent.Description)
talents := []Talent{}
for _, talent := range c.Talents {
talents = append(talents, talent)
}

slice.Sort(talents, func(i, j int) bool {
return talents[i].FullName() < talents[j].FullName()
})

w := tabwriter.NewWriter(os.Stdout, 10, 1, 2, ' ', 0)
for _, talent := range talents {
if talent.Value != 1 {
fmt.Fprintf(w, "%s (%d)\t%s\n", strings.Title(talent.FullName()), talent.Value, talent.Description)
} else {
fmt.Fprintf(w, "%s\t%s\n", strings.Title(talent.FullName()), talent.Description)
}
}
w.Flush()
}
w.Flush()

// Print the spells

Expand All @@ -281,6 +294,7 @@ func (c *Character) Print() {
return spells[i].Name < spells[j].Name
})

w := tabwriter.NewWriter(os.Stdout, 10, 1, 2, ' ', 0)
for _, spell := range spells {
fmt.Fprintf(w, "%s\t%s\n", strings.Title(spell.Name), spell.Description)
}
Expand All @@ -302,6 +316,7 @@ func (c *Character) Print() {
return rules[i].Name < rules[j].Name
})

w := tabwriter.NewWriter(os.Stdout, 10, 1, 2, ' ', 0)
for _, rule := range rules {
fmt.Printf("%s\t%s\n", strings.Title(rule.Name), rule.Description)
}
Expand Down Expand Up @@ -332,7 +347,7 @@ func (c *Character) PrintHistory() {
}

// Suggest the next purchasable upgrades of the character.
func (c *Character) Suggest(max int, all bool) {
func (c *Character) Suggest(max int, all bool, allowSpells bool) {

// Aggregate each coster into a unique slice of costers.
costers := []Coster{}
Expand All @@ -348,15 +363,18 @@ func (c *Character) Suggest(max int, all bool) {
costers = append(costers, upgrade)
}

for _, upgrade := range universe.Spells {
costers = append(costers, upgrade)
}

for _, upgrade := range universe.Gauges {
upgrade.Value = 1
costers = append(costers, upgrade)
}

if allowSpells {

for _, upgrade := range universe.Spells {
costers = append(costers, upgrade)
}
}

// Default max value equals to the remaining XP.
if max == 0 {
max = c.Experience - c.Spent
Expand Down Expand Up @@ -387,30 +405,9 @@ func (c *Character) Suggest(max int, all bool) {

upgrade.Cost = &cost
upgrade.Mark = MarkApply
upgrade.Name = coster.DefaultName()

switch t := coster.(type) {

case Characteristic:
upgrade.Name = fmt.Sprintf("%s +%d", t.Name, 5)
err = t.Apply(c, upgrade)

case Skill:
upgrade.Name = fmt.Sprintf("%s", t.Name)
err = t.Apply(c, upgrade)

case Talent:
upgrade.Name = fmt.Sprintf("%s", t.Name)
err = t.Apply(c, upgrade)

case Spell:
upgrade.Name = fmt.Sprintf("%s", t.Name)
err = t.Apply(c, upgrade)

case Gauge:
upgrade.Name = fmt.Sprintf("%s +%d", t.Name, 1)
err = t.Apply(c, upgrade)
}

err = coster.Apply(c, upgrade)
if err != nil {
continue
}
Expand Down
6 changes: 6 additions & 0 deletions characteristic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"strconv"
"strings"
)
Expand Down Expand Up @@ -85,3 +86,8 @@ func (c Characteristic) Apply(character *Character, upgrade Upgrade) error {

return nil
}

// DefaultName returns the default upgrade name.
func (c Characteristic) DefaultName() string {
return fmt.Sprintf("%s +%d", c.Name, 5)
}
2 changes: 2 additions & 0 deletions coster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ type Coster interface {

// TODO: rename the interface
Apply(*Character, Upgrade) error

DefaultName() string
}
6 changes: 6 additions & 0 deletions gauge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"strconv"
"strings"
)
Expand Down Expand Up @@ -51,3 +52,8 @@ func (g Gauge) Apply(character *Character, upgrade Upgrade) error {

return nil
}

// DefaultName returns the default upgrade name.
func (g Gauge) DefaultName() string {
return fmt.Sprintf("%s +%d", g.Name, 1)
}
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ func main() {
Usage: "display the list of purchasable upgrades, ordered by cost",
Flags: []cli.Flag{
cli.IntFlag{
Name: "max",
Name: "max,m",
Usage: "maximum XP cost of the upgrades to suggest",
},
cli.BoolFlag{
Name: "all",
Name: "all,a",
Usage: "display all upgrades regardless of their costs",
},
cli.BoolFlag{
Name: "with-spells,s",
Usage: "display spells along with other upgrades",
},
},
Action: func(ctx *cli.Context) {
character.Suggest(ctx.Int("max"), ctx.Bool("all"))
character.Suggest(ctx.Int("max"), ctx.Bool("all"), ctx.Bool("with-spells"))
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ func (r Rule) Apply(character *Character, upgrade Upgrade) error {

return nil
}

// DefaultName returns the default upgrade name.
func (r Rule) DefaultName() string {
return r.Name
}
5 changes: 5 additions & 0 deletions skill.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ func (s Skill) Apply(character *Character, upgrade Upgrade) error {

return nil
}

// DefaultName returns the default upgrade name.
func (s Skill) DefaultName() string {
return s.FullName()
}
5 changes: 5 additions & 0 deletions spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ func (s *Spell) UnmarshalJSON(raw []byte) error {

return nil
}

// DefaultName returns the default upgrade name.
func (s Spell) DefaultName() string {
return s.Name
}
5 changes: 5 additions & 0 deletions talent.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ func (t Talent) Apply(character *Character, upgrade Upgrade) error {

return nil
}

// DefaultName returns the default upgrade name.
func (t Talent) DefaultName() string {
return t.FullName()
}

0 comments on commit b79b7af

Please sign in to comment.