From 90923cbfe788dc52af03d22a625902797c842cfc Mon Sep 17 00:00:00 2001
From: Sky Johnson
Date: Wed, 13 Aug 2025 09:26:35 -0500
Subject: [PATCH] style updates, finish shop table, add shop modal
---
assets/dk.css | 78 ++++++++++++++++++++++++--
internal/routes/town.go | 26 ++++++---
internal/template/template.go | 13 ++++-
templates/auth/login.html | 4 +-
templates/layout.html | 2 +
templates/town/shop.html | 101 +++++++++++++++++++++++++++++++++-
6 files changed, 207 insertions(+), 17 deletions(-)
diff --git a/assets/dk.css b/assets/dk.css
index 8a8a565..dfdd942 100644
--- a/assets/dk.css
+++ b/assets/dk.css
@@ -104,7 +104,7 @@ a {
}
.light {
- color: #999999;
+ color: rgba(0, 0, 0, 0.35);
}
div.title {
@@ -186,7 +186,7 @@ button.btn {
background-color: #808080;
background-image: url("/assets/images/overlay.png");
border: 1px solid #808080;
- padding: 0.5rem 1rem;
+ padding: 0.25rem 0.5rem;
cursor: pointer;
color: white;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.2);
@@ -195,6 +195,18 @@ button.btn {
&:hover {
background-color: #909090;
}
+
+ &.btn-primary {
+ color: rgba(0, 0, 0, 0.5);
+ background-color: #F2994A;
+ background-image: url("/assets/images/overlay.png"), linear-gradient(to bottom, #F2C94C, #F2994A);
+ border-color: #F2994A;
+
+ &:hover {
+ background-color: #ffb574;
+ background-image: url("/assets/images/overlay.png"), linear-gradient(to bottom, #ffd965, #ffb574);
+ }
+ }
}
form.standard {
@@ -291,7 +303,7 @@ div#statbars {
height: 100%;
background-color: white;
}
-
+
hp {
& > div.bar {
background: #56ab2f;
@@ -324,4 +336,62 @@ div#statbars {
.inline-block {
display: inline-block;
-}
\ No newline at end of file
+}
+
+table {
+ border-collapse: collapse;
+ width: 100%;
+
+ th, td {
+ padding: 0.5rem;
+ text-align: left;
+ border: 1px solid rgba(0, 0, 0, 0.2);
+ }
+
+ th {
+ background-color: rgba(0, 0, 0, 0.1);
+ }
+
+ tr:nth-child(even) {
+ background-color: rgba(0, 0, 0, 0.05);
+ }
+}
+
+table.item-shop {
+ width: 80%;
+ margin: 0px auto;
+
+ td:first-child {
+ width: fit-content;
+ }
+}
+
+div.modal {
+ display: none;
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background: rgba(0, 0, 0, 0.5);
+ z-index: 1000;
+
+ & > div.content {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ background: white;
+ padding: 1.25rem;
+ min-width: 300px;
+ text-align: center;
+ background-image: url("/assets/images/backgrounds/snowstorm.jpg");
+ }
+
+ div.buttons {
+ margin-top: 20px;
+ gap: 10px;
+ display: flex;
+ justify-content: center;
+ }
+}
diff --git a/internal/routes/town.go b/internal/routes/town.go
index 3467a45..f5f4c54 100644
--- a/internal/routes/town.go
+++ b/internal/routes/town.go
@@ -9,7 +9,6 @@ import (
"dk/internal/template/components"
"dk/internal/towns"
"dk/internal/users"
- "fmt"
)
func RegisterTownRoutes(r *router.Router) {
@@ -33,10 +32,17 @@ func showTown(ctx router.Ctx, _ []string) {
}
func showInn(ctx router.Ctx, _ []string) {
+ var errorHTML string
+ if flash := auth.GetFlashMessage(ctx); flash != nil {
+ errorHTML = `` + flash.Message + "
"
+ }
+
town := ctx.UserValue("town").(*towns.Town)
+
components.RenderPage(ctx, town.Name+" Inn", "town/inn.html", map[string]any{
- "town": town,
- "rested": false,
+ "town": town,
+ "rested": false,
+ "error_message": errorHTML,
})
}
@@ -45,8 +51,8 @@ func rest(ctx router.Ctx, _ []string) {
user := ctx.UserValue("user").(*users.User)
if user.Gold < town.InnCost {
- fmt.Println("Cant afford")
- ctx.Redirect("/town", 303)
+ auth.SetFlashMessage(ctx, "error", "You can't afford to stay here tonight.")
+ ctx.Redirect("/town/inn", 303)
return
}
@@ -63,6 +69,11 @@ func rest(ctx router.Ctx, _ []string) {
}
func showShop(ctx router.Ctx, _ []string) {
+ var errorHTML string
+ if flash := auth.GetFlashMessage(ctx); flash != nil {
+ errorHTML = `` + flash.Message + "
"
+ }
+
town := ctx.UserValue("town").(*towns.Town)
var itemlist []*items.Item
@@ -77,7 +88,8 @@ func showShop(ctx router.Ctx, _ []string) {
}
components.RenderPage(ctx, town.Name+" Shop", "town/shop.html", map[string]any{
- "town": town,
- "itemlist": itemlist,
+ "town": town,
+ "itemlist": itemlist,
+ "error_message": errorHTML,
})
}
diff --git a/internal/template/template.go b/internal/template/template.go
index d283fb5..0d36bcd 100644
--- a/internal/template/template.go
+++ b/internal/template/template.go
@@ -671,7 +671,18 @@ func (t *Template) findElseAtLevel(content string) int {
func (t *Template) evaluateCondition(condition string, data map[string]any) bool {
condition = strings.TrimSpace(condition)
- // Handle 'and' operator
+ // Handle 'or' operator (lower precedence)
+ if strings.Contains(condition, " or ") {
+ parts := strings.SplitSeq(condition, " or ")
+ for part := range parts {
+ if t.evaluateCondition(strings.TrimSpace(part), data) {
+ return true
+ }
+ }
+ return false
+ }
+
+ // Handle 'and' operator (higher precedence)
if strings.Contains(condition, " and ") {
parts := strings.SplitSeq(condition, " and ")
for part := range parts {
diff --git a/templates/auth/login.html b/templates/auth/login.html
index 1b6fd43..e36f096 100644
--- a/templates/auth/login.html
+++ b/templates/auth/login.html
@@ -19,7 +19,7 @@
- Log in
+ Log in
@@ -31,4 +31,4 @@
You may also change your password , or
request a new one if you've lost yours.
-{/block}
\ No newline at end of file
+{/block}
diff --git a/templates/layout.html b/templates/layout.html
index 927cb9a..c9b4465 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -48,5 +48,7 @@
Version {_version} {_build}
+
+ {yield "scripts"}