Skip to content

Commit

Permalink
feat: exporting also tractors
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Apr 6, 2024
1 parent 893bc15 commit 5e81ec3
Show file tree
Hide file tree
Showing 6 changed files with 112 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 @@ -145,6 +145,7 @@ templ TabMenu(url utils_types.FilePath) {
<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>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Ships.ToString() } class={ templ.KV("selected", urls.Ships == url) } role="tab" aria-selected="false" aria-controls="tab-content">Ships</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.ShipDetails.ToString() } class={ templ.KV("selected", urls.ShipDetails == url) } role="tab" aria-selected="false" aria-controls="tab-content">Ship Details</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Tractors.ToString() } class={ templ.KV("selected", urls.Tractors == url) } role="tab" aria-selected="false" aria-controls="tab-content">Tractors</button>
</div>
}
<hr/>
Expand Down
78 changes: 78 additions & 0 deletions darkstat/front/tractors.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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"
"strings"
)

func TractorDetailedUrl(tractor configs_export.Tractor) string {
return "tractor/tractor_base_" + strings.ToLower(tractor.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 TractorsT(tractors []configs_export.Tractor) {
@TabMenu(urls.Tractors)
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
<div id="table-top">
<table class="sortable">
<thead>
<tr>
<th style="width:200px;">Tractor</th>
<th style="width:50px;">Price</th>
<th style="width:50px;">Buyable</th>
<th style="width:50px;">Max Length</th>
<th style="width:50px;">Reach Speed</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 _, tractor := range tractors {
<tr
id={ "bottominfo_click" + tractor.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + TractorDetailedUrl(tractor) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
>
<td>{ tractor.Name }</td>
<td>{ strconv.Itoa(tractor.Price) } </td>
<td>{ strconv.FormatBool(len(tractor.Bases) > 0) }</td>
<td>{ strconv.Itoa(tractor.MaxLength) } </td>
<td>{ strconv.Itoa(tractor.ReachSpeed) }</td>
<td>{ strconv.FormatBool(tractor.Lootable) }</td>
<td>{ tractor.Nickname } </td>
<td>{ strconv.Itoa(tractor.NameID) } </td>
<td>{ strconv.Itoa(tractor.InfoID) } </td>
<td
id={ "infocard_click" + tractor.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + InfocardURL(configs_export.InfocardKey(tractor.Nickname)) }
hx-trigger="click"
hx-target="#infocard_view"
hx-swap="innerHTML"
></td>
@templ.Raw(JoinClickTriggers("bottominfo_click"+tractor.Nickname, "infocard_click"+tractor.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 @@ -18,4 +18,5 @@ const (
Thrusters utils_types.FilePath = "thrusters.html"
Ships utils_types.FilePath = "ships.html"
ShipDetails utils_types.FilePath = "ship_details.html"
Tractors utils_types.FilePath = "tractors.html"
)
29 changes: 29 additions & 0 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ func (l *Linker) Link() *builder.Builder {
})
}

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

for _, base_info := range data.Tractors {
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 @@ -219,6 +235,10 @@ func (l *Linker) Link() *builder.Builder {
urls.ShipDetails,
front.ShipsT(data.Ships, front.ShipShowDetails),
),
builder.NewComponent(
urls.Tractors,
front.TractorsT(data.Tractors),
),
)

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

for _, tractor := range data.Tractors {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.TractorDetailedUrl(tractor)),
front.GoodAtBaseInfoT(tractor.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.27.0
github.com/darklab8/fl-configs v0.28.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 @@ -32,6 +32,8 @@ github.com/darklab8/fl-configs v0.26.0 h1:sxNYGvvUqSh+x7h6HJx7cCAeZBmvUCtf12kHYh
github.com/darklab8/fl-configs v0.26.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.27.0 h1:z62lSXdPSw1Qq9z860iVRHtT6l6qkzBEbAxsrG+esFs=
github.com/darklab8/fl-configs v0.27.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.28.0 h1:DvsMg/1H4oo+zjym2AeuSXurThW/WgyOlEKTjAghWGg=
github.com/darklab8/fl-configs v0.28.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 5e81ec3

Please sign in to comment.