From 7b086654272738e16307f18aaa7e8ea7d3f62d22 Mon Sep 17 00:00:00 2001 From: mehbark Date: Wed, 12 Jul 2023 07:52:26 -0400 Subject: [PATCH] fight done enough, gonna hack in a timer --- html/common.tsx | 5 +++ html/eggbug-spamclick-battle.tsx | 55 ++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/html/common.tsx b/html/common.tsx index 0161ae6..52abd38 100644 --- a/html/common.tsx +++ b/html/common.tsx @@ -15,3 +15,8 @@ export const HCenter: Component = (attributes, children) => ( {...children} ); + +export const styles = (s: Record): string => + Object.entries(s) + .map(([rule, val]) => `${rule}: ${val};`) + .join(""); diff --git a/html/eggbug-spamclick-battle.tsx b/html/eggbug-spamclick-battle.tsx index d805e45..936e06d 100644 --- a/html/eggbug-spamclick-battle.tsx +++ b/html/eggbug-spamclick-battle.tsx @@ -1,4 +1,4 @@ -import { HCenter, Main } from "./common.tsx"; +import { HCenter, Main, styles } from "./common.tsx"; import { debug_render } from "./html.ts"; import { Component } from "./jsx/jsx-runtime.ts"; @@ -17,9 +17,10 @@ function health_style(current: number, last: number, max: number) { const dhealth = last - current; console.log(inc_width, dhealth); - return `transform: translateX(${-(inc_width * dhealth)}%); width: ${ - last * inc_width - }%;`; + return styles({ + transform: `translateX(${-(inc_width * dhealth)}%)`, + width: `${last * inc_width}%`, + }); } // could be generalized @@ -34,8 +35,12 @@ const Health: Component = ({ current, last, max }) => ( style={health_style(current, last, max)} > - {Math.floor(current).toString()} - /{max.toString()} + + + {Math.floor(current).toString()} + + /{max.toString()} + ) ); @@ -51,8 +56,30 @@ const BattleFrame: Component = ({ health, last_health, max_health, msg }) => ( const Defeated: Component = ({ last_health, max_health }) => (
- - defeated... + + eggbug is physically unharmed, emotionally destroyed
+ ...
+ ok eggbug is fine now
+ "reeadbug" to "killbug" +
+); + +const DamageNumber: Component = ({ n }) => ( +
+
{Math.round(n).toString()}
); @@ -72,6 +99,9 @@ const Battle: Component = ({ last_health={last_health} max_health={max_health} /> + {health < last_health && ( + + )} ); +// a timer would be flippin rad +// (it would look like an actual scrolling clock thingie) +// (because it would have to) debug_render(
- +
);