Skip to content

Commit

Permalink
Added bgm name in script viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
squaresmile committed Aug 9, 2024
1 parent 519eda5 commit bb48ca0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 42 deletions.
8 changes: 6 additions & 2 deletions packages/api-connector/src/ApiConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,12 @@ class ApiConnector {
);
}

bgm(id: number, cacheDuration?: number): Promise<BgmEntity> {
const query = this.getQueryString(new URLSearchParams());
bgm(id: number, cacheDuration?: number, fileName?: string): Promise<BgmEntity> {
const params = new URLSearchParams();
if (fileName) {
params.append("fileName", fileName);
}
const query = this.getQueryString(params);
const fetch = () => {
return ApiConnector.fetch<BgmEntity>(`${this.host}/nice/${this.region}/bgm/${id}${query}`);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/Api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Api {
apiConnector = new ApiConnector({ host: Host, region, language });
}

static bgm(id: number): Promise<Bgm.BgmEntity> {
return apiConnector.bgm(id, cacheDuration);
static bgm(id: number, fileName?: string): Promise<Bgm.BgmEntity> {
return apiConnector.bgm(id, cacheDuration, fileName);
}

static bgmList(): Promise<Bgm.BgmEntity[]> {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/Component/ScriptDialogueLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";

import { Region } from "@atlasacademy/api-connector";

import BgmDescriptor from "../Descriptor/BgmDescriptor";
import { BgmDescriptorFileName } from "../Descriptor/BgmDescriptor";
import { FGOText } from "../Helper/StringHelper";
import { useImageSize } from "../Hooks/useImageSize";
import { lang } from "../Setting/Manager";
Expand Down Expand Up @@ -227,7 +227,7 @@ export const DialogueChild = ({
case ScriptComponentType.DIALOGUE_TEXT_IMAGE:
return <DialogueBasic region={region} component={component} index={index} wideScreen={wideScreen} />;
case ScriptComponentType.BGM:
return <BgmDescriptor region={region} bgm={component.bgm} style={{ padding: "0 0.5em" }} />;
return <BgmDescriptorFileName region={region} bgm={component.bgm} style={{ padding: "0 0.5em" }} />;
default:
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/Component/ScriptTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next";

import { Region } from "@atlasacademy/api-connector";

import BgmDescriptor from "../Descriptor/BgmDescriptor";
import BgmDescriptor, { BgmDescriptorFileName } from "../Descriptor/BgmDescriptor";
import QuestDescriptor from "../Descriptor/QuestDescriptor";
import { useImageSize } from "../Hooks/useImageSize";
import useWindowDimensions from "../Hooks/useWindowDimensions";
Expand Down Expand Up @@ -534,7 +534,7 @@ const ScriptBracketRow = (props: {
<tr ref={refs.get(component.bgm.audioAsset)}>
<td>{t("BGM")}</td>
<td colSpan={colSpan}>
<BgmDescriptor region={region} bgm={component.bgm} />
<BgmDescriptorFileName region={region} bgm={component.bgm} />
</td>
{showScriptLine && <td className="text-center">{lineNumber}</td>}
</tr>
Expand Down
56 changes: 22 additions & 34 deletions packages/db/src/Descriptor/BgmDescriptor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,41 @@ export const getBgmName = (bgm: Bgm.Bgm) => {
}
};

export const BgmDescriptorId = ({
region,
bgmId,
showName,
showLink,
style,
className,
}: {
interface BgmProps {
region: Region;
bgmId: number;
showName?: string;
showLink?: boolean;
style?: React.CSSProperties;
className?: string;
}) => {
const { data: bgm } = useApi("bgm", bgmId);
}

export const BgmDescriptorId = (props: BgmProps & { bgmId: number }) => {
const { data: bgm } = useApi("bgm", props.bgmId);
if (bgm === undefined) return <></>;

return (
<BgmDescriptor
region={region}
bgm={bgm}
showName={showName}
showLink={showLink}
style={style}
className={className}
/>
);
return <BgmDescriptor {...props} bgm={bgm} />;
};

export default function BgmDescriptor(props: {
region: Region;
bgm: Bgm.Bgm;
showName?: string;
showLink?: boolean;
style?: React.CSSProperties;
className?: string;
}) {
const { bgm, region, className } = props;
export const BgmDescriptorFileName = (props: BgmProps & { bgm: Bgm.Bgm }) => {
const { data: bgmApi } = useApi("bgm", -1, props.bgm.fileName);

if (bgmApi === undefined) {
return <BgmDescriptor {...props} />;
} else {
return <BgmDescriptor {...props} bgm={bgmApi} />;
}
};

export default function BgmDescriptor(props: BgmProps & { bgm: Bgm.Bgm }) {
const { bgm, region, className, style } = props;
if (bgm.id === 0) {
return null;
} else if (bgm.audioAsset !== undefined) {
const showName = getBgmName(bgm);
const toLink = props.showLink ? (
<>
<Button variant="primary" as={Link} to={`/${props.region}/bgm/${bgm.id}`}>
<FontAwesomeIcon icon={faShare} title={`Go to ${props.region} BGM ${showName}`} />
<Button variant="primary" as={Link} to={`/${region}/bgm/${bgm.id}`}>
<FontAwesomeIcon icon={faShare} title={`Go to ${region} BGM ${showName}`} />
</Button>
</>
) : null;
Expand All @@ -80,7 +68,7 @@ export default function BgmDescriptor(props: {
);
return (
<>
<ButtonGroup size="sm" style={props.style}>
<ButtonGroup size="sm" style={style}>
<VoiceLinePlayer audioAssetUrls={[bgm.audioAsset]} delay={[0]} title={bgm.name} />
{downloadButton}
{toLink}
Expand All @@ -89,7 +77,7 @@ export default function BgmDescriptor(props: {
);
} else {
return (
<Button variant={"info"} disabled style={props.style} className={className}>
<Button variant={"info"} disabled style={style} className={className}>
<span lang={lang(region)}>{bgm.name}</span>
</Button>
);
Expand Down

0 comments on commit bb48ca0

Please sign in to comment.