From bd901e9cb3598e2837a617c03223bb1616c596e3 Mon Sep 17 00:00:00 2001 From: Adam Balan Date: Fri, 1 Nov 2024 12:58:26 -0600 Subject: [PATCH] Split up the icons and the monster section into components with types and deffintions --- .../js/phoniex/components/actions/actions.tsx | 246 +----------------- .../attack-buttons-container.tsx | 12 + .../fight-section/attack-messages.tsx | 47 ++++ .../attack-message-deffinition.ts | 6 + .../enums/attack-message-type.ts | 5 + .../fight-section/enums/health-bar-type.ts | 4 + .../fight-section/health-bar-container.tsx | 17 ++ .../components/fight-section/health-bar.tsx | 54 ++++ .../fight-section/monster-top-section.tsx | 67 +++++ .../types/attack-buttons-container-props.ts | 5 + .../types/attack-messages-props.ts | 5 + .../types/health-bar-container-props.ts | 5 + .../fight-section/types/health-bar-props.ts | 8 + .../types/monster-top-section-props.ts | 7 + .../components/icon-section/floating-card.tsx | 29 +++ .../icon-section/icon-container.tsx | 14 + .../icon-section/types/floating-card-props.ts | 7 + .../types/icon-container-props.ts | 5 + .../actions/partials/icon-section.tsx | 57 ++++ .../actions/partials/monster-section.tsx | 100 +++++++ 20 files changed, 458 insertions(+), 242 deletions(-) create mode 100644 resources/js/phoniex/components/actions/components/fight-section/attack-buttons-container.tsx create mode 100644 resources/js/phoniex/components/actions/components/fight-section/attack-messages.tsx create mode 100644 resources/js/phoniex/components/actions/components/fight-section/deffinitions/attack-message-deffinition.ts create mode 100644 resources/js/phoniex/components/actions/components/fight-section/enums/attack-message-type.ts create mode 100644 resources/js/phoniex/components/actions/components/fight-section/enums/health-bar-type.ts create mode 100644 resources/js/phoniex/components/actions/components/fight-section/health-bar-container.tsx create mode 100644 resources/js/phoniex/components/actions/components/fight-section/health-bar.tsx create mode 100644 resources/js/phoniex/components/actions/components/fight-section/monster-top-section.tsx create mode 100644 resources/js/phoniex/components/actions/components/fight-section/types/attack-buttons-container-props.ts create mode 100644 resources/js/phoniex/components/actions/components/fight-section/types/attack-messages-props.ts create mode 100644 resources/js/phoniex/components/actions/components/fight-section/types/health-bar-container-props.ts create mode 100644 resources/js/phoniex/components/actions/components/fight-section/types/health-bar-props.ts create mode 100644 resources/js/phoniex/components/actions/components/fight-section/types/monster-top-section-props.ts create mode 100644 resources/js/phoniex/components/actions/components/icon-section/floating-card.tsx create mode 100644 resources/js/phoniex/components/actions/components/icon-section/icon-container.tsx create mode 100644 resources/js/phoniex/components/actions/components/icon-section/types/floating-card-props.ts create mode 100644 resources/js/phoniex/components/actions/components/icon-section/types/icon-container-props.ts create mode 100644 resources/js/phoniex/components/actions/partials/icon-section.tsx create mode 100644 resources/js/phoniex/components/actions/partials/monster-section.tsx diff --git a/resources/js/phoniex/components/actions/actions.tsx b/resources/js/phoniex/components/actions/actions.tsx index ad7e4d696..ca9a0a84f 100644 --- a/resources/js/phoniex/components/actions/actions.tsx +++ b/resources/js/phoniex/components/actions/actions.tsx @@ -1,255 +1,17 @@ import React from "react"; import Card from "../../ui/cards/card"; -import LinkButton from "../../ui/buttons/link-button"; -import { ButtonVariant } from "../../ui/buttons/enums/button-variant-enum"; -import Button from "../../ui/buttons/button"; -import GradientButton from "../../ui/buttons/gradient-button"; -import { ButtonGradientVarient } from "../../ui/buttons/enums/button-gradient-variant"; -import Seperator from "../../ui/seperatror/seperator"; -import IconButton from "../../ui/buttons/icon-button"; +import IconSection from "./partials/icon-section"; +import MonsterSection from "./partials/monster-section"; export default class Actions extends React.Component { render() { return (
- {/* Icon Container */} -
-
-
-
- - {/* Content Area */}
- A cute cat -
- - Monster Name - -
-
- {}} - /> -
-
-
-
-
- - Monster Name - - Monster Name - - 100/100 - -
-
-
-
-
-
-
- - Character Name - - Character Name - - 100/100 - -
-
-
-
-
-
-
-
-
- -
- {}} - /> - {}} - /> -
- -
-
- - -
-
-
- You hit for 5,000 Damage! -
-
- Your enchantments glow with rage! -
-
- You hit for 5,000 Enchanted Damage! -
-
- Your enemy hits you for 50,000 Damage! -
-
-
+
diff --git a/resources/js/phoniex/components/actions/components/fight-section/attack-buttons-container.tsx b/resources/js/phoniex/components/actions/components/fight-section/attack-buttons-container.tsx new file mode 100644 index 000000000..2b6774cad --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/attack-buttons-container.tsx @@ -0,0 +1,12 @@ +import React from "react"; +import AttackButtonsContainerProps from "./types/attack-buttons-container-props"; + +export default class AttackButtonsContainer extends React.Component { + render() { + return ( +
+ {this.props.children} +
+ ); + } +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/attack-messages.tsx b/resources/js/phoniex/components/actions/components/fight-section/attack-messages.tsx new file mode 100644 index 000000000..b14831410 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/attack-messages.tsx @@ -0,0 +1,47 @@ +import React, { ReactNode } from "react"; +import AttackMessagesProps from "./types/attack-messages-props"; +import AttackMessageDeffintion from "./deffinitions/attack-message-deffinition"; +import { AttackMessageType } from "./enums/attack-message-type"; +import { match } from "ts-pattern"; + +export default class AttackMessages extends React.Component { + renderMessages(): ReactNode[] | [] { + return this.props.messages.map((message: AttackMessageDeffintion) => { + const messageColor = this.fetchColorForType(message.type); + + return
{message.message}
; + }); + } + + fetchColorForType(type: AttackMessageType): string { + return match(type) + .with( + AttackMessageType.ENEMY_ATTACK, + () => "text-rose-700 dark:text-rose-500", + ) + .with( + AttackMessageType.PLAYER_ATTACK, + () => "text-emerald-700 dark:text-emerald-500", + ) + .with( + AttackMessageType.REGULAR, + () => "text-danube-700 dark:text-danube-500", + ) + .otherwise(() => ""); + } + + render() { + return ( +
+
+ {this.renderMessages()} +
+
+ ); + } +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/deffinitions/attack-message-deffinition.ts b/resources/js/phoniex/components/actions/components/fight-section/deffinitions/attack-message-deffinition.ts new file mode 100644 index 000000000..72e8770d3 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/deffinitions/attack-message-deffinition.ts @@ -0,0 +1,6 @@ +import { AttackMessageType } from "../enums/attack-message-type"; + +export default interface AttackMessageDeffintion { + message: string; + type: AttackMessageType; +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/enums/attack-message-type.ts b/resources/js/phoniex/components/actions/components/fight-section/enums/attack-message-type.ts new file mode 100644 index 000000000..d93e6fbc9 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/enums/attack-message-type.ts @@ -0,0 +1,5 @@ +export enum AttackMessageType { + PLAYER_ATTACK = "player-attack", + ENEMY_ATTACK = "enemy-attack", + REGULAR = "regular", +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/enums/health-bar-type.ts b/resources/js/phoniex/components/actions/components/fight-section/enums/health-bar-type.ts new file mode 100644 index 000000000..f7ca77388 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/enums/health-bar-type.ts @@ -0,0 +1,4 @@ +export enum HealthBarType { + ENEMY, + PLAYER, +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/health-bar-container.tsx b/resources/js/phoniex/components/actions/components/fight-section/health-bar-container.tsx new file mode 100644 index 000000000..58a152d10 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/health-bar-container.tsx @@ -0,0 +1,17 @@ +import React from "react"; +import HealthBarContainerProps from "./types/health-bar-container-props"; + +export default class HealthBarContainer extends React.Component { + render() { + return ( +
+
{this.props.children}
+
+ ); + } +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/health-bar.tsx b/resources/js/phoniex/components/actions/components/fight-section/health-bar.tsx new file mode 100644 index 000000000..3ccad2d57 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/health-bar.tsx @@ -0,0 +1,54 @@ +import React from "react"; +import HealthBarProps from "./types/health-bar-props"; +import { match } from "ts-pattern"; +import { HealthBarType } from "./enums/health-bar-type"; +import clsx from "clsx"; + +export default class HealthBar extends React.Component { + healthBarPercentage() { + return ( + (this.props.current_health / this.props.max_health) * + 100 + ).toFixed(0); + } + + fetchColor(): string { + console.log(this.props.health_bar_type); + return match(this.props.health_bar_type) + .with(HealthBarType.ENEMY, () => "bg-rose-600 dark:bg-rose-500") + .with( + HealthBarType.PLAYER, + () => "bg-emerald-600 dark:bg-emerald-500", + ) + .otherwise(() => ""); + } + + render() { + return ( +
+
+ + {this.props.name} + + {this.props.name} + + {this.props.current_health}/{this.props.max_health} + +
+
+
+
+
+ ); + } +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/monster-top-section.tsx b/resources/js/phoniex/components/actions/components/fight-section/monster-top-section.tsx new file mode 100644 index 000000000..9d7cd5373 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/monster-top-section.tsx @@ -0,0 +1,67 @@ +import React from "react"; +import LinkButton from "../../../../ui/buttons/link-button"; +import { ButtonVariant } from "../../../../ui/buttons/enums/button-variant-enum"; +import MonsterTopSectionProps from "./types/monster-top-section-props"; + +export default class MonsterTopSection extends React.Component { + render() { + return ( + <> + A cute cat +
+ + + {this.props.monster_name} + + +
+ +
+ this.props.view_stats_action(1)} + /> +
+ + ); + } +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/types/attack-buttons-container-props.ts b/resources/js/phoniex/components/actions/components/fight-section/types/attack-buttons-container-props.ts new file mode 100644 index 000000000..a59156f3c --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/types/attack-buttons-container-props.ts @@ -0,0 +1,5 @@ +import { ReactNode } from "react"; + +export default interface AttackButtonsContainerProps { + children: ReactNode | ReactNode[]; +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/types/attack-messages-props.ts b/resources/js/phoniex/components/actions/components/fight-section/types/attack-messages-props.ts new file mode 100644 index 000000000..3d2227893 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/types/attack-messages-props.ts @@ -0,0 +1,5 @@ +import AttackMessageDeffintion from "../deffinitions/attack-message-deffinition"; + +export default interface AttackMessagesProps { + messages: AttackMessageDeffintion[] | []; +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/types/health-bar-container-props.ts b/resources/js/phoniex/components/actions/components/fight-section/types/health-bar-container-props.ts new file mode 100644 index 000000000..7f613c026 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/types/health-bar-container-props.ts @@ -0,0 +1,5 @@ +import { ReactNode } from "react"; + +export default interface HealthBarContainerProps { + children: ReactNode[] | []; +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/types/health-bar-props.ts b/resources/js/phoniex/components/actions/components/fight-section/types/health-bar-props.ts new file mode 100644 index 000000000..c04c66543 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/types/health-bar-props.ts @@ -0,0 +1,8 @@ +import { HealthBarType } from "../enums/health-bar-type"; + +export default interface HealthBarProps { + name: string; + current_health: number; + max_health: number; + health_bar_type: HealthBarType; +} diff --git a/resources/js/phoniex/components/actions/components/fight-section/types/monster-top-section-props.ts b/resources/js/phoniex/components/actions/components/fight-section/types/monster-top-section-props.ts new file mode 100644 index 000000000..eccd36d4f --- /dev/null +++ b/resources/js/phoniex/components/actions/components/fight-section/types/monster-top-section-props.ts @@ -0,0 +1,7 @@ +export default interface MonsterTopSectionProps { + img_src: string; + monster_name: string; + next_action: (currentIndex: number) => {}; + prev_action: (currentIndex: number) => {}; + view_stats_action: (monsterId: number) => {}; +} diff --git a/resources/js/phoniex/components/actions/components/icon-section/floating-card.tsx b/resources/js/phoniex/components/actions/components/icon-section/floating-card.tsx new file mode 100644 index 000000000..d7ae55f67 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/icon-section/floating-card.tsx @@ -0,0 +1,29 @@ +import React from "react"; +import FloatingCardProps from "./types/floating-card-props"; + +export default class FloatingCard extends React.Component { + render() { + return ( +
+
+

+ {this.props.title} +

+ +
+
+ {this.props.children} +
+
+ ); + } +} diff --git a/resources/js/phoniex/components/actions/components/icon-section/icon-container.tsx b/resources/js/phoniex/components/actions/components/icon-section/icon-container.tsx new file mode 100644 index 000000000..04f358fde --- /dev/null +++ b/resources/js/phoniex/components/actions/components/icon-section/icon-container.tsx @@ -0,0 +1,14 @@ +import React from "react"; +import IconContainerProps from "./types/icon-container-props"; + +export default class IconContainer extends React.Component { + render() { + return ( +
+
+ {this.props.children} +
+
+ ); + } +} diff --git a/resources/js/phoniex/components/actions/components/icon-section/types/floating-card-props.ts b/resources/js/phoniex/components/actions/components/icon-section/types/floating-card-props.ts new file mode 100644 index 000000000..8e680ab57 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/icon-section/types/floating-card-props.ts @@ -0,0 +1,7 @@ +import { ReactNode } from "react"; + +export default interface FloatingCardProps { + title: string; + close_action: () => void; + children: ReactNode | ReactNode[]; +} diff --git a/resources/js/phoniex/components/actions/components/icon-section/types/icon-container-props.ts b/resources/js/phoniex/components/actions/components/icon-section/types/icon-container-props.ts new file mode 100644 index 000000000..f7d6b91f0 --- /dev/null +++ b/resources/js/phoniex/components/actions/components/icon-section/types/icon-container-props.ts @@ -0,0 +1,5 @@ +import { ReactNode } from "react"; + +export default interface IconContainerProps { + children: ReactNode | ReactNode[]; +} diff --git a/resources/js/phoniex/components/actions/partials/icon-section.tsx b/resources/js/phoniex/components/actions/partials/icon-section.tsx new file mode 100644 index 000000000..0b0f3750f --- /dev/null +++ b/resources/js/phoniex/components/actions/partials/icon-section.tsx @@ -0,0 +1,57 @@ +import React from "react"; +import IconContainer from "../components/icon-section/icon-container"; +import IconButton from "../../../ui/buttons/icon-button"; +import { ButtonVariant } from "../../../ui/buttons/enums/button-variant-enum"; +import FloatingCard from "../components/icon-section/floating-card"; + +export default class IconSection extends React.Component { + render() { + return ( + + + ); + } +} diff --git a/resources/js/phoniex/components/actions/partials/monster-section.tsx b/resources/js/phoniex/components/actions/partials/monster-section.tsx new file mode 100644 index 000000000..5374b6075 --- /dev/null +++ b/resources/js/phoniex/components/actions/partials/monster-section.tsx @@ -0,0 +1,100 @@ +import React from "react"; +import MonsterTopSection from "../components/fight-section/monster-top-section"; +import AttackButtonsContainer from "../components/fight-section/attack-buttons-container"; +import HealthBarContainer from "../components/fight-section/health-bar-container"; +import HealthBar from "../components/fight-section/health-bar"; +import { HealthBarType } from "../components/fight-section/enums/health-bar-type"; +import Button from "../../../ui/buttons/button"; +import { ButtonVariant } from "../../../ui/buttons/enums/button-variant-enum"; +import GradientButton from "../../../ui/buttons/gradient-button"; +import { ButtonGradientVarient } from "../../../ui/buttons/enums/button-gradient-variant"; +import Seperator from "../../../ui/seperatror/seperator"; +import AttackMessages from "../components/fight-section/attack-messages"; +import AttackMessageDeffintion from "../components/fight-section/deffinitions/attack-message-deffinition"; +import { AttackMessageType } from "../components/fight-section/enums/attack-message-type"; + +export default class MonsterSection extends React.Component { + messages(): AttackMessageDeffintion[] { + return [ + { + message: "You Attack for 150,000 Damage!", + type: AttackMessageType.PLAYER_ATTACK, + }, + { + message: "Your spells charge and magic crackles in the air!", + type: AttackMessageType.REGULAR, + }, + { + message: + "The enemy stops your spells and attack you for 125,000 Damage", + type: AttackMessageType.ENEMY_ATTACK, + }, + ]; + } + + render() { + return ( + <> + (currentIndex: number) => {}} + prev_action={() => (currentIndex: number) => {}} + view_stats_action={() => (monsterId: number) => {}} + monster_name="Sewer Rat" + /> + + + + + +