From 4732b97d654074bc512189388861dd826acc066a Mon Sep 17 00:00:00 2001 From: mehbark Date: Wed, 12 Jul 2023 07:05:48 -0400 Subject: [PATCH] finally functional skeleton --- html/common.tsx | 10 ++++ html/eggbug-spamclick-battle.tsx | 98 ++++++++++++++++++++++++++++++-- html/html.ts | 6 +- 3 files changed, 105 insertions(+), 9 deletions(-) diff --git a/html/common.tsx b/html/common.tsx index 9d32c21..0161ae6 100644 --- a/html/common.tsx +++ b/html/common.tsx @@ -5,3 +5,13 @@ export const Main: Component = (attributes, children) => ( {...children} ); + +export const HCenter: Component = (attributes, children) => ( +
+ {...children} +
+); diff --git a/html/eggbug-spamclick-battle.tsx b/html/eggbug-spamclick-battle.tsx index 287bcf0..d805e45 100644 --- a/html/eggbug-spamclick-battle.tsx +++ b/html/eggbug-spamclick-battle.tsx @@ -1,12 +1,98 @@ +import { HCenter, Main } from "./common.tsx"; import { debug_render } from "./html.ts"; import { Component } from "./jsx/jsx-runtime.ts"; const Eggbug: Component = () => ( - eggbug, smiling + + eggbug, smiling + ); -debug_render(); +function health_style(current: number, last: number, max: number) { + const inc_width = 100 / max; + const dhealth = last - current; + console.log(inc_width, dhealth); + + return `transform: translateX(${-(inc_width * dhealth)}%); width: ${ + last * inc_width + }%;`; +} + +// could be generalized +// might be worthwhile later since is BAN +const Health: Component = ({ current, last, max }) => ( + console.log({ current, last, max }), + ( +
+
+
+
+ {Math.floor(current).toString()} + /{max.toString()} +
+ ) +); +// one-time animations of hit numbers of health flying off the screen + +const BattleFrame: Component = ({ health, last_health, max_health, msg }) => ( +
+ + +
+); + +const Defeated: Component = ({ last_health, max_health }) => ( +
+ + + defeated... +
+); + +const Battle: Component = ({ + max_health = 100, + health = max_health, + last_health = health, + damage_multiplier = 10, + damage_bonus = 1, + ...rest +}) => + health > 0 ? ( +
+ + + + +
+ ) : ( + + ); + +debug_render( +
+ +
+); diff --git a/html/html.ts b/html/html.ts index de97f2c..0e91bc1 100644 --- a/html/html.ts +++ b/html/html.ts @@ -93,12 +93,12 @@ function render_elem( mini = false, ): string { if (children.length == 0) { - if (!NON_SELF_CLOSING.includes(tag)) { + if (NON_SELF_CLOSING.includes(tag)) { + return `<${tag}${render_attributes(attributes)}>`; + } else { return ( `<${tag}${render_attributes(attributes)}` + (mini ? "/>" : " />") ); - } else { - return `<${tag}${render_attributes(attributes)}>`; } } else { let inner = "";