Skip to content

Commit

Permalink
feat: thrusters info render
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Apr 1, 2024
1 parent 746bb5b commit 13035c5
Show file tree
Hide file tree
Showing 6 changed files with 121 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 @@ -137,6 +137,7 @@ templ TabMenu(url utils_types.FilePath) {
<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>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Thrusters.ToString() } class={ templ.KV("selected", urls.Thrusters == url) } role="tab" aria-selected="false" aria-controls="tab-content">Thrusters</button>
</div>
}
<hr/>
Expand Down
87 changes: 87 additions & 0 deletions darkstat/front/thrusters.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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 ThrusterDetailedUrl(thruster configs_export.Thruster) string {
return "thrusters/thruster_base_" + strings.ToLower(thruster.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 ThrusterT(thrusters []configs_export.Thruster) {
@TabMenu(urls.Thrusters)
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
<div id="table-top">
<table class="sortable">
<thead>
<tr>
<th style="width:200px;">Thruster</th>
<th style="width:50px;">Price</th>
<th style="width:50px;">Buyable</th>
<th style="width:50px;">Max Force</th>
<th style="width:50px;">Power Usage</th>
<th style="width:50px;">Efficiency</th>
<th style="width:100px;">Value</th>
<th style="width:100px;">Rating</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 _, thruster := range thrusters {
<tr
id={ "bottominfo_click" + thruster.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + ThrusterDetailedUrl(thruster) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
>
<td>{ thruster.Name }</td>
<td>{ strconv.Itoa(thruster.Price) } </td>
<td>{ strconv.FormatBool(len(thruster.Bases) > 0) }</td>
<td>{ strconv.Itoa(thruster.MaxForce) } </td>
<td>{ strconv.Itoa(thruster.PowerUsage) }</td>
<td>{ fmt.Sprintf("%.2f",thruster.Efficiency) }</td>
<td>{ fmt.Sprintf("%.2f", thruster.Value) }</td>
<td>{ fmt.Sprintf("%.2f", thruster.Rating) }</td>
<td>{ strconv.Itoa(thruster.HitPts) }</td>
<td>{ strconv.FormatBool(thruster.Lootable) }</td>
<td>{ thruster.Nickname } </td>
<td>{ strconv.Itoa(thruster.NameID) } </td>
<td>{ strconv.Itoa(thruster.InfoID) } </td>
<td
id={ "infocard_click" + thruster.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + InfocardURL(configs_export.InfocardKey(thruster.Nickname)) }
hx-trigger="click"
hx-target="#infocard_view"
hx-swap="innerHTML"
></td>
@templ.Raw(JoinClickTriggers("bottominfo_click"+thruster.Nickname, "infocard_click"+thruster.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 @@ -15,4 +15,5 @@ const (
Missiles utils_types.FilePath = "missiles.html"
Mines utils_types.FilePath = "mines.html"
Shields utils_types.FilePath = "shields.html"
Thrusters utils_types.FilePath = "thrusters.html"
)
29 changes: 29 additions & 0 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ func (l *Linker) Link() *builder.Builder {
})
}

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

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

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

for _, thruster := range data.Thrusters {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.ThrusterDetailedUrl(thruster)),
front.GoodAtBaseInfoT(thruster.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.24.0
github.com/darklab8/fl-configs v0.25.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 @@ -26,6 +26,8 @@ github.com/darklab8/fl-configs v0.23.1 h1:NnPyyodeJEyAzbCLlcvlwl/vxFOMldZRReacx7
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/fl-configs v0.25.0 h1:A3ydu6zAiA8Szsv7bCaatsHDz1qdRGXhkQBUkBhzIJo=
github.com/darklab8/fl-configs v0.25.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 13035c5

Please sign in to comment.