Skip to content

Commit

Permalink
feat: shield tab to add
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Apr 1, 2024
1 parent f79da86 commit a1a3be1
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions darkstat/front/shared.templ
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ templ TabMenu(url utils_types.FilePath) {
<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>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Shields.ToString() } class={ templ.KV("selected", urls.Shields == url) } role="tab" aria-selected="false" aria-controls="tab-content">Shields</button>
</div>
}
<hr/>
Expand Down
93 changes: 93 additions & 0 deletions darkstat/front/shields.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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 ShieldDetailedUrl(shield configs_export.Shield) string {
return "shields/shields_base_" + strings.ToLower(shield.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 ShieldT(shields []configs_export.Shield) {
@TabMenu(urls.Shields)
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
<div id="table-top">
<table class="sortable">
<thead>
<tr>
<th style="width:200px;">Shield</th>
<th style="width:50px;">Class</th>
<th style="width:50px;">Type</th>
<th style="width:50px;">Technology</th>
<th style="width:50px;">Price</th>
<th style="width:50px;">Capacity</th>
<th style="width:50px;">Regen Rate</th>
<th style="width:50px;">Const Power Draw</th>
<th style="width:100px;">Rebuild Power Draw</th>
<th style="width:100px;">Off Power Draw</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 _, shield := range shields {
<tr
id={ "bottominfo_click" + shield.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + ShieldDetailedUrl(shield) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
>
<td>{ shield.Name }</td>
<td>{ shield.Class }</td>
<td>{ shield.Type }</td>
<td>{ shield.Technology }</td>
<td>{ strconv.Itoa(shield.Price) } </td>
<td>{ strconv.Itoa(shield.Capacity) } </td>
<td>{ strconv.Itoa(shield.RegenerationRate) }</td>
<td>{ strconv.Itoa(shield.ConstantPowerDraw) }</td>
<td>{ strconv.Itoa(shield.RebuildPowerDraw) }</td>
<td>{ strconv.Itoa(shield.OffRebuildTime) }</td>
<td>{ fmt.Sprintf("%.2f",shield.Toughness) }</td>
<td>{ strconv.Itoa(shield.HitPts) }</td>
<td>{ strconv.FormatBool(shield.Lootable) }</td>
<td>{ shield.Nickname } </td>
<td>{ strconv.Itoa(shield.IdsName) } </td>
<td>{ strconv.Itoa(shield.IdsInfo) } </td>
<td
id={ "infocard_click" + shield.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + InfocardURL(configs_export.InfocardKey(shield.Nickname)) }
hx-trigger="click"
hx-target="#infocard_view"
hx-swap="innerHTML"
></td>
@templ.Raw(JoinClickTriggers("bottominfo_click"+shield.Nickname, "infocard_click"+shield.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/urls/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ const (
GunModifiers utils_types.FilePath = "gun_modifiers.html"
Missiles utils_types.FilePath = "missiles.html"
Mines utils_types.FilePath = "mines.html"
Shields utils_types.FilePath = "shields.html"
)
29 changes: 29 additions & 0 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ func (l *Linker) Link() *builder.Builder {
})
}

sort.Slice(data.Shields, func(i, j int) bool {
if data.Shields[i].Name != "" && data.Shields[j].Name == "" {
return true
}
return data.Shields[i].Name < data.Shields[j].Name
})

for _, base_info := range data.Shields {
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 @@ -155,6 +171,10 @@ func (l *Linker) Link() *builder.Builder {
urls.Mines,
front.MinesT(data.Mines),
),
builder.NewComponent(
urls.Shields,
front.ShieldT(data.Shields),
),
)

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

for _, shield := range data.Shields {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.ShieldDetailedUrl(shield)),
front.GoodAtBaseInfoT(shield.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.23.1
github.com/darklab8/fl-configs v0.24.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 @@ -24,6 +24,8 @@ github.com/darklab8/fl-configs v0.23.0 h1:QqVOMnWLewFBzZNdvgdrD0C8RuY06dBwaREpux
github.com/darklab8/fl-configs v0.23.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.23.1 h1:NnPyyodeJEyAzbCLlcvlwl/vxFOMldZRReacx7x3V20=
github.com/darklab8/fl-configs v0.23.1/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.24.0 h1:0FyycPLtFAehWIzw/REvt5GXC1Is4keqBOSiuT0+4TU=
github.com/darklab8/fl-configs v0.24.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 a1a3be1

Please sign in to comment.