UI updates and bug fixes
authorxangelo <git@xangelo.ca>
Mon, 9 May 2022 15:29:05 +0000 (11:29 -0400)
committerxangelo <git@xangelo.ca>
Thu, 12 May 2022 04:39:29 +0000 (00:39 -0400)
Fixes:
- Resource requirements for construction/training not appearing until
  you click the build button (which then requires you hitting
  Build/Train twice)
- References to "tick-city"
- Resources are now visible and updated on every page
- Menu removed from sidebar to give content more room

13 files changed:
package-lock.json
package.json
public/game.html
public/index.html
public/scifi.css
src/api.ts
src/lib/server.ts
src/render/fight.ts
src/render/kingdom-overview.ts
src/render/land-development.ts
src/render/mail.ts
src/render/topbar.ts [new file with mode: 0644]
src/render/unit-training.ts

index bb69af89fd73683929b1458a2d0154bb6d9101f5..b9e071942d97e02367df8ddd652bc30d14e758dd 100644 (file)
@@ -4,6 +4,7 @@
        "requires": true,
        "packages": {
                "": {
+                       "name": "tick-city",
                        "dependencies": {
                                "@bull-board/api": "^3.11.0",
                                "@bull-board/express": "^3.11.0",
index 070db231eb8245973041daa5b108816590c80c6f..25f5e4aa36f8004e14b7d0c21bb8b6d452ce0dd7 100644 (file)
@@ -1,5 +1,6 @@
 {
-       "name": "tick-city",
+       "name": "antares",
+       "private": true,
        "scripts": {
                "dev": "npx nodemon src/api.ts",
                "setup:rebels": "npx ts-node scripts/generate-cities.ts",
index 07e38fb51980ac520a20e16ec99ada508a1edddb..dedfa56a1d95041ceae22a85d29f90a7257fdd29 100644 (file)
 
 <body>
     <div class="row">
-        <div class="col sidebar">
-            <div class="row">
-                <div class="col pane" data-augmented-ui="tl-clip tr-2-clip-x br-2-clip-y bl-clip-x border"> 
-                    <h2 data-augmented-ui="tl-clip bl-clip none">Nav</h2>
-                    <ul class="nav">
-                        <li>
-                            <a href="#" hx-target="#main" hx-get="/poll/overview" hx-trigger="load, click">Home</a>
-                        </li>
-                        <li>
-                            <a href="#" hx-target="#main" hx-get="/poll/construction" hx-trigger="click">Construction</a>
-                        </li>
-                        <li>
-                            <a href="#" hx-target="#main" hx-get="/poll/unit-training" hx-trigger="click">Unit Training</a>
-                        </li>
-                        <li>
-                            <a href="#" hx-target="#main" hx-get="/poll/map" hx-trigger="click">Map</a>
-                        </li>
-                        <li>
-                            <a href="#" hx-target="#main" hx-get="/poll/mailroom" hx-trigger="click">Mail</a>
-                        </li>
-                    </ul>
+        <div class="col">
+            <div class="pane" id="topbar" data-augmented-ui="br-clip bl-clip border">
+                <div class="row">
+                    <div class="col" id="nav">
+                        <ul>
+                            <li>
+                                <a href="#" hx-target="#main" hx-get="/poll/overview" hx-trigger="load, click">Home</a>
+                            </li>
+                            <li>
+                                <a href="#" hx-target="#main" hx-get="/poll/construction" hx-trigger="click">Construction</a>
+                            </li>
+                            <li>
+                                <a href="#" hx-target="#main" hx-get="/poll/unit-training" hx-trigger="click">Unit Training</a>
+                            </li>
+                            <li>
+                                <a href="#" hx-target="#main" hx-get="/poll/map" hx-trigger="click">Map</a>
+                            </li>
+                            <li>
+                                <a href="#" hx-target="#main" hx-get="/poll/mailroom" hx-trigger="click">Mail</a>
+                            </li>
+                        </ul>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="col" id="info-bar">
+                        <span><b>Gold:</b> 10,000,0000</span>
+                        <span><b>Ore:</b> 10,000,000</span>
+                        <span><b>Logs:</b> 10,000,0000</span>
+                    </div>
                 </div>
             </div>
         </div>
-        <div class="col" id="main" data-augmented-ui="tl-clip tr-clip br-clip-x bl-clip border">
+    </div>
+    <div class="row">
+        <div class="col">
+            <div id="notifications"></div>
+            <div id="main" data-augmented-ui="tl-clip tr-clip br-clip-x bl-clip border">
 
+            </div>
         </div>
     </div>
     <footer>
index 8cdfc070031c32bdc5f46169b0c92f1cb8845abb..ca96901d6442a4c10e88286f6e29b7be2a4e57a8 100644 (file)
@@ -17,6 +17,9 @@
 
 <body id="home">
     <h1 data-augmented-ui="tl-clip bl-clip none">Antares</h1>
+    <div class="row">
+        <div class="col" id="notifications"></div>
+    </div>
     <div class="row">
         <div class="col">
             <p>Welcome to <b>Antares</b>, a free-to-play browser based strategy game.</p>
@@ -45,7 +48,7 @@
             <div class="row">
                 <div class="col pane" data-augmented-ui="tl-clip tr-2-clip-x br-2-clip-y bl-clip-x border">
                     <h3 data-augmented-ui="tl-clip bl-clip none">Signup</h3>
-                    <form hx-post="/accounts">
+                    <form hx-post="/accounts" hx-target="#notifications">
                         <div>
                             <label>Username:</label>
                             <input type="text" name="username">
@@ -61,7 +64,7 @@
             <div class="row">
                 <div class="col pane" style="margin-top: 2rem; " data-augmented-ui="tl-clip tr-2-clip-x br-2-clip-y bl-clip-x border">
                     <h3 data-augmented-ui="tl-clip bl-clip none">Login</h3>
-                    <form hx-post="/login">
+                    <form hx-post="/login" hx-target="#notifications">
                         <div>
                             <label>Username:</label>
                             <input type="text" name="username">
index c7c02f2a0bb7a675a356648dd0debc4df94c4ff4..2aa04852608cf1c96f1bab8f2440f7856826cde4 100644 (file)
@@ -1,5 +1,6 @@
 :root {
     --border: #1c7282;
+    --blended-border: #073b44;
     --page-bg: #061619;
     --green-bg: #193818;
     --green-border: #32821c;
@@ -12,8 +13,8 @@ input {
 body {
     background-color: var(--page-bg);
     color: #fff;
-    margin: 50px auto 20px;
-    width: 1024px;
+    margin: 0 auto 20px;
+    max-width: 1024px;
     font-family: 'Roboto Condensed', sans-serif;
     font-weight: normal;
     font-size: 16px;
@@ -86,18 +87,18 @@ button::after, .btn::after {
     float: right;
     color: var(--border);
 }
-button.danger, .btn.danger {
+.danger {
     background-color: #381818;
     border-color: #821c1c;
 }
-button.danger::after, .btn.danger::after {
+.danger::after {
     color: #821c1c
 }
-button.success, .btn.success {
+.success {
     background-color: var(--green-bg);
     border-color: var(--green-border);
 }
-button.success::after, .btn.success::after{
+.success::after{
     color: #32821c;
 }
 button:active, .btn:active, button:hover, .btn:hover {
@@ -135,25 +136,38 @@ footer {
     margin-top: 2rem;
 }
 
-.nav {
+#nav, #nav ul {
     padding: 0;
     margin: 0;
 }
-.nav li {
+#nav ul {
+    display: flex;
+    justify-content: space-evenly;
+    align-items: center;
+}
+#nav li {
+    margin: 0;
     list-style: none;
+    display: inline-flex;
 }
-.nav li a {
-    display: block;
+#nav li a {
     padding: 10px 25px;
 }
-.nav li a:hover {
-    background-color: #0d2329;
+#nav li a:hover {
+    background-color: var(--border);
 }
-.nav li a::before {
+#nav li a::before {
     content: '';
 }
-.nav li a::after {
-    float: right;
+#nav li a::after {
+    content: '';
+}
+.alert {
+    padding: 10px;
+    font-size: 1rem;
+    margin-bottom: 1.2rem;
+    border-style: solid;
+    border-width: 1px;
 }
 
 /** Grid Stuff **/
@@ -208,9 +222,6 @@ form > div {
     --aug-border-all: 1px;
     --aug-border-bg: var(--border);
 }
-.nav {
-    margin-bottom: 1rem;
-}
 #main {
     background-color: var(--page-bg);
     padding: 1rem;
@@ -219,4 +230,23 @@ form > div {
 }
 #corp-ads {
     margin-top: 1rem;
+}
+#topbar {
+    margin-bottom: 50px;
+    padding: 0;
+    --aug-border-all: 1px;
+    --aug-border-bg: var(--border);
+    background: linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(28,114,130,0.5) 100%);
+}
+#topbar > .row {
+    border-bottom: solid 1px var(--blended-border);
+}
+#info-bar {
+    display: flex;
+    flex-basis: 40%;
+    border: solid 0 var(--border);
+    border-left-width: 1px;
+    padding: 10px 25px;
+    background-color: var(--page-bg);
+    justify-content: space-evenly;
 }
\ No newline at end of file
index 76873678c2d2741723ddcb932c702439760f9c08..5f48de443d383b76ec6375fd80d9ef63f0088a08 100644 (file)
@@ -47,7 +47,7 @@ server.post<{
        // lets create the city!
        await cityRepo.create(acct.id);
 
-       return `<p>You are all signed up! You can go ahead and log in</p>`;
+       return `<div class="alert success">You are all signed up! You can go ahead and log in</div>`;
 });
 
 server.post<{body: {username: string, password: string}}, void>('/login', async (req, raw, res) => {
@@ -137,7 +137,12 @@ server.post<{
                building_type: string
        }
 }, string>('/cost/construction', async req => {
-       const amount = parseInt(req.body.amount, 10);
+       const amount = parseInt(req.body.amount.trim(), 10);
+       console.log('checking amount', amount);
+
+       if(isNaN(amount) || amount < 1) {
+               return '';
+       }
        const building = await cityRepo.buildingRepository.findBySlug(req.body.building_type);
 
        if(!building) {
index 13545e41cee10fcab849fddde57a4909ba90f40a..00f41fa2b36da892f6e8b55bcaba1339d6a6d00a 100644 (file)
@@ -72,8 +72,10 @@ export class HttpServer {
                        }
                        catch(e) {
                                console.log(e);
-                               res.statusCode = (e as HttpError).statusCode || 500;
-                               res.json(e)
+                               //res.statusCode = (e as HttpError).statusCode || 500;
+                               res.send(`
+                               <div class="alert danger">${e.message}</div>
+                               `);
                        }
                        finally {
                                res.end();
index a4864a2e240033a3dcb4456ec5b9de256182ee4f..ee3fbe4d4dffbc989e08720f163146cfc26d250e 100644 (file)
@@ -3,6 +3,7 @@ import { DateTime } from "luxon";
 import { Account } from "../repository/accounts";
 import { ArmyQueueWithAttackedOwner } from "../repository/army";
 import { City, CityRepository, CityWithLocation } from "../repository/city";
+import { topbar } from "./topbar";
 
 const cityRepo = new CityRepository();
 
@@ -146,5 +147,5 @@ export async function launchOffensive(city: CityWithLocation, owner: Account, yo
     </form>
     `;
 
-    return html;
+    return html + topbar(yourCity);
 }
\ No newline at end of file
index d82f6a411d80042c23423a5fd1155f0aaf351eb8..9fd07ab18be444963af57fd5c82e0a4c69fa493e 100644 (file)
@@ -1,6 +1,7 @@
 import { Account } from "../repository/accounts";
 import { CityWithLocation } from "../repository/city";
 import * as _ from 'lodash';
+import { topbar } from "./topbar";
 
 export function renderKingomOverview(city: CityWithLocation, account: Account): string {
     return `
@@ -49,5 +50,5 @@ export function renderKingomOverview(city: CityWithLocation, account: Account):
        </tr>
        </table>
        </div>
-       `;
+       ${topbar(city)}`;
 }
\ No newline at end of file
index 935ff74dbdd74868b9dedda76480e209e9467f68..d5cc4e34baa72615a3d5fa1e99506c7ac617ff84 100644 (file)
@@ -2,6 +2,7 @@ import { BuildQueue } from "../repository/build-queue";
 import { CityWithLocation } from "../repository/city";
 import { Building } from '../repository/buildings';
 import _ from "lodash";
+import { topbar } from "./topbar";
 
 function progressBar(current, max): string {
     const percent = Math.ceil((current/max) * 100);
@@ -32,7 +33,7 @@ export function renderLandDevelopment(city: CityWithLocation, buildings: Buildin
                 <td>${city[building.slug]}</td>
                 <td>
                     <form hx-post="/build">
-                        <input type="number" size="6" name="amount" hx-post="/cost/construction" hx-trigger="change" hx-target="#${building.slug}-cost">
+                        <input type="number" size="6" name="amount" hx-post="/cost/construction" hx-trigger="keyup" hx-target="#${building.slug}-cost">
                         <input type="hidden" name="building_type" value="${building.slug}">
                         <button type="submit">Build</button>
                     </form>
@@ -73,6 +74,5 @@ export function renderLandDevelopment(city: CityWithLocation, buildings: Buildin
     </table>
     </div>
     `;
-
-    return html + queues;
+    return html + queues + topbar(city);
 }
\ No newline at end of file
index 7c20cc5d1a0657a416b02d4cfa8918bcbd53679f..271eed9f70e136cf96baad6e964e9ac552886c49 100644 (file)
@@ -1,5 +1,6 @@
 import { DateTime } from "luxon";
 import { MessageWithNames } from "../repository/mail";
+import { topbar } from "./topbar";
 
 export function renderMailroom(mail: MessageWithNames[]): string {
     return `
diff --git a/src/render/topbar.ts b/src/render/topbar.ts
new file mode 100644 (file)
index 0000000..e126137
--- /dev/null
@@ -0,0 +1,13 @@
+import { City } from "../repository/city";
+
+export function topbar(city: City): string {
+    const oob = `
+    <div class="col" id="info-bar" hx-swap-oob="true">
+    <span><b>Gold:</b> ${city.gold.toLocaleString()}</span>
+    <span><b>Ore:</b> ${city.ore.toLocaleString()}</span>
+    <span><b>Logs:</b> ${city.logs.toLocaleString()}</span>
+    </div>
+    `;
+
+    return oob;
+}
\ No newline at end of file
index 5b4ffcf026cd3d0613af6f76c5ac3da2f73c0c9d..bfed36e2cd33cca3d346141b203327a92370b239 100644 (file)
@@ -2,6 +2,7 @@ import _ from "lodash";
 import { CityWithLocation } from "../repository/city";
 import { UnitTrainingQueue } from "../repository/training-queue";
 import { Unit } from "../repository/unit";
+import { topbar } from "./topbar";
 
 function progressBar(current, max): string {
     const percent = Math.ceil((current/max) * 100);
@@ -114,5 +115,5 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini
     </div>
     `;
 
-    return html + queues;
+    return html + queues + topbar(city);
 }
\ No newline at end of file