Skip to content

Commit

Permalink
feat: add buildpower
Browse files Browse the repository at this point in the history
  • Loading branch information
wezzle committed Sep 15, 2024
1 parent 69f4724 commit 93296b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions model/unit_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func NewUnitModel(ref util.UnitRef, mainModel *MainModel) *Unit {
m.health = progress.New(progress.WithSolidFill("#49AE11"), progress.WithoutPercentage())
m.sightRange = progress.New(progress.WithSolidFill("#C6C8C9"), progress.WithoutPercentage())
m.speed = progress.New(progress.WithSolidFill("#1175AE"), progress.WithoutPercentage())
m.buildpower = progress.New(progress.WithSolidFill("#6e17a3"), progress.WithoutPercentage())

return &m
}
Expand All @@ -74,6 +75,7 @@ type Unit struct {
health progress.Model
sightRange progress.Model
speed progress.Model
buildpower progress.Model
}

func (m *Unit) Init() tea.Cmd {
Expand Down Expand Up @@ -144,6 +146,10 @@ func (m *Unit) View() string {
{"Speed", m.speed.ViewAs(m.PercentageWithBaseF(m.properties.Speed, 1.5)), strconv.Itoa(m.properties.SightDistance)},
}

if m.properties.Buildpower != nil {
stats = append(stats, []string{"Buildpower", m.buildpower.ViewAs(m.PercentageWithBase(*m.properties.Buildpower, 3)), strconv.Itoa(*m.properties.Buildpower)})
}

maxLabelWidth := 0
maxValueWidth := 0
for _, stat := range stats {
Expand Down
7 changes: 7 additions & 0 deletions util/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ func LoadUnitProperties(ref UnitRef) (*UnitProperties, error) {
}
speed, _ := strconv.ParseFloat(data.RawGetString("speed").String(), 64)

var workertime *int
if data.RawGetString("workertime").Type() != lua.LTNil {
workertimeVal, _ := strconv.Atoi(data.RawGetString("workertime").String())
workertime = &workertimeVal
}

// Build option slice
bo := data.RawGetString("buildoptions")
var buildOptions []UnitRef
Expand Down Expand Up @@ -221,6 +227,7 @@ func LoadUnitProperties(ref UnitRef) (*UnitProperties, error) {
Health: health,
SightDistance: sightdistance,
Speed: speed,
Buildpower: workertime,
CustomParams: &customParams,
}
unitPropertyCache[ref] = properties
Expand Down
1 change: 1 addition & 0 deletions util/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ type (
Health int
SightDistance int
Speed float64
Buildpower *int
WeaponDefs []WeaponDef
CustomParams *CustomParams
}
Expand Down

0 comments on commit 93296b9

Please sign in to comment.