text chat integration
This commit is contained in:
1 parent
d5362e71b9
commit
98a7a2d774
2 files changed
+33
-1
No files matched your search
@@ -26,4 +26,13 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatRow {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
|
||||||
|
input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import styles from "./CharacterSheetApp.module.scss";
|
import styles from "./CharacterSheetApp.module.scss";
|
||||||
|
|
||||||
const modifier = (score: number) => Math.floor((score - 10) / 2);
|
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 }) {
|
export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) {
|
||||||
const system = actor.system;
|
const system = actor.system;
|
||||||
const attrs = system.attributes;
|
const attrs = system.attributes;
|
||||||
|
const [chatMessage, setChatMessage] = useState("");
|
||||||
|
|
||||||
const updateAttribute = (key: "strength" | "agility" | "spirit", value: number) => {
|
const updateAttribute = (key: "strength" | "agility" | "spirit", value: number) => {
|
||||||
actor.update({ system: { attributes: { [key]: value } } });
|
actor.update({ system: { attributes: { [key]: value } } });
|
||||||
@@ -16,6 +17,15 @@ export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) {
|
|||||||
actor.update({ system: { biography: value } });
|
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
|
// derived purely from current doc state — recomputed every render, no local state needed
|
||||||
const total = attrs.strength + attrs.agility + attrs.spirit;
|
const total = attrs.strength + attrs.agility + attrs.spirit;
|
||||||
const totalMod = modifier(attrs.strength) + modifier(attrs.agility) + modifier(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)}
|
onBlur={(e) => updateBiography(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<div className={styles.chatRow}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Say something..."
|
||||||
|
value={chatMessage}
|
||||||
|
onChange={(e) => setChatMessage(e.target.value)}
|
||||||
|
onKeyDown={(e) => e.key === "Enter" && sendChatMessage()}
|
||||||
|
/>
|
||||||
|
<button type="button" onClick={sendChatMessage}>
|
||||||
|
Send to chat
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user