[ISSUE-1] Refactor NPC forms to modular node-based system #2
224
src/App.tsx
224
src/App.tsx
@@ -1,20 +1,11 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Settings, MessageSquare, Sword, Users, Code, FileText, Upload } from 'lucide-react';
|
||||
import type { NPCConfiguration, DialogueConfiguration } from './types/npc';
|
||||
import { NPCBasicSettings } from './components/NPCBasicSettings';
|
||||
import { NPCBattleConfiguration } from './components/NPCBattleConfiguration';
|
||||
import { NPCPartyBuilder } from './components/NPCPartyBuilder';
|
||||
import { NPCInteractionEditor } from './components/NPCInteractionEditor';
|
||||
import { ConfigVariablesEditor } from './components/ConfigVariablesEditor';
|
||||
import { DialogueEditor } from './components/DialogueEditor';
|
||||
import { JSONPreview } from './components/JSONPreview';
|
||||
import { ImportExport } from './components/ImportExport';
|
||||
|
||||
type Tab = 'basic' | 'battle' | 'party' | 'interaction' | 'variables' | 'dialogue' | 'preview' | 'import';
|
||||
import { useState } from 'react';
|
||||
import { Sparkles, Grid } from 'lucide-react';
|
||||
import type { NPCConfiguration } from './types/npc';
|
||||
import { NodeCanvas } from './components/NodeCanvas';
|
||||
|
||||
function App() {
|
||||
const [activeTab, setActiveTab] = useState<Tab>('basic');
|
||||
|
||||
const [viewMode, setViewMode] = useState<'modular' | 'classic'>('modular');
|
||||
|
||||
const [npcConfig, setNpcConfig] = useState<NPCConfiguration>({
|
||||
id: 'my_npc',
|
||||
name: 'My NPC',
|
||||
@@ -26,173 +17,74 @@ function App() {
|
||||
resourceIdentifier: 'cobblemon:my_npc'
|
||||
});
|
||||
|
||||
const [dialogueConfig, setDialogueConfig] = useState<DialogueConfiguration | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (npcConfig.interactions && npcConfig.interactions.length > 0 && npcConfig.interactions[0].type === 'dialogue' && !dialogueConfig) {
|
||||
const newDialogue: DialogueConfiguration = {
|
||||
speakers: {
|
||||
npc: {
|
||||
name: { type: 'expression', expression: 'q.npc.name' },
|
||||
face: 'q.npc.face(false);'
|
||||
},
|
||||
player: {
|
||||
name: { type: 'expression', expression: 'q.player.username' },
|
||||
face: 'q.player.face();'
|
||||
}
|
||||
},
|
||||
pages: [{
|
||||
id: 'greeting',
|
||||
speaker: 'npc',
|
||||
lines: ['Hello there!'],
|
||||
input: 'q.dialogue.close();'
|
||||
}]
|
||||
};
|
||||
setDialogueConfig(newDialogue);
|
||||
}
|
||||
}, [npcConfig.interactions, dialogueConfig]);
|
||||
|
||||
const tabs = [
|
||||
{ id: 'basic', name: 'Basic Settings', icon: Settings },
|
||||
{ id: 'battle', name: 'Battle Config', icon: Sword },
|
||||
{ id: 'party', name: 'Pokemon Party', icon: Users },
|
||||
{ id: 'interaction', name: 'Interaction', icon: MessageSquare },
|
||||
{ id: 'variables', name: 'Variables', icon: Code },
|
||||
{ id: 'dialogue', name: 'Dialogue', icon: MessageSquare },
|
||||
{ id: 'preview', name: 'JSON Preview', icon: FileText },
|
||||
{ id: 'import', name: 'Import/Export', icon: Upload }
|
||||
];
|
||||
|
||||
const renderActiveTab = () => {
|
||||
switch (activeTab) {
|
||||
case 'basic':
|
||||
return <NPCBasicSettings config={npcConfig} onChange={setNpcConfig} />;
|
||||
case 'battle':
|
||||
return <NPCBattleConfiguration config={npcConfig} onChange={setNpcConfig} />;
|
||||
case 'party':
|
||||
return <NPCPartyBuilder config={npcConfig} onChange={setNpcConfig} />;
|
||||
case 'interaction':
|
||||
return <NPCInteractionEditor config={npcConfig} onChange={setNpcConfig} />;
|
||||
case 'variables':
|
||||
return <ConfigVariablesEditor config={npcConfig} onChange={setNpcConfig} />;
|
||||
case 'dialogue':
|
||||
return <DialogueEditor dialogue={dialogueConfig} onChange={setDialogueConfig} />;
|
||||
case 'preview':
|
||||
return <JSONPreview npcConfig={npcConfig} dialogueConfig={dialogueConfig} />;
|
||||
case 'import':
|
||||
return (
|
||||
<ImportExport
|
||||
npcConfigs={[npcConfig]}
|
||||
dialogueConfiguration={dialogueConfig}
|
||||
onImport={(configs) => {
|
||||
if (configs.length > 0) {
|
||||
setNpcConfig(configs[0]);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
{/* Header */}
|
||||
<header className="bg-white shadow-sm border-b border-gray-200">
|
||||
<header className="bg-white shadow-sm border-b border-gray-200 sticky top-0 z-50">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="flex items-center justify-between h-16">
|
||||
<div className="flex items-center">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="flex-shrink-0">
|
||||
<h1 className="text-xl font-bold text-gray-900">Cobblemon NPC Creator</h1>
|
||||
</div>
|
||||
<div className="hidden sm:flex items-center gap-2 px-3 py-1 bg-gradient-to-r from-indigo-500 to-purple-500 text-white text-xs font-medium rounded-full">
|
||||
<Sparkles className="h-3 w-3" />
|
||||
Modular Edition
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-sm text-gray-500">
|
||||
Create and customize NPCs for your Cobblemon mod
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-gray-500 hidden md:block">
|
||||
Build NPCs with connectable modules
|
||||
</div>
|
||||
<div className="flex items-center bg-gray-100 rounded-lg p-1">
|
||||
<button
|
||||
onClick={() => setViewMode('modular')}
|
||||
className={`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${
|
||||
viewMode === 'modular'
|
||||
? 'bg-white text-indigo-600 shadow-sm'
|
||||
: 'text-gray-600 hover:text-gray-900'
|
||||
}`}
|
||||
>
|
||||
<span className="flex items-center gap-1">
|
||||
<Sparkles className="h-3 w-3" />
|
||||
Modular
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setViewMode('classic')}
|
||||
className={`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${
|
||||
viewMode === 'classic'
|
||||
? 'bg-white text-indigo-600 shadow-sm'
|
||||
: 'text-gray-600 hover:text-gray-900'
|
||||
}`}
|
||||
disabled
|
||||
title="Classic view coming soon"
|
||||
>
|
||||
<span className="flex items-center gap-1">
|
||||
<Grid className="h-3 w-3" />
|
||||
Classic
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<div className="lg:grid lg:grid-cols-12 lg:gap-8">
|
||||
{/* Sidebar Navigation */}
|
||||
<div className="lg:col-span-3">
|
||||
<nav className="space-y-1">
|
||||
{tabs.map(tab => {
|
||||
const Icon = tab.icon;
|
||||
const isActive = activeTab === tab.id;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id as Tab)}
|
||||
className={`w-full group flex items-center px-3 py-2 text-sm font-medium rounded-md transition-colors ${
|
||||
isActive
|
||||
? 'bg-indigo-100 text-indigo-700 border-r-2 border-indigo-500'
|
||||
: 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'
|
||||
}`}
|
||||
>
|
||||
<Icon
|
||||
className={`flex-shrink-0 -ml-1 mr-3 h-5 w-5 ${
|
||||
isActive ? 'text-indigo-500' : 'text-gray-400 group-hover:text-gray-500'
|
||||
}`}
|
||||
/>
|
||||
{tab.name}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Quick Info Panel */}
|
||||
<div className="mt-8 bg-white rounded-lg shadow p-4">
|
||||
<h3 className="text-sm font-medium text-gray-900 mb-3">Current NPC</h3>
|
||||
<dl className="space-y-2 text-xs">
|
||||
<div>
|
||||
<dt className="font-medium text-gray-700">Name</dt>
|
||||
<dd className="text-gray-600">{npcConfig.names[0] || 'Unnamed'}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="font-medium text-gray-700">Type</dt>
|
||||
<dd className="text-gray-600 capitalize">
|
||||
{npcConfig.battleConfiguration?.canChallenge ? 'Trainer' : 'NPC'}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="font-medium text-gray-700">Interaction</dt>
|
||||
<dd className="text-gray-600 capitalize">
|
||||
{npcConfig.interactions && npcConfig.interactions.length > 0
|
||||
? npcConfig.interactions[0].type
|
||||
: 'none'}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="font-medium text-gray-700">Variables</dt>
|
||||
<dd className="text-gray-600">{npcConfig.config?.length || 0}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main Content */}
|
||||
<div className="mt-8 lg:mt-0 lg:col-span-9">
|
||||
<div className="bg-white shadow rounded-lg">
|
||||
<div className="px-6 py-8">
|
||||
{renderActiveTab()}
|
||||
</div>
|
||||
</div>
|
||||
{/* Main Content - Full Screen Canvas */}
|
||||
{viewMode === 'modular' ? (
|
||||
<NodeCanvas
|
||||
npcConfig={npcConfig}
|
||||
onConfigChange={setNpcConfig}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-screen">
|
||||
<div className="text-center">
|
||||
<h2 className="text-2xl font-bold text-gray-900 mb-2">Classic View</h2>
|
||||
<p className="text-gray-600">Coming soon...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<footer className="bg-white border-t border-gray-200 mt-12">
|
||||
<div className="max-w-7xl mx-auto py-4 px-4 sm:px-6 lg:px-8">
|
||||
<p className="text-center text-sm text-gray-500">
|
||||
Built for the Cobblemon Minecraft mod - Create amazing NPCs for your world!
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user