Skip to content

Commit

Permalink
Add ps3 converter
Browse files Browse the repository at this point in the history
  • Loading branch information
kbinani committed Jan 13, 2024
1 parent b4a7a4d commit 067df36
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 57 deletions.
2 changes: 1 addition & 1 deletion deps/je2be-core
Submodule je2be-core updated 167 files
65 changes: 46 additions & 19 deletions src/front/component/convert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid";
import { ConvertSession } from "../convert-session";
import { gettext } from "../i18n";
import { useForceUpdate } from "./main";
import { WorkerError } from "../../share/messages";
import { WorkerError, WorkerErrorType } from "../../share/messages";
import { ErrorMessage } from "./error-message";
import { directoryNameFromFileList } from "../../share/file-list-ext";
import {
Expand All @@ -19,6 +19,7 @@ import {
convertModeDescription,
convertModeInputFileExtension,
convertModeMetadata,
convertModeRequiredFile,
convertModeSupportsDirectoryInput,
} from "../mode";
import { Link } from "./link";
Expand Down Expand Up @@ -70,7 +71,17 @@ export const Convert: React.FC<{
session.current?.close();
onBack();
};
const changeHandler = ({ file }: { file: boolean }) => {
const changeHandler = ({
file,
requiredFile,
}: {
file: boolean;
requiredFile?: {
name: string;
notFoundError: WorkerErrorType;
tooManyError: WorkerErrorType;
};
}) => {
return (ev: ChangeEvent<HTMLInputElement>) => {
const files = ev.target.files;
const noFileSelectedError: WorkerError = {
Expand Down Expand Up @@ -98,7 +109,7 @@ export const Convert: React.FC<{
source = f;
filename = f.name;
} else {
let numLevelDatFiles = 0;
let numRequiredFiles = 0;
const dirname = directoryNameFromFileList(files);
if (dirname === undefined) {
setState({
Expand All @@ -109,22 +120,28 @@ export const Convert: React.FC<{
});
return;
}
for (let i = 0; i < files.length; i++) {
const item = files.item(i);
if (!item) {
continue;
if (requiredFile !== undefined) {
for (let i = 0; i < files.length; i++) {
const item = files.item(i);
if (!item) {
continue;
}
if (item.name === requiredFile.name) {
numRequiredFiles++;
}
}
if (item.name === "level.dat") {
numLevelDatFiles++;
if (numRequiredFiles === 0) {
setState({
error: { type: requiredFile.notFoundError, native: {} },
});
return;
} else if (numRequiredFiles > 1) {
setState({
error: { type: requiredFile.tooManyError, native: {} },
});
return;
}
}
if (numLevelDatFiles === 0) {
setState({ error: { type: "NoLevelDatFound", native: {} } });
return;
} else if (numLevelDatFiles > 1) {
setState({ error: { type: "2OrMoreLevelDatFound", native: {} } });
return;
}
source = files;
filename = dirname;
}
Expand Down Expand Up @@ -175,7 +192,10 @@ export const Convert: React.FC<{
{gettext("Mode: ") + convertModeDescription(mode)}
</div>
<div className="hFlex" style={{ marginTop: 20 }}>
{convertModeSupportsDirectoryInput(mode) && (
{(mode === "j2b" ||
mode === "b2j" ||
mode === "p2j" ||
mode === "p2b") && (
<div className="inputContainer vFlex" style={{ marginRight: 5 }}>
<label
className="roundButton inputLabel"
Expand All @@ -185,14 +205,19 @@ export const Convert: React.FC<{
<input
id={"input_directory"}
type={"file"}
onChange={changeHandler({ file: false })}
onChange={changeHandler({
file: false,
requiredFile: convertModeRequiredFile(mode),
})}
ref={inputDirectory}
disabled={state.current.id !== undefined}
/>
</label>
<div className="inputGuidance">
{gettext(
"Select a world directory to convert, which must contain a level.dat file",
mode === "j2b" || mode === "b2j"
? "Select a world directory to convert, which must contain a level.dat file"
: "Select a world directory to convert, which must contain a GAMEDATA file",
)}
</div>
</div>
Expand Down Expand Up @@ -304,6 +329,8 @@ export const Convert: React.FC<{
const FileInputGuidance: React.FC<{ mode: ConvertMode }> = ({ mode }) => {
switch (mode) {
case "j2b":
case "p2j":
case "p2b":
return (
<>{gettext("Select a zip archive of world directory to convert")}</>
);
Expand Down
12 changes: 12 additions & 0 deletions src/front/component/mode-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export const ModeSelect: React.FC<{
>
{gettext("Xbox360 to Java")}
</div>
<div
className="roundButton modeSelectButton"
onClick={() => onSelect("p2b")}
>
{gettext("PS3 to Bedrock")}
</div>
<div
className="roundButton modeSelectButton"
onClick={() => onSelect("p2j")}
>
{gettext("PS3 to Java")}
</div>
</div>
);
};
10 changes: 8 additions & 2 deletions src/front/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ export function gettext(
case "Xbox360 to Java":
return "Xbox360版 から Java版に";
case "Select a world directory to convert, which must contain a level.dat file":
return "変換するワールドのディレクトリを選択して下さい。このディレクトリには level.dat が含まれている必要があります";
return "変換するワールドのディレクトリを選択して下さい。このディレクトリには level.dat ファイルが含まれている必要があります";
case "Select a zip archive of world directory to convert":
return "変換するワールドの zip ファイルを選択して下さい";
return "変換するワールドのディレクトリを zip に圧縮したファイルを選択して下さい";
case "Select a *.mcworld file to convert":
return "変換する *.mcworld ファイルを選択して下さい";
case "Select a *.bin to convert. This file can be copied from Xbox360 using USB stick. Check the link to know how to prepare USB stick for Xbox360":
return "変換する *.bin ファイルを選択して下さい。このファイルは USB メモリーを使うことで Xbox360 の実機からコピーする必要があります。Xbox360 用の USB メモリーを準備する方法は以下のリンクが参考になります。";
case "PS3 to Java":
return "PS3版 から Java版に";
case "PS3 to Bedrock":
return "PS3版 から 統合版に";
case "Select a world directory to convert, which must contain a GAMEDATA file":
return "変換するワールドのディレクトリを選択して下さい。このディレクトリには GAMEDATA ファイルが含まれている必要があります";
}
break;
}
Expand Down
46 changes: 44 additions & 2 deletions src/front/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ import {
B2JConverterMetadata,
ConverterMetadata,
J2BConverterMetadata,
P2BConverterMetadata,
P2JConverterMetadata,
X2BConverterMetadata,
X2JConverterMetadata,
} from "../share/progress";
import { gettext } from "./i18n";
import { WorkerError, WorkerErrorType } from "../share/messages";

export type ConvertMode = "j2b" | "b2j" | "x2b" | "x2j";
export type ConvertMode = "j2b" | "b2j" | "x2b" | "x2j" | "p2b" | "p2j";
export type Mode = "select" | ConvertMode;

export function convertModeSupportsDirectoryInput(mode: ConvertMode): boolean {
return mode === "j2b" || mode == "b2j";
return mode === "j2b" || mode === "b2j" || mode === "p2b" || mode === "p2j";
}

export function convertModeInputFileExtension(mode: ConvertMode): string {
switch (mode) {
case "j2b":
case "p2b":
case "p2j":
return ".zip";
case "b2j":
return ".mcworld";
Expand All @@ -30,13 +35,42 @@ export function convertModeOutputFileExtension(mode: ConvertMode): string {
switch (mode) {
case "j2b":
case "x2b":
case "p2b":
return ".mcworld";
case "b2j":
case "x2j":
case "p2j":
return ".zip";
}
}

export function convertModeRequiredFile(mode: ConvertMode):
| {
name: string;
notFoundError: WorkerErrorType;
tooManyError: WorkerErrorType;
}
| undefined {
switch (mode) {
case "j2b":
case "b2j":
return {
name: "level.dat",
notFoundError: "NoLevelDatFound",
tooManyError: "2OrMoreLevelDatFound",
};
case "p2j":
case "p2b":
return {
name: "GAMEDATA",
notFoundError: "NoGAMEDATAFound",
tooManyError: "2OrMoreGAMEDATAFound",
};
default:
return undefined;
}
}

export function convertModeMetadata(
mode: ConvertMode,
file: boolean,
Expand All @@ -50,6 +84,10 @@ export function convertModeMetadata(
return new X2JConverterMetadata();
case "x2b":
return new X2BConverterMetadata();
case "p2b":
return new P2BConverterMetadata(file);
case "p2j":
return new P2JConverterMetadata(file);
}
}

Expand All @@ -63,5 +101,9 @@ export function convertModeDescription(mode: ConvertMode): string {
return gettext("Xbox360 to Java");
case "x2b":
return gettext("Xbox360 to Bedrock");
case "p2b":
return gettext("PS3 to Bedrock");
case "p2j":
return gettext("PS3 to Java");
}
}
5 changes: 4 additions & 1 deletion src/front/translation-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ export type TranslationKey =
| "Unsupported browser because:"
| "Xbox360 to Bedrock"
| "Xbox360 to Java"
| "seconds";
| "seconds"
| "PS3 to Bedrock"
| "PS3 to Java"
| "Select a world directory to convert, which must contain a GAMEDATA file";
4 changes: 3 additions & 1 deletion src/share/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export function isProgressMessage(x: any): x is ProgressMessage {
);
}

type WorkerErrorType =
export type WorkerErrorType =
| "NoLevelDatFound"
| "NoGAMEDATAFound"
| "2OrMoreLevelDatFound"
| "2OrMoreGAMEDATAFound"
| "ConverterFailed"
| "Unzip"
| "CopyToIdb"
Expand Down
78 changes: 78 additions & 0 deletions src/share/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,84 @@ export class X2BConverterMetadata implements ConverterMetadata {
}
}

export class P2JConverterMetadata implements ConverterMetadata {
constructor(readonly file: boolean) {}

get steps(): Step[] {
if (this.file) {
return ["unzip", "extract"];
} else {
return ["copy", "extract"];
}
}

displayUnit(step: Step): string | undefined {
switch (step) {
case "copy":
case "unzip":
return "files";
case "extract":
return undefined;
}
}

stepDescription(step: Step): string | undefined {
switch (step) {
case "copy":
return "Copy";
case "unzip":
return "Unzip";
case "extract":
return "Convert";
}
}
}

export class P2BConverterMetadata implements ConverterMetadata {
constructor(readonly file: boolean) {}

get steps(): Step[] {
if (this.file) {
return ["unzip", "extract", "convert", "postprocess", "compaction"];
} else {
return ["copy", "extract", "convert", "postprocess", "compaction"];
}
}

displayUnit(step: Step): string | undefined {
switch (step) {
case "copy":
case "unzip":
return "files";
case "extract":
return undefined;
case "convert":
return "chunks";
case "postprocess":
return undefined;
case "compaction":
return undefined;
}
}

stepDescription(step: Step): string | undefined {
switch (step) {
case "copy":
return "Copy";
case "unzip":
return "Unzip";
case "extract":
return "Extract";
case "convert":
return "Convert";
case "postprocess":
return "Post Process";
case "compaction":
return "LevelDB Compaction";
}
}
}

export function nextProgress(
progress: Progress,
m: ProgressMessage,
Expand Down
Loading

0 comments on commit 067df36

Please sign in to comment.