Skip to content

Commit

Permalink
Put compare scripts side by side if they are not aligned
Browse files Browse the repository at this point in the history
  • Loading branch information
squaresmile committed Jun 16, 2024
1 parent 82a8f3a commit b68189c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 20 deletions.
4 changes: 4 additions & 0 deletions packages/db/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
width: 25%;
}

.w-50pct {
width: 50%;
}

.w-1px {
width: 1px;
}
Expand Down
17 changes: 17 additions & 0 deletions packages/db/src/Component/Script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1551,3 +1551,20 @@ export const countWord = (region: Region, components: ScriptComponent[]) => {

return wordCount;
};

export const areComparableScripts = (mainScript: ScriptInfo, compareScript: ScriptInfo): boolean => {
for (let i = 0; i < mainScript.components.length; i++) {
const mainComponent = mainScript.components[i];
const compareComponent = compareScript.components[i];

if (
mainComponent === undefined ||
compareComponent === undefined ||
mainComponent.lineNumber !== compareComponent.lineNumber ||
mainComponent.content.type !== compareComponent.content.type
)
return false;
}

return true;
};
12 changes: 9 additions & 3 deletions packages/db/src/Component/ScriptTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,14 @@ const SceneRow = (props: {
effects?: string[];
filters: { content: ScriptCharaFilter; lineNumber?: number }[];
colSpan?: number;
halfWidth?: boolean;
}) => {
const { lineNumber, cameraFilter, effects, wideScreen } = props,
const { lineNumber, cameraFilter, effects, wideScreen, halfWidth } = props,
{ t } = useTranslation(),
resolution = wideScreen ? { height: 576, width: 1344 } : { height: 576, width: 1024 },
{ height, width } = useImageSize(wideScreen),
imageSize = useImageSize(wideScreen),
height = halfWidth ? imageSize.height / 2 : imageSize.height,
width = halfWidth ? imageSize.width / 2 : imageSize.width,
background = props.background ? { asset: props.background.backgroundAsset } : undefined;

const showScriptLine = useContext(ShowScriptLineContext);
Expand Down Expand Up @@ -701,6 +704,7 @@ const ScriptTable = (props: {
showScene?: boolean;
refs: RowBgmRefMap;
compareScript?: { region: Region; script: ScriptInfo };
halfWidth?: boolean;
}) => {
const scriptComponents = props.script.components,
{ t } = useTranslation(),
Expand Down Expand Up @@ -749,7 +753,7 @@ const ScriptTable = (props: {
}

return (
<Table hover responsive className="script-table">
<Table hover responsive className="script-table" style={props.halfWidth ? { fontSize: "10pt" } : {}}>
<thead>
<tr>
<th className="text-center" style={{ width: "10%" }}>
Expand Down Expand Up @@ -782,6 +786,7 @@ const ScriptTable = (props: {
lineNumber={lineNumber}
effects={[...effects]}
colSpan={colSpan}
halfWidth={props.halfWidth}
/>
);
};
Expand Down Expand Up @@ -961,6 +966,7 @@ const ScriptTable = (props: {
figure={figureComponent}
wideScreen={wideScreen}
effects={[...effects]}
halfWidth={props.halfWidth}
/>
) : null}
</tbody>
Expand Down
60 changes: 43 additions & 17 deletions packages/db/src/Page/ScriptPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ScriptComponent,
ScriptComponentType,
ScriptComponentWrapper,
areComparableScripts,
countWord,
parseScript,
} from "../Component/Script";
Expand Down Expand Up @@ -247,6 +248,14 @@ const ScriptPage = ({ region, scriptId }: { region: Region; scriptId: string })
);
if (hasRayshiftScript) availableCompareRegions.push("rayshift");

const parsedCompareScript =
compareSource !== undefined && compareScript !== undefined
? parseScript(compareSource === "rayshift" ? Region.NA : compareSource, compareScript)
: undefined;
const compareRegion = compareSource === "rayshift" ? Region.NA : compareSource;
const comparableScripts =
parsedCompareScript !== undefined && areComparableScripts(parsedScript, parsedCompareScript);

return (
<>
<div id="scroll-bar" className={classes.scrollBarIndicator} style={{ width: 0 }}></div>
Expand Down Expand Up @@ -318,23 +327,40 @@ const ScriptPage = ({ region, scriptId }: { region: Region; scriptId: string })
</ButtonGroup>
</ButtonToolbar>
<ShowScriptLineContext.Provider value={showScriptLine}>
<ScriptTable
region={region}
script={parsedScript}
showScene={enableScene}
refs={scrollRefs}
compareScript={
compareSource !== undefined && compareScript !== undefined
? {
region: compareSource === "rayshift" ? Region.NA : compareSource,
script: parseScript(
compareSource === "rayshift" ? Region.NA : compareSource,
compareScript
),
}
: undefined
}
/>
{parsedCompareScript !== undefined && compareRegion !== undefined && !comparableScripts ? (
<div className="d-flex">
<div className="w-50pct">
<ScriptTable
halfWidth
region={region}
script={parsedScript}
showScene={enableScene}
refs={scrollRefs}
/>
</div>
<div className="w-50pct">
<ScriptTable
halfWidth
region={compareRegion}
script={parsedCompareScript}
showScene={enableScene}
refs={scrollRefs}
/>
</div>
</div>
) : (
<ScriptTable
region={region}
script={parsedScript}
showScene={enableScene}
refs={scrollRefs}
compareScript={
compareSource !== undefined && compareRegion !== undefined && comparableScripts
? { region: compareRegion, script: parsedCompareScript }
: undefined
}
/>
)}
</ShowScriptLineContext.Provider>
</ScriptMainData>
</>
Expand Down

0 comments on commit b68189c

Please sign in to comment.