From 42a71c1ac32443c4a4edfed4cf8ddcbd6b9b2a8b Mon Sep 17 00:00:00 2001
From: Eryn Wells
Date: Tue, 24 Jan 2023 08:53:58 -0800
Subject: [PATCH] =?UTF-8?q?Update=20Nethack=20partials,=20shortcodes,=20an?=
=?UTF-8?q?d=20page=20to=20properly=20handle=20ascensions=20=F0=9F=98=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
content/nethack/index.md | 40 +++++++++-------------
layouts/partials/nethack/log.html | 6 ++++
layouts/partials/nethack/logentry.html | 31 ++++++++++++-----
layouts/shortcodes/nethack/ascensions.html | 3 ++
layouts/shortcodes/nethack/logfile.html | 6 +---
layouts/shortcodes/nethack/n.html | 2 ++
layouts/shortcodes/nethack/topn.html | 7 ++++
7 files changed, 59 insertions(+), 36 deletions(-)
create mode 100644 layouts/partials/nethack/log.html
create mode 100644 layouts/shortcodes/nethack/ascensions.html
create mode 100644 layouts/shortcodes/nethack/n.html
create mode 100644 layouts/shortcodes/nethack/topn.html
diff --git a/content/nethack/index.md b/content/nethack/index.md
index 18cf6d6..b8bda90 100644
--- a/content/nethack/index.md
+++ b/content/nethack/index.md
@@ -1,36 +1,30 @@
---
title: "Nethack"
-description: In which I play way too much of a silly command line Rogue-like game.
+description: In which I play way too much of a silly command line Roguelike game.
date: 2022-04-13T08:43:46-07:00
---
Every so often I get hooked on [this game][nethack]. It's a command line
-Roguelike adventure game with rules based on Dungeons & Dragons. You play a
-character on a mission for their deity to retrieve the Amulet of Yendor from an
-evil Wizard and bring it back to the surface. The game gives you very little to
-go on when you start, and it teaches you almost nothing except the basic
-controls. Famously, almost every item you encounter or action you can take can
-go wrong in some catastrophic way and cause
- {{< abbr title="Yet Another Stupid Death" >}}YASD{{ abbr >}}.
-The more you play, the more you learn, and the more you begin to understand the
-risks and consequences.
+[Roguelike][rl] adventure game with rules based on Dungeons & Dragons. As far as
+I know, it is the oldest computer game in ongoing development.
-In short: it's very hard, you die a lot, and it's quite easy to lose hours
-delving deeper and deeper into the Dungeons of Doom, dying, and starting again.
-It's also really fun.
+You play a character on a mission to retrieve the Amulet of Yendor, held in the
+deepest level of Gehennom by the evil god Moloch, and ascend to demigodhood by
+offering it to your deity. You are taught nothing and given no training, and
+worse: almost every monster, item, and dungeon feature can kill you if you
+aren't careful. The more you play, the more you learn, and the more you begin to
+understand the risks and consequences.
-Here's my best game so far:
+In short: it's very hard, you die a lot, and it's easy to lose hours delving
+deeper and deeper into the Dungeons of Doom, dying, and starting again. It's
+tons of fun.
-{{< nethack/best_game >}}
+Since I started keeping records, I've played {{< nethack/n >}} games, and
+ascended {{< nethack/ascensions >}} of them.
-## A Game Log
+Here are my top 10 best games:
-The game logs every play-through, along with a bunch of data about your
-character and how you did.
-
-Herein is a chronological accounting of my last ten descents into the Dungeons
-of Doom.
-
-{{< nethack/logfile >}}
+{{< nethack/topn 10 >}}
[nethack]: https://www.nethack.org
+[rl]: https://en.wikipedia.org/wiki/Roguelike
diff --git a/layouts/partials/nethack/log.html b/layouts/partials/nethack/log.html
new file mode 100644
index 0000000..fdb99b8
--- /dev/null
+++ b/layouts/partials/nethack/log.html
@@ -0,0 +1,6 @@
+{{ $nethack_data := $.Site.Data.nethack.logfile }}
+{{ $logfile := slice }}
+{{ range $nethack_data }}
+ {{ $logfile = $logfile | append .logfile }}
+{{ end }}
+{{ return $logfile }}
diff --git a/layouts/partials/nethack/logentry.html b/layouts/partials/nethack/logentry.html
index caa9494..bbc03ff 100644
--- a/layouts/partials/nethack/logentry.html
+++ b/layouts/partials/nethack/logentry.html
@@ -1,12 +1,24 @@
-{{ $level := (cond (gt .dungeon.level.n 0) (.dungeon.level.descriptive | lower) .dungeon.level.descriptive) }}
-{{ if .death.cause }}🪦{{ end }}
+{{- $cause := .death.cause -}}
+{{- $didAscend := eq $cause "ascended" -}}
+{{- $level := (cond (gt .dungeon.level.n 0) (.dungeon.level.descriptive | lower) .dungeon.level.descriptive) -}}
+{{- if $didAscend -}}✨{{- else -}}🪦{{- end -}}
{{ time.Format "January 2, 2006" .end_date }}
{{ .character.abbreviated }}
-{{ .character.name }}, a {{ .character.alignment.descriptive | lower }} {{ .character.race.descriptive | lower }}
- {{ .character.gender.descriptive | lower }} {{ .character.role.descriptive }},
- died {{ if gt .death.count 1 }}for the last time{{ end }} in {{ .dungeon.name }}
+
+ {{- $name := .character.name -}}
+ {{- $descriptiveAlignment := .character.alignment.descriptive | lower -}}
+ {{- $descriptiveRace := .character.race.descriptive | lower -}}
+ {{- $descriptiveRole := .character.role.descriptive -}}
+ {{- if $didAscend -}}
+ {{ $name }}, a {{ $descriptiveAlignment }} {{ $descriptiveRace }} {{ $descriptiveRole }}, ascended.
+ {{- else -}}
+ {{ $name }}, a {{ $descriptiveAlignment }} {{ $descriptiveRace }} {{ $descriptiveRole }}, died
+ {{ if gt .death.count 1 -}}for the last time{{- end }} in
+ {{ .dungeon.name }}
on {{ $level }}.
- She was {{ .death.cause }}.
+ She was {{ .death.cause }}.
+ {{- end -}}
+
{{- $startDate := time.Format "January, 02 2006" .start_date -}}
@@ -27,7 +39,10 @@
{{ else }}
{{ with .character.max_level }}Level {{ . }} | {{ end }}
{{ end }}
- {{ cond (gt .character.hp.n 0) (printf "%s / %s" .character.hp.n .character.hp.max)
- .character.hp.max }} hp |
+
+ {{- $hp := float .character.hp.n -}}
+ {{- $hpMax := .character.hp.max -}}
+ {{- if gt $hp 0 }}{{ $hp }} / {{ $hpMax }}{{ else }}{{ $hp }}{{ end }} hp
+ |
diff --git a/layouts/shortcodes/nethack/ascensions.html b/layouts/shortcodes/nethack/ascensions.html
new file mode 100644
index 0000000..1eb86a0
--- /dev/null
+++ b/layouts/shortcodes/nethack/ascensions.html
@@ -0,0 +1,3 @@
+{{- $logfile := partial "nethack/log.html" . -}}
+{{- $numberOfAscensions := where $logfile "death.cause" "ascended" | len -}}
+{{- $numberOfAscensions | lang.FormatNumber 0 -}}
diff --git a/layouts/shortcodes/nethack/logfile.html b/layouts/shortcodes/nethack/logfile.html
index 430856a..73d0450 100644
--- a/layouts/shortcodes/nethack/logfile.html
+++ b/layouts/shortcodes/nethack/logfile.html
@@ -1,8 +1,4 @@
-{{ $nethack_data := $.Site.Data.nethack.logfile }}
-{{ $logfile := slice }}
-{{ range $nethack_data }}
- {{ $logfile = $logfile | append .logfile }}
-{{ end }}
+{{- $logfile := partial "nethack/log.html" . -}}
{{ range sort $logfile "end_date" "desc" }}
{{ if ne .death.cause "quit" }}
diff --git a/layouts/shortcodes/nethack/n.html b/layouts/shortcodes/nethack/n.html
new file mode 100644
index 0000000..8f0bb78
--- /dev/null
+++ b/layouts/shortcodes/nethack/n.html
@@ -0,0 +1,2 @@
+{{- $numberOfEntries := (partial "nethack/log.html" .) | len -}}
+{{- $numberOfEntries | lang.FormatNumber 0 -}}
diff --git a/layouts/shortcodes/nethack/topn.html b/layouts/shortcodes/nethack/topn.html
new file mode 100644
index 0000000..699c650
--- /dev/null
+++ b/layouts/shortcodes/nethack/topn.html
@@ -0,0 +1,7 @@
+{{- $n := .Get 0 -}}
+{{- $logfile := partial "nethack/log.html" . -}}
+
+ {{ range first $n (sort $logfile "score" "desc") -}}
+ - {{ partial "nethack/logentry.html" . }}
+ {{- end }}
+