1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
import React, { useEffect, useMemo, useRef, useState } from 'react'
import { TopBar } from './TopBar'
import { VNViewport } from './VNViewport'
import { DialogueBox } from './DialogueBox'
import { ChoiceMenu } from './ChoiceMenu'
import { BottomBar } from './BottomBar'
import { LoadingScreen } from './LoadingScreen'
import { ConfigModal } from './ConfigModal'
import { VNWebSocket } from '../services/ws'
import { ChatMessage, Choice } from '../types'
// Using direct PNG logo in VN header
const DEFAULT_CHOICES: Choice[] = [
{ id: 'greet', label: '"Hello?"' },
{ id: 'who', label: '"Who are you?"' },
{ id: 'silence', label: '(Stay silent)' },
]
export function VNApp() {
const [loading, setLoading] = useState(true)
const [loadingComplete, setLoadingComplete] = useState(false)
const [messages, setMessages] = useState<ChatMessage[]>([
{ id: 'm1', role: 'assistant', content: 'A warm CRT glow fills the room. A figure turns towards you...' },
])
const [choices, setChoices] = useState<Choice[]>(DEFAULT_CHOICES)
const [status, setStatus] = useState('OFFLINE')
const [name, setName] = useState('???')
const [bg, setBg] = useState('/__gaogao__56242cbde8f18ac64522e410bad04e68_waifu2x_art_noise2.png')
const [money, setMoney] = useState(15000)
const [currentTime, setCurrentTime] = useState(new Date())
const [location, setLocation] = useState('Tokyo')
const [weather, setWeather] = useState('Sunny 22°C')
const [configModalOpen, setConfigModalOpen] = useState(false)
const [skipIntro, setSkipIntro] = useState(() => {
const saved = localStorage.getItem('skipIntro')
return saved === 'true'
})
const ws = useMemo(() => new VNWebSocket('ws://localhost:8080/ws'), [])
const lastId = useRef(2)
// Check if intro should be skipped on initial load
useEffect(() => {
if (skipIntro) {
setLoading(false)
setLoadingComplete(true)
// Set skip intro to true after first time loading screen is shown
localStorage.setItem('skipIntro', 'true')
}
}, [])
// Handle skip intro toggle
const handleSkipIntroChange = (skip: boolean) => {
setSkipIntro(skip)
localStorage.setItem('skipIntro', skip.toString())
}
// Handle loading screen completion
const handleLoadingComplete = () => {
setLoading(false)
setLoadingComplete(true)
// Set skip intro to true after first time loading screen is shown
if (!skipIntro) {
setSkipIntro(true)
localStorage.setItem('skipIntro', 'true')
}
}
useEffect(() => {
ws.on('open', () => setStatus('ONLINE'))
ws.on('close', () => setStatus('OFFLINE'))
ws.on('message', (data) => {
// Expecting { type: 'assistant'|'choices'|'bg'|'name'|'system', ... }
if (data?.type === 'assistant') {
pushMessage('assistant', data.content || '')
} else if (data?.type === 'choices') {
setChoices((data.items || []).map((it: any, idx: number) => ({ id: it.id ?? String(idx), label: it.label ?? String(it) })))
} else if (data?.type === 'bg') {
setBg(data.src || '/bg.jpg')
} else if (data?.type === 'name') {
setName(data.value || name)
} else if (data?.type === 'system') {
pushMessage('system', data.content || '')
}
})
ws.connect()
return () => ws.close()
}, [ws])
// Update clock every second
useEffect(() => {
const timer = setInterval(() => {
setCurrentTime(new Date())
}, 1000)
return () => clearInterval(timer)
}, [])
function pushMessage(role: 'user' | 'assistant' | 'system', content: string) {
lastId.current += 1
setMessages((prev) => [...prev, { id: 'm' + lastId.current, role, content }])
}
function handleChoice(id: string) {
const choice = choices.find(c => c.id === id)
const content = choice?.label || id
pushMessage('user', content)
ws.send({ type: 'user_choice', id, label: content })
setChoices([])
setTimeout(() => {
pushMessage('assistant', `The figure nods: "${content}"...`)
setChoices(DEFAULT_CHOICES)
setName('Guide')
}, 600)
}
const lastAssistant = messages.slice().reverse().find(m => m.role !== 'user')
return (
<div>
{!loadingComplete && (
<LoadingScreen
onComplete={handleLoadingComplete}
/>
)}
<div className={`main-interface ${loadingComplete ? 'visible' : 'hidden'}`}>
<div className="screen" role="application">
<div className="left-pillar">
<div className="pillar-image">
Character A
</div>
<div className="pillar-bottom-section">
<div className="pillar-buttons">
<button className="pillar-btn" onClick={() => {}}>SAVE</button>
<button className="pillar-btn" onClick={() => {}}>LOAD</button>
<button className="pillar-btn" onClick={() => setConfigModalOpen(true)}>CONFIG</button>
<button className="pillar-btn" onClick={() => {}}>EXIT</button>
</div>
</div>
</div>
<div className="screen-content">
<div className="screen-header header-footer-border">
<div className="brand">
<img
src="/logo/crane-logo-transparent.png"
alt="Soryu"
height={24}
className="brand-mark"
onError={(e) => { const img = (e.currentTarget as HTMLImageElement); img.onerror = null; img.src = '/logo/crane-logo.png'; }}
/>
</div>
</div>
<VNViewport bgSrc={bg}>
<div className="ui-layer">
<div className="weather-display">
{location} - {weather}
</div>
</div>
</VNViewport>
<DialogueBox name={name} text={lastAssistant?.content || ''} />
<div className="text-input-area">
<input
type="text"
className="text-input"
placeholder="Type your response..."
onKeyPress={(e) => {
if (e.key === 'Enter') {
const target = e.target as HTMLInputElement;
if (target.value.trim()) {
pushMessage('user', target.value);
target.value = '';
}
}
}}
/>
</div>
<div className="screen-footer header-footer-border">
<div className="desktop-time">{new Date().toLocaleDateString('ja-JP', { year: 'numeric', month: 'long', day: 'numeric' })} {new Date().toLocaleTimeString('ja-JP', { hour12: false })}</div>
<div className="mobile-time-money">
<div className="mobile-clock">
{currentTime.toLocaleDateString('ja-JP', { year: 'numeric', month: 'long', day: 'numeric' })} {currentTime.toLocaleTimeString('ja-JP', { hour12: false })}
</div>
<div className="mobile-money">
{money.toLocaleString()}
</div>
</div>
<div className="mobile-buttons">
<button className="mobile-btn" onClick={() => {}}>SAVE</button>
<button className="mobile-btn" onClick={() => {}}>LOAD</button>
<button className="mobile-btn" onClick={() => setConfigModalOpen(true)}>CONFIG</button>
<button className="mobile-btn" onClick={() => {}}>EXIT</button>
</div>
</div>
<BottomBar
onSkip={() => {}}
onAuto={() => {}}
onLog={() => {}}
location={location}
/>
</div>
<div className="right-pillar">
<div className="pillar-image">
Character B
</div>
<div className="pillar-bottom-section">
<div className="pillar-display digital-clock">
{currentTime.toLocaleDateString('ja-JP', { year: 'numeric', month: 'long', day: 'numeric' })}
<br />
{currentTime.toLocaleTimeString('ja-JP', { hour12: false })}
</div>
<div className="pillar-display yen-counter">
{money.toLocaleString()}
</div>
</div>
</div>
</div>
</div>
<ConfigModal
isOpen={configModalOpen}
onClose={() => setConfigModalOpen(false)}
skipIntro={skipIntro}
onSkipIntroChange={handleSkipIntroChange}
/>
</div>
)
}
|