Skip to content

Commit

Permalink
feat: mines tab shown
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Mar 31, 2024
1 parent 1cad5f2 commit d384821
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
103 changes: 103 additions & 0 deletions darkstat/front/mines.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package front

import (
"strconv"
"github.com/darklab8/fl-darkstat/darkstat/front/urls"
"github.com/darklab8/fl-darkstat/darkstat/common/types"
"github.com/darklab8/fl-configs/configs/configs_export"
"fmt"
"strings"
)

func MineDetailedUrl(mine configs_export.Mine) string {
return "mines/mines_base_" + strings.ToLower(mine.Nickname)
}

// https://www.cssscript.com/minimalist-table-sortable/#:~:text=Description%3A-,sorttable.,clicking%20on%20the%20table%20headers
// https://www.cssscript.com/fast-html-table-sorting/
templ MinesT(mines []configs_export.Mine) {
@TabMenu(urls.Mines)
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
<div id="table-top">
<table class="sortable">
<thead>
<tr>
<th style="width:200px;">Mine</th>
<th style="width:50px;">Price</th>
<th style="width:50px;">Ammo Price</th>
<th style="width:50px;">Hull Dmg</th>
<th style="width:50px;">Shield Dmg</th>
<th style="width:100px;">Value</th>
<th style="width:100px;">Refire</th>
<th style="width:50px;">Detonation Dist.</th>
<th style="width:50px;">Radius</th>
<th style="width:50px;">Seek Dist.</th>
<th style="width:50px;">Top Speed</th>
<th style="width:50px;">Acceleration</th>
<th style="width:50px;">Linear Drag</th>
<th style="width:50px;">Lifetime</th>
<th style="width:50px;">Owner Safe</th>
<th style="width:50px;">Toughness</th>
<th style="width:50px;">Hit Pts</th>
<th style="width:50px;">Lootable</th>
<th style="width:50px;">Nickname</th>
<th style="width:100px;">Name ID</th>
<th style="width:100px;">Info ID</th>
<th style="max-width:100%;"></th>
</tr>
</thead>
<tbody>
for _, mine := range mines {
<tr
id={ "bottominfo_click" + mine.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + MineDetailedUrl(mine) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
>
<td>{ mine.Name }</td>
<td>{ strconv.Itoa(mine.Price) } </td>
<td>{ strconv.Itoa(mine.AmmoPrice) } </td>
<td>{ strconv.Itoa(mine.HullDamage) }</td>
<td>{ strconv.Itoa(mine.ShieldDamage) }</td>
<td>{ fmt.Sprintf("%.2f",mine.Value) }</td>
<td>{ fmt.Sprintf("%.2f", mine.Refire) }</td>
<td>{ fmt.Sprintf("%.2f", mine.DetonationDistance) }</td>
<td>{ fmt.Sprintf("%.2f",mine.Radius) }</td>
<td>{ strconv.Itoa(mine.SeekDistance) }</td>
<td>{ strconv.Itoa(mine.TopSpeed) }</td>
<td>{ strconv.Itoa(mine.Acceleration) }</td>
<td>{ fmt.Sprintf("%.6f",mine.LinearDrag) }</td>
<td>{ fmt.Sprintf("%.2f",mine.LifeTime) }</td>
<td>{ strconv.Itoa(mine.OwnerSafe) }</td>
<td>{ fmt.Sprintf("%.2f",mine.Toughness) }</td>
<td>{ strconv.Itoa(mine.HitPts) }</td>
<td>{ strconv.FormatBool(mine.Lootable) }</td>
<td>{ mine.Nickname } </td>
<td>{ strconv.Itoa(mine.IdsName) } </td>
<td>{ strconv.Itoa(mine.IdsInfo) } </td>
<td
id={ "infocard_click" + mine.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + InfocardURL(configs_export.InfocardKey(mine.Nickname)) }
hx-trigger="click"
hx-target="#infocard_view"
hx-swap="innerHTML"
></td>
@templ.Raw(JoinClickTriggers("bottominfo_click"+mine.Nickname, "infocard_click"+mine.Nickname))
</tr>
}
</tbody>
</table>
</div>
<div id="table-bottom">
@GoodAtBaseSharedT(ShowPricePerVolume(false))
</div>
</div>
<div id="infocard_view">
@InfocardShared()
</div>
</div>
}
}
1 change: 1 addition & 0 deletions darkstat/front/shared.templ
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ templ TabMenu(url utils_types.FilePath) {
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Guns.ToString() } class={ templ.KV("selected", urls.Guns == url) } role="tab" aria-selected="false" aria-controls="tab-content">Guns</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.GunModifiers.ToString() } class={ templ.KV("selected", urls.GunModifiers == url) } role="tab" aria-selected="false" aria-controls="tab-content">Gun Modifiers</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Missiles.ToString() } class={ templ.KV("selected", urls.Missiles == url) } role="tab" aria-selected="false" aria-controls="tab-content">Missiles</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Mines.ToString() } class={ templ.KV("selected", urls.Mines == url) } role="tab" aria-selected="false" aria-controls="tab-content">Mines</button>
</div>
}
<hr/>
Expand Down
1 change: 1 addition & 0 deletions darkstat/front/urls/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ const (
Guns utils_types.FilePath = "guns.html"
GunModifiers utils_types.FilePath = "gun_modifiers.html"
Missiles utils_types.FilePath = "missiles.html"
Mines utils_types.FilePath = "mines.html"
)
22 changes: 22 additions & 0 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ func (l *Linker) Link() *builder.Builder {
})
}

for _, base_info := range data.Mines {
sort.Slice(base_info.Bases, func(i, j int) bool {
if base_info.Bases[i].BaseName != "" && base_info.Bases[j].BaseName == "" {
return true
}
return base_info.Bases[i].BaseName < base_info.Bases[j].BaseName
})
}

build := builder.NewBuilder()
build.RegComps(
builder.NewComponent(
Expand Down Expand Up @@ -142,6 +151,10 @@ func (l *Linker) Link() *builder.Builder {
urls.Missiles,
front.GunsT(data.Missiles, front.GunsMissiles),
),
builder.NewComponent(
urls.Mines,
front.MinesT(data.Mines),
),
)

for _, base := range data.Bases {
Expand Down Expand Up @@ -207,5 +220,14 @@ func (l *Linker) Link() *builder.Builder {
)
}

for _, mine := range data.Mines {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.MineDetailedUrl(mine)),
front.GoodAtBaseInfoT(mine.Bases, front.ShowPricePerVolume(false)),
),
)
}

return build
}
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.22.0
github.com/darklab8/fl-configs v0.23.0
github.com/darklab8/go-typelog v0.6.0
github.com/darklab8/go-utils v0.12.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 @@ -20,6 +20,8 @@ github.com/darklab8/fl-configs v0.21.1 h1:dBIVOJocWL9JefjU616cY4KdpxyCgEBuvpETf7
github.com/darklab8/fl-configs v0.21.1/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.22.0 h1:f3klPld5n0qLS7wn3x3uqEvrgf348pgHnuOnpqgRlVQ=
github.com/darklab8/fl-configs v0.22.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.23.0 h1:QqVOMnWLewFBzZNdvgdrD0C8RuY06dBwaREpux/29x4=
github.com/darklab8/fl-configs v0.23.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 d384821

Please sign in to comment.