From 98a7a2d7745239a825bb70c8bec27d318deb3df7 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Jun 2026 22:52:33 +0200 Subject: [PATCH] text chat integration --- .../components/CharacterSheetApp.module.scss | 9 +++++++ src/sheets/components/CharacterSheetApp.tsx | 25 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/sheets/components/CharacterSheetApp.module.scss b/src/sheets/components/CharacterSheetApp.module.scss index b81c0e7..fc2ddcc 100644 --- a/src/sheets/components/CharacterSheetApp.module.scss +++ b/src/sheets/components/CharacterSheetApp.module.scss @@ -26,4 +26,13 @@ display: flex; gap: 1rem; font-weight: bold; +} + +.chatRow { + display: flex; + gap: 0.5rem; + + input { + flex: 1; + } } \ No newline at end of file diff --git a/src/sheets/components/CharacterSheetApp.tsx b/src/sheets/components/CharacterSheetApp.tsx index b6d9f1b..a50eddd 100644 --- a/src/sheets/components/CharacterSheetApp.tsx +++ b/src/sheets/components/CharacterSheetApp.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import styles from "./CharacterSheetApp.module.scss"; const modifier = (score: number) => Math.floor((score - 10) / 2); @@ -7,6 +7,7 @@ const fmtMod = (mod: number) => (mod >= 0 ? `+${mod}` : `${mod}`); export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) { const system = actor.system; const attrs = system.attributes; + const [chatMessage, setChatMessage] = useState(""); const updateAttribute = (key: "strength" | "agility" | "spirit", value: number) => { actor.update({ system: { attributes: { [key]: value } } }); @@ -16,6 +17,15 @@ export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) { actor.update({ system: { biography: value } }); }; + const sendChatMessage = () => { + if (!chatMessage.trim()) return; + ChatMessage.create({ + speaker: ChatMessage.getSpeaker({ actor }), + content: chatMessage + }); + setChatMessage(""); + }; + // derived purely from current doc state — recomputed every render, no local state needed const total = attrs.strength + attrs.agility + attrs.spirit; const totalMod = modifier(attrs.strength) + modifier(attrs.agility) + modifier(attrs.spirit); @@ -47,6 +57,19 @@ export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) { onBlur={(e) => updateBiography(e.target.value)} /> + +
+ setChatMessage(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && sendChatMessage()} + /> + +
); }