From da24e463ad386dfba95d045d0b26acee6084558d Mon Sep 17 00:00:00 2001 From: dd84ai Date: Sat, 6 Apr 2024 18:02:17 +0200 Subject: [PATCH] feat: ships tab to add --- darkstat/front/shared.templ | 1 + darkstat/front/ships.templ | 107 ++++++++++++++++++++++++++++++++++++ darkstat/front/urls/urls.go | 1 + darkstat/linker/linker.go | 29 ++++++++++ go.mod | 2 +- go.sum | 2 + 6 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 darkstat/front/ships.templ diff --git a/darkstat/front/shared.templ b/darkstat/front/shared.templ index 9e490c9f..9086de7f 100644 --- a/darkstat/front/shared.templ +++ b/darkstat/front/shared.templ @@ -138,6 +138,7 @@ templ TabMenu(url utils_types.FilePath) { + }
diff --git a/darkstat/front/ships.templ b/darkstat/front/ships.templ new file mode 100644 index 00000000..aa098008 --- /dev/null +++ b/darkstat/front/ships.templ @@ -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() { +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + for _, ship := range ships { + + + + + + + + + + + + + + + + + + + + + + + + + + @templ.Raw(JoinClickTriggers("bottominfo_click"+ship.Nickname, "infocard_click"+ship.Nickname)) + + } + +
ShipClassTypePriceBuyableArmorHold SizeNanobotsBatteriesMax Angular Speed (deg/s)Ang Dist. from 0 to 0.5 sec (deg)Time to 90% Max Angular Speed (s)Power CapacityPower Recharge RateThrust CapacityThrust Recharge RateImpulse SpeedReverse FractionNudge ForceStrafe ForeceNicknameName IDInfo ID
{ ship.Name }{ strconv.Itoa(ship.Class) }{ ship.Type }{ strconv.Itoa(ship.Price) }{ strconv.FormatBool(len(ship.Bases) > 0) }{ strconv.Itoa(ship.Armor) } { strconv.Itoa(ship.HoldSize) } { strconv.Itoa(ship.Nanobots) }{ strconv.Itoa(ship.Batteries) }{ fmt.Sprintf("%.2f",ship.MaxAngularSpeedDegS) }{ fmt.Sprintf("%.2f",ship.AngularDistanceFrom0ToHalfSec) }{ fmt.Sprintf("%.2f",ship.TimeTo90MaxAngularSpeed) }{ strconv.Itoa(ship.PowerCapacity) }{ strconv.Itoa(ship.PowerRechargeRate) }{ strconv.Itoa(ship.ThrustCapacity) }{ strconv.Itoa(ship.ThrustRecharge) }{ fmt.Sprintf("%.2f",ship.ImpulseSpeed) }{ fmt.Sprintf("%.2f",ship.ReverseFraction) }{ fmt.Sprintf("%.2f",ship.NudgeForce) }{ fmt.Sprintf("%.2f",ship.StrafeForce) }{ ship.Nickname } { strconv.Itoa(ship.NameID) } { strconv.Itoa(ship.InfoID) }
+
+
+ @GoodAtBaseSharedT(ShowPricePerVolume(false)) +
+
+
+ @InfocardShared() +
+
+ } +} diff --git a/darkstat/front/urls/urls.go b/darkstat/front/urls/urls.go index 2e3858f6..cc8ff632 100644 --- a/darkstat/front/urls/urls.go +++ b/darkstat/front/urls/urls.go @@ -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" ) diff --git a/darkstat/linker/linker.go b/darkstat/linker/linker.go index f544e50c..28c3c5af 100644 --- a/darkstat/linker/linker.go +++ b/darkstat/linker/linker.go @@ -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( @@ -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 { @@ -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 } diff --git a/go.mod b/go.mod index 74bb1875..c8929ff1 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 1b9a30fc..66a23b58 100644 --- a/go.sum +++ b/go.sum @@ -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=