feat: add specialized visual editors for items, creatures, areas, and dialogs
This commit is contained in:
@@ -2,13 +2,28 @@ import { useCallback, useMemo, useState } from "react";
|
||||
import { MonacoEditor } from "../components/editor/MonacoEditor";
|
||||
import { EditorTabs } from "../components/editor/EditorTabs";
|
||||
import { GffEditor } from "../components/gff/GffEditor";
|
||||
import { ItemEditor } from "../components/gff/ItemEditor";
|
||||
import { CreatureEditor } from "../components/gff/CreatureEditor";
|
||||
import { AreaEditor } from "../components/gff/AreaEditor";
|
||||
import { DialogEditor } from "../components/gff/DialogEditor";
|
||||
|
||||
const GFF_EXTENSIONS = [".uti.json", ".utc.json", ".are.json", ".dlg.json", ".utp.json", ".utm.json"];
|
||||
|
||||
type GffEditorType = "uti" | "utc" | "are" | "dlg" | "generic" | null;
|
||||
|
||||
function isGffFile(tabKey: string): boolean {
|
||||
return GFF_EXTENSIONS.some((ext) => tabKey.endsWith(ext));
|
||||
}
|
||||
|
||||
function getGffEditorType(tabKey: string): GffEditorType {
|
||||
if (tabKey.endsWith(".uti.json")) return "uti";
|
||||
if (tabKey.endsWith(".utc.json")) return "utc";
|
||||
if (tabKey.endsWith(".are.json")) return "are";
|
||||
if (tabKey.endsWith(".dlg.json")) return "dlg";
|
||||
if (tabKey.endsWith(".utp.json") || tabKey.endsWith(".utm.json")) return "generic";
|
||||
return null;
|
||||
}
|
||||
|
||||
function repoFromTabKey(tabKey: string): string {
|
||||
const idx = tabKey.indexOf(":");
|
||||
return idx > 0 ? tabKey.slice(0, idx) : "";
|
||||
@@ -99,16 +114,28 @@ export function Editor({ editorState }: EditorProps) {
|
||||
}
|
||||
|
||||
if (isActiveGff && activeMode === "visual") {
|
||||
return (
|
||||
<GffEditor
|
||||
key={activeTab}
|
||||
repo={activeRepo}
|
||||
filePath={activeFilePath}
|
||||
content={activeContent}
|
||||
onSave={handleGffSave}
|
||||
onSwitchToRaw={handleSwitchToRaw}
|
||||
/>
|
||||
);
|
||||
const editorType = getGffEditorType(activeTab);
|
||||
const commonProps = {
|
||||
key: activeTab,
|
||||
repo: activeRepo,
|
||||
filePath: activeFilePath,
|
||||
content: activeContent,
|
||||
onSave: handleGffSave,
|
||||
onSwitchToRaw: handleSwitchToRaw,
|
||||
};
|
||||
|
||||
switch (editorType) {
|
||||
case "uti":
|
||||
return <ItemEditor {...commonProps} />;
|
||||
case "utc":
|
||||
return <CreatureEditor {...commonProps} />;
|
||||
case "are":
|
||||
return <AreaEditor {...commonProps} />;
|
||||
case "dlg":
|
||||
return <DialogEditor {...commonProps} />;
|
||||
default:
|
||||
return <GffEditor {...commonProps} />;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user