Skip to content

Commit

Permalink
feat: gun modifiers tab
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Mar 31, 2024
1 parent 2dfa747 commit 8f823c9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 19 deletions.
2 changes: 1 addition & 1 deletion darkstat/common/common_static/common.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ templ CommonCSS() {
}

p {
font-size: 1.17em;
font-size: 1.1em;
}

hr {
Expand Down
68 changes: 60 additions & 8 deletions darkstat/front/guns.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ import (
"strings"
)

func GunBaseInfoUrl(gun configs_export.Gun) string {
return "guns/guns_base_" + strings.ToLower(gun.Nickname)
func GunDetailedUrl(gun configs_export.Gun, mode GunTabMode) string {
if mode == GunsShowBases {
return "guns/guns_base_" + strings.ToLower(gun.Nickname)
} else {
return "guns/guns_bonuses_" + strings.ToLower(gun.Nickname)
}
}

type GunTabMode int64

const (
GunsShowBases GunTabMode = iota
GunsShowDamageBonuses
)

// 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 GunsT(guns []configs_export.Gun) {
@TabMenu(urls.Guns)
templ GunsT(guns []configs_export.Gun, mode GunTabMode) {
if mode == GunsShowBases {
@TabMenu(urls.Guns)
} else {
@TabMenu(urls.GunModifiers)
}
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
Expand Down Expand Up @@ -53,8 +68,8 @@ templ GunsT(guns []configs_export.Gun) {
<tbody>
for _, gun := range guns {
<tr
id={ "baseinfo_click" + gun.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + GunBaseInfoUrl(gun) }
id={ "guninfo_click" + gun.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + GunDetailedUrl(gun, mode) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
Expand Down Expand Up @@ -89,14 +104,18 @@ templ GunsT(guns []configs_export.Gun) {
hx-target="#infocard_view"
hx-swap="innerHTML"
></td>
@templ.Raw(JoinClickTriggers("baseinfo_click"+gun.Nickname, "infocard_click"+gun.Nickname))
@templ.Raw(JoinClickTriggers("guninfo_click"+gun.Nickname, "infocard_click"+gun.Nickname))
</tr>
}
</tbody>
</table>
</div>
<div id="table-bottom">
@GoodAtBaseSharedT(ShowPricePerVolume(true))
if mode == GunsShowBases {
@GoodAtBaseSharedT(ShowPricePerVolume(true))
} else {
@GunShowModifiersShared()
}
</div>
</div>
<div id="infocard_view">
Expand All @@ -105,3 +124,36 @@ templ GunsT(guns []configs_export.Gun) {
</div>
}
}

templ GunShowModifiersShared() {
<table class="sortable">
<thead>
<tr class="flexed-tr">
<th style="width:50px;">Technology</th>
<th style="width:50px;">Target Type</th>
<th style="width:50px;">Damage Modifier</th>
<th style="width:50px;">Hull Dmg</th>
<th style="width:50px;">Shield Dmg</th>
<th style="max-width:100%;"></th>
</tr>
</thead>
<tbody>
{ children... }
</tbody>
</table>
}

templ GunShowModifiers(gun configs_export.Gun) {
@GunShowModifiersShared() {
for _, bonus := range gun.DamangeBonuses {
<tr>
<td>{ gun.DamageType }</td>
<td>{ bonus.Type }</td>
<td>{ fmt.Sprintf("%.2f", bonus.Modifier) }</td>
<td>{ strconv.Itoa(int(float64(gun.HullDamage)*bonus.Modifier)) }</td>
<td>{ strconv.Itoa(int(float64(gun.ShieldDamage)*bonus.Modifier)) }</td>
<td></td>
</tr>
}
}
}
1 change: 1 addition & 0 deletions darkstat/front/shared.templ
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ templ TabMenu(url utils_types.FilePath) {
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Rephacks.ToString() } class={ templ.KV("selected", urls.Rephacks == url) } role="tab" aria-selected="false" aria-controls="tab-content">Rephacks</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Commodities.ToString() } class={ templ.KV("selected", urls.Commodities == url) } role="tab" aria-selected="false" aria-controls="tab-content">Commodities</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Guns.ToString() } class={ templ.KV("selected", urls.Guns == url) } role="tab" aria-selected="false" aria-controls="tab-content">Guns</button>
<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>
</div>
}
<hr/>
Expand Down
13 changes: 7 additions & 6 deletions darkstat/front/urls/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
)

const (
Index utils_types.FilePath = "index.html"
Bases utils_types.FilePath = "bases.html"
Factions utils_types.FilePath = "factions.html"
Rephacks utils_types.FilePath = "rephacks.html"
Commodities utils_types.FilePath = "commodities.html"
Guns utils_types.FilePath = "guns.html"
Index utils_types.FilePath = "index.html"
Bases utils_types.FilePath = "bases.html"
Factions utils_types.FilePath = "factions.html"
Rephacks utils_types.FilePath = "rephacks.html"
Commodities utils_types.FilePath = "commodities.html"
Guns utils_types.FilePath = "guns.html"
GunModifiers utils_types.FilePath = "gun_modifiers.html"
)
16 changes: 12 additions & 4 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ func (l *Linker) Link() *builder.Builder {
),
builder.NewComponent(
urls.Guns,
front.GunsT(data.Guns),
front.GunsT(data.Guns, front.GunsShowBases),
),
builder.NewComponent(
urls.GunModifiers,
front.GunsT(data.Guns, front.GunsShowDamageBonuses),
),
)

Expand Down Expand Up @@ -177,11 +181,15 @@ func (l *Linker) Link() *builder.Builder {
)
}

for _, base_info := range data.Guns {
for _, gun := range data.Guns {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.GunBaseInfoUrl(base_info)),
front.GoodAtBaseInfoT(base_info.Bases, front.ShowPricePerVolume(false)),
utils_types.FilePath(front.GunDetailedUrl(gun, front.GunsShowBases)),
front.GoodAtBaseInfoT(gun.Bases, front.ShowPricePerVolume(false)),
),
builder.NewComponent(
utils_types.FilePath(front.GunDetailedUrl(gun, front.GunsShowDamageBonuses)),
front.GunShowModifiers(gun),
),
)
}
Expand Down

0 comments on commit 8f823c9

Please sign in to comment.