Skip to content

Commit

Permalink
feat: ships tab to add
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Apr 6, 2024
1 parent 13035c5 commit da24e46
Show file tree
Hide file tree
Showing 6 changed files with 141 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 @@ -138,6 +138,7 @@ templ TabMenu(url utils_types.FilePath) {
<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>
<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>
</div>
}
<hr/>
Expand Down
107 changes: 107 additions & 0 deletions darkstat/front/ships.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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 ShipDetailedUrl(ship configs_export.Ship) string {
return "ships/ships_base_" + strings.ToLower(ship.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 ShipsT(ships []configs_export.Ship) {
@TabMenu(urls.Ships)
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
<div id="table-top">
<table class="sortable">
<thead>
<tr>
<th style="width:200px;">Ship</th>
<th style="width:50px;">Class</th>
<th style="width:50px;">Type</th>
<th style="width:50px;">Price</th>
<th style="width:50px;">Buyable</th>
<th style="width:50px;">Armor</th>
<th style="width:50px;">Hold Size</th>
<th style="width:50px;">Nanobots</th>
<th style="width:50px;">Batteries</th>
<th style="width:100px;">Max Angular Speed (deg/s)</th>
<th style="width:100px;">Ang Dist. from 0 to 0.5 sec (deg)</th>
<th style="width:50px;">Time to 90% Max Angular Speed (s)</th>
<th style="width:50px;">Power Capacity</th>
<th style="width:50px;">Power Recharge Rate</th>
<th style="width:50px;">Thrust Capacity</th>
<th style="width:50px;">Thrust Recharge Rate</th>
<th style="width:50px;">Impulse Speed</th>
<th style="width:50px;">Reverse Fraction</th>
<th style="width:50px;">Nudge Force</th>
<th style="width:50px;">Strafe Forece</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 _, ship := range ships {
<tr
id={ "bottominfo_click" + ship.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + ShipDetailedUrl(ship) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
>
<td>{ ship.Name }</td>
<td>{ strconv.Itoa(ship.Class) }</td>
<td>{ ship.Type }</td>
<td>{ strconv.Itoa(ship.Price) }</td>
<td>{ strconv.FormatBool(len(ship.Bases) > 0) }</td>
<td>{ strconv.Itoa(ship.Armor) } </td>
<td>{ strconv.Itoa(ship.HoldSize) } </td>
<td>{ strconv.Itoa(ship.Nanobots) }</td>
<td>{ strconv.Itoa(ship.Batteries) }</td>
<td>{ fmt.Sprintf("%.2f",ship.MaxAngularSpeedDegS) }</td>
<td>{ fmt.Sprintf("%.2f",ship.AngularDistanceFrom0ToHalfSec) }</td>
<td>{ fmt.Sprintf("%.2f",ship.TimeTo90MaxAngularSpeed) }</td>
<td>{ strconv.Itoa(ship.PowerCapacity) }</td>
<td>{ strconv.Itoa(ship.PowerRechargeRate) }</td>
<td>{ strconv.Itoa(ship.ThrustCapacity) }</td>
<td>{ strconv.Itoa(ship.ThrustRecharge) }</td>
<td>{ fmt.Sprintf("%.2f",ship.ImpulseSpeed) }</td>
<td>{ fmt.Sprintf("%.2f",ship.ReverseFraction) }</td>
<td>{ fmt.Sprintf("%.2f",ship.NudgeForce) }</td>
<td>{ fmt.Sprintf("%.2f",ship.StrafeForce) }</td>
<td>{ ship.Nickname } </td>
<td>{ strconv.Itoa(ship.NameID) } </td>
<td>{ strconv.Itoa(ship.InfoID) } </td>
<td
id={ "infocard_click" + ship.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + InfocardURL(configs_export.InfocardKey(ship.Nickname)) }
hx-trigger="click"
hx-target="#infocard_view"
hx-swap="innerHTML"
></td>
@templ.Raw(JoinClickTriggers("bottominfo_click"+ship.Nickname, "infocard_click"+ship.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 @@ -16,4 +16,5 @@ const (
Mines utils_types.FilePath = "mines.html"
Shields utils_types.FilePath = "shields.html"
Thrusters utils_types.FilePath = "thrusters.html"
Ships utils_types.FilePath = "ships.html"
)
29 changes: 29 additions & 0 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ func (l *Linker) Link() *builder.Builder {
})
}

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

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

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

for _, ship := range data.Ships {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.ShipDetailedUrl(ship)),
front.GoodAtBaseInfoT(ship.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.25.0
github.com/darklab8/fl-configs v0.26.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 @@ -28,6 +28,8 @@ github.com/darklab8/fl-configs v0.24.0 h1:0FyycPLtFAehWIzw/REvt5GXC1Is4keqBOSiuT
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/fl-configs v0.26.0 h1:sxNYGvvUqSh+x7h6HJx7cCAeZBmvUCtf12kHYhwnYtA=
github.com/darklab8/fl-configs v0.26.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 da24e46

Please sign in to comment.