Skip to content

Commit

Permalink
refactor: move filtering logic to configs
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Apr 7, 2024
1 parent 6bd2302 commit e87a501
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 61 deletions.
2 changes: 1 addition & 1 deletion darkstat/front/engines.templ
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ templ Engines(engines []configs_export.Engine, mode ShowEmpty) {
>
<td>{ engine.Name }</td>
<td>{ strconv.Itoa(engine.Price) } </td>
<td>{ strconv.FormatBool(Buyable(engine.Bases)) }</td>
<td>{ strconv.FormatBool(configs_export.Buyable(engine.Bases)) }</td>
<td>{ fmt.Sprintf("%.2f",engine.ImpulseSpeed) } </td>
<td>{ strconv.Itoa(engine.CruiseSpeed) }</td>
<td>{ engine.HpType }</td>
Expand Down
2 changes: 1 addition & 1 deletion darkstat/front/guns.templ
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ templ GunsT(guns []configs_export.Gun, mode GunTabMode, mode2 ShowEmpty) {
<td>{ gun.Type }</td>
<td>{ gun.DamageType }</td>
<td>{ strconv.Itoa(gun.Price) } </td>
<td>{ strconv.FormatBool(Buyable(gun.Bases)) }</td>
<td>{ strconv.FormatBool(configs_export.Buyable(gun.Bases)) }</td>
<td>{ strconv.Itoa(gun.HullDamage) }</td>
<td>{ strconv.Itoa(gun.ShieldDamage) }</td>
<td>{ fmt.Sprintf("%.2f", gun.PowerUsage) }</td>
Expand Down
2 changes: 1 addition & 1 deletion darkstat/front/mines.templ
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ templ MinesT(mines []configs_export.Mine, mode2 ShowEmpty) {
>
<td>{ mine.Name }</td>
<td>{ strconv.Itoa(mine.Price) } </td>
<td>{ strconv.FormatBool(Buyable(mine.Bases)) }</td>
<td>{ strconv.FormatBool(configs_export.Buyable(mine.Bases)) }</td>
<td>{ strconv.Itoa(mine.AmmoPrice) } </td>
<td>{ strconv.Itoa(mine.HullDamage) }</td>
<td>{ strconv.Itoa(mine.ShieldDamage) }</td>
Expand Down
19 changes: 0 additions & 19 deletions darkstat/front/shared.templ
Original file line number Diff line number Diff line change
Expand Up @@ -281,25 +281,6 @@ templ GoodAtBaseInfoT(base_infos []configs_export.GoodAtBase, show_price_per_vol
}
}

func Buyable(Bases []configs_export.GoodAtBase) bool {
for _, base := range Bases {
if !strings.Contains(base.SystemName, "Bastille") {
return true
}
}

return false
}

func Empty(phrase string) bool {
for _, letter := range phrase {
if letter != ' ' {
return false
}
}
return true
}

func AllItemsUrl(url utils_types.FilePath) utils_types.FilePath {
return "all_" + url
}
Expand Down
2 changes: 1 addition & 1 deletion darkstat/front/shields.templ
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ templ ShieldT(shields []configs_export.Shield,mode2 ShowEmpty) {
<td>{ shield.Type }</td>
<td>{ shield.Technology }</td>
<td>{ strconv.Itoa(shield.Price) } </td>
<td>{ strconv.FormatBool(Buyable(shield.Bases)) }</td>
<td>{ strconv.FormatBool(configs_export.Buyable(shield.Bases)) }</td>
<td>{ strconv.Itoa(shield.Capacity) } </td>
<td>{ strconv.Itoa(shield.RegenerationRate) }</td>
<td>{ strconv.Itoa(shield.ConstantPowerDraw) }</td>
Expand Down
2 changes: 1 addition & 1 deletion darkstat/front/ships.templ
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ templ ShipsT(ships []configs_export.Ship, mode ShipTabMode, mode2 ShowEmpty) {
<td>{ strconv.Itoa(ship.Class) }</td>
<td>{ ship.Type }</td>
<td>{ strconv.Itoa(ship.Price) }</td>
<td>{ strconv.FormatBool(Buyable(ship.Bases)) }</td>
<td>{ strconv.FormatBool(configs_export.Buyable(ship.Bases)) }</td>
<td>{ strconv.Itoa(ship.Armor) } </td>
<td>{ strconv.Itoa(ship.HoldSize) } </td>
<td>{ strconv.Itoa(ship.Nanobots) }</td>
Expand Down
2 changes: 1 addition & 1 deletion darkstat/front/thrusters.templ
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ templ ThrusterT(thrusters []configs_export.Thruster, mode2 ShowEmpty) {
>
<td>{ thruster.Name }</td>
<td>{ strconv.Itoa(thruster.Price) } </td>
<td>{ strconv.FormatBool(Buyable(thruster.Bases)) }</td>
<td>{ strconv.FormatBool(configs_export.Buyable(thruster.Bases)) }</td>
<td>{ strconv.Itoa(thruster.MaxForce) } </td>
<td>{ strconv.Itoa(thruster.PowerUsage) }</td>
<td>{ fmt.Sprintf("%.2f",thruster.Efficiency) }</td>
Expand Down
2 changes: 1 addition & 1 deletion darkstat/front/tractors.templ
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ templ TractorsT(tractors []configs_export.Tractor, mode2 ShowEmpty) {
>
<td>{ tractor.Name }</td>
<td>{ strconv.Itoa(tractor.Price) } </td>
<td>{ strconv.FormatBool(Buyable(tractor.Bases)) }</td>
<td>{ strconv.FormatBool(configs_export.Buyable(tractor.Bases)) }</td>
<td>{ strconv.Itoa(tractor.MaxLength) } </td>
<td>{ strconv.Itoa(tractor.ReachSpeed) }</td>
<td>{ strconv.FormatBool(tractor.Lootable) }</td>
Expand Down
38 changes: 4 additions & 34 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ into stuff rendered by fl-darkstat

import (
"sort"
"strings"

"github.com/darklab8/fl-configs/configs/configs_export"
"github.com/darklab8/fl-configs/configs/configs_mapped"
Expand Down Expand Up @@ -201,45 +200,16 @@ func (l *Linker) Link() *builder.Builder {

build := builder.NewBuilder()

var useful_bases []configs_export.Base = make([]configs_export.Base, 0, len(data.Bases))
for _, item := range data.Bases {
if item.Name == "" {
continue
}
useful_bases = append(useful_bases, item)
}

var useful_factions []configs_export.Faction = make([]configs_export.Faction, 0, len(data.Factions))
for _, item := range data.Factions {
if front.Empty(item.Name) || strings.Contains(item.Name, "_grp") {
continue
}
useful_factions = append(useful_factions, item)
}
useful_factions := configs_export.FilterToUsefulFactions(data.Factions)

var buyable_tractors []configs_export.Tractor = make([]configs_export.Tractor, 0, len(data.Tractors))
for _, item := range data.Tractors {
if !front.Buyable(item.Bases) {
continue
}
buyable_tractors = append(buyable_tractors, item)
}

var buyable_engines []configs_export.Engine = make([]configs_export.Engine, 0, len(data.Engines))
for _, engine := range data.Engines {
if !front.Buyable(engine.Bases) {
continue
}
buyable_engines = append(buyable_engines, engine)
}
build.RegComps(
builder.NewComponent(
urls.Index,
front.Index(),
),
builder.NewComponent(
urls.Bases,
front.BasesT(useful_bases, front.ShowEmpty(false)),
front.BasesT(configs_export.FilterToUserfulBases(data.Bases), front.ShowEmpty(false)),
),
builder.NewComponent(
front.AllItemsUrl(urls.Bases),
Expand Down Expand Up @@ -335,15 +305,15 @@ func (l *Linker) Link() *builder.Builder {
),
builder.NewComponent(
urls.Tractors,
front.TractorsT(buyable_tractors, front.ShowEmpty(false)),
front.TractorsT(configs_export.FilterToUsefulTractors(data.Tractors), front.ShowEmpty(false)),
),
builder.NewComponent(
front.AllItemsUrl(urls.Tractors),
front.TractorsT(data.Tractors, front.ShowEmpty(true)),
),
builder.NewComponent(
urls.Engines,
front.Engines(buyable_engines, front.ShowEmpty(false)),
front.Engines(configs_export.FilterToUsefulEngines(data.Engines), front.ShowEmpty(false)),
),
builder.NewComponent(
front.AllItemsUrl(urls.Engines),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.1

require (
github.com/a-h/templ v0.2.543
github.com/darklab8/fl-configs v0.32.0
github.com/darklab8/fl-configs v0.33.0
github.com/darklab8/go-typelog v0.6.0
github.com/darklab8/go-utils v0.13.0
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ github.com/darklab8/fl-configs v0.31.0 h1:BGdFUj6lqj7FdRYq4HKu/YETGWPCOLDpR1gExi
github.com/darklab8/fl-configs v0.31.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.32.0 h1:HsmWxf+CQvmOVmesPXqIMze/UXmh01jXZwcxXmkRi3w=
github.com/darklab8/fl-configs v0.32.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.33.0 h1:gcxBl11SbtUsuLLeuyno9DyRJavXT5XPBQLcloykCsM=
github.com/darklab8/fl-configs v0.33.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/go-typelog v0.6.0 h1:Ci8imc7ScXiy5e1qMgf46NyJjrqNLPoIE1gbVe7bxl4=
github.com/darklab8/go-typelog v0.6.0/go.mod h1:AwwOf3dkp/tpevHFNbkB+PbwlDrUUgO1CVFkEnj+q5w=
github.com/darklab8/go-utils v0.12.0 h1:LxsG3yVNf9W4xyV+tHPOaZB2ewItgM/1BzOXyKFvofs=
Expand Down

0 comments on commit e87a501

Please sign in to comment.