Small improvement
This commit is contained in:
parent
ef79a9371f
commit
c393582978
@ -3,6 +3,7 @@ import { Mathuscript, parseMathuscript } from "./parse";
|
|||||||
import katex from "katex";
|
import katex from "katex";
|
||||||
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||||
import { MathText } from "./MathText";
|
import { MathText } from "./MathText";
|
||||||
|
import { characterData } from "./data";
|
||||||
|
|
||||||
type VisualState = {
|
type VisualState = {
|
||||||
characters: {name: string, emotion: string, x: number}[],
|
characters: {name: string, emotion: string, x: number}[],
|
||||||
@ -19,6 +20,7 @@ const afterStep = (state: VisualState, step: Mathuscript[number]): VisualState =
|
|||||||
let char = characters.find(c => c.name === step.name);
|
let char = characters.find(c => c.name === step.name);
|
||||||
if (!char) {
|
if (!char) {
|
||||||
char = {name: step.name, emotion: "default", x: 0.5};
|
char = {name: step.name, emotion: "default", x: 0.5};
|
||||||
|
characters.push(char);
|
||||||
}
|
}
|
||||||
char.emotion = step.emotion ?? char.emotion;
|
char.emotion = step.emotion ?? char.emotion;
|
||||||
dialog.name = step.name;
|
dialog.name = step.name;
|
||||||
@ -28,6 +30,13 @@ const afterStep = (state: VisualState, step: Mathuscript[number]): VisualState =
|
|||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getCharData = (name: string | null) => {
|
||||||
|
if (name && name in characterData) {
|
||||||
|
return characterData[name as keyof typeof characterData];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export const MathuscriptPlayer = (props: { script: string }) => {
|
export const MathuscriptPlayer = (props: { script: string }) => {
|
||||||
const {script} = props;
|
const {script} = props;
|
||||||
const parsedScript = useMemo(() => parseMathuscript(script), [script]);
|
const parsedScript = useMemo(() => parseMathuscript(script), [script]);
|
||||||
@ -45,6 +54,8 @@ export const MathuscriptPlayer = (props: { script: string }) => {
|
|||||||
}
|
}
|
||||||
}, [index, parsedScript, setIndex, setVisualState]);
|
}, [index, parsedScript, setIndex, setVisualState]);
|
||||||
|
|
||||||
|
const speakingChar = getCharData(visualState.dialog.name);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={css`
|
<div className={css`
|
||||||
@ -58,6 +69,7 @@ export const MathuscriptPlayer = (props: { script: string }) => {
|
|||||||
background-size: 118%;
|
background-size: 118%;
|
||||||
background-position-x: center;
|
background-position-x: center;
|
||||||
background-position-y: bottom;
|
background-position-y: bottom;
|
||||||
|
overflow: hidden;
|
||||||
`}>
|
`}>
|
||||||
<div className={css`
|
<div className={css`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -76,6 +88,33 @@ export const MathuscriptPlayer = (props: { script: string }) => {
|
|||||||
<MathText>{visualState.board.text}</MathText>
|
<MathText>{visualState.board.text}</MathText>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className={css`
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
`}>
|
||||||
|
{
|
||||||
|
visualState.characters.map(c => {
|
||||||
|
// TODO: make it change with emotion
|
||||||
|
const char = getCharData(c.name);
|
||||||
|
if (!char) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return <img
|
||||||
|
className={css`
|
||||||
|
position: absolute;
|
||||||
|
left: -20%;
|
||||||
|
height: 90%;
|
||||||
|
bottom: 0;
|
||||||
|
`}
|
||||||
|
key={c.name}
|
||||||
|
src={char.assets["default"]}
|
||||||
|
/>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</div>
|
||||||
<div className={css`
|
<div className={css`
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -94,8 +133,8 @@ export const MathuscriptPlayer = (props: { script: string }) => {
|
|||||||
color: white;
|
color: white;
|
||||||
`}>
|
`}>
|
||||||
{
|
{
|
||||||
visualState.dialog.name && <>
|
speakingChar && <>
|
||||||
<strong>{visualState.dialog.name}.</strong> <MathText>{visualState.dialog.text}</MathText>
|
<strong>{speakingChar.displayName}.</strong> <MathText>{visualState.dialog.text}</MathText>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
16
src/client/player/data.ts
Normal file
16
src/client/player/data.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
export const characterData = {
|
||||||
|
bridget: {
|
||||||
|
displayName: "Bridget",
|
||||||
|
assets: {
|
||||||
|
default: "/assets/bridget.png",
|
||||||
|
fallback: "/assets/bridget.png",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
axelle: {
|
||||||
|
displayName: "Axelle",
|
||||||
|
assets: {
|
||||||
|
default: "/assets/bridget.png",
|
||||||
|
fallback: "/assets/bridget.png",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user