2025-11-21 17:58:56 +09:00
|
|
|
import 'package:flutter/material.dart';
|
2025-11-24 17:53:00 +09:00
|
|
|
import 'package:playwith_core/playwith_core.dart';
|
|
|
|
|
import 'package:playwith_game_quiz/quiz_game.dart'; // 퀴즈 모듈 import
|
2025-11-21 18:04:15 +09:00
|
|
|
import 'intro_screen.dart';
|
2025-11-21 17:58:56 +09:00
|
|
|
|
|
|
|
|
void main() {
|
2025-11-24 17:53:00 +09:00
|
|
|
// 1. 플러터 바인딩 초기화
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
|
|
// 2. 사운드 리소스 주입 (여기가 핵심!)
|
|
|
|
|
// AssetSource는 'assets/' 접두어를 자동으로 붙이므로 그 하위 경로만 적습니다.
|
|
|
|
|
SoundManager().initialize(soundPaths: {
|
|
|
|
|
SoundKey.bgm: 'audio/bgm.mp3',
|
|
|
|
|
SoundKey.correct: 'audio/correct.mp3',
|
|
|
|
|
SoundKey.wrong: 'audio/wrong.mp3',
|
|
|
|
|
SoundKey.win: 'audio/win.mp3',
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-21 18:04:15 +09:00
|
|
|
runApp(const PlayWithApp());
|
2025-11-21 17:58:56 +09:00
|
|
|
}
|
|
|
|
|
|
2025-11-24 17:53:00 +09:00
|
|
|
class PlayWithApp extends StatefulWidget {
|
2025-11-21 18:04:15 +09:00
|
|
|
const PlayWithApp({super.key});
|
2025-11-21 17:58:56 +09:00
|
|
|
|
2025-11-24 17:53:00 +09:00
|
|
|
@override
|
|
|
|
|
State<PlayWithApp> createState() => _PlayWithAppState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PlayWithAppState extends State<PlayWithApp> {
|
|
|
|
|
final _net = NetworkManager();
|
|
|
|
|
|
|
|
|
|
// 등록된 게임 목록
|
|
|
|
|
final List<BaseGame> _games = [
|
|
|
|
|
QuizGame(), // 여기서 등록!
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
// [전역 라우팅] 네트워크 메시지를 감시하다가 'GAME_START'가 오면 해당 게임 실행
|
|
|
|
|
_net.messageStream.listen((data) {
|
|
|
|
|
if (data['type'] == 'GAME_START') {
|
|
|
|
|
final String gameId = data['gameId'];
|
|
|
|
|
|
|
|
|
|
// ID에 맞는 게임 찾기
|
|
|
|
|
final game = _games.firstWhere(
|
|
|
|
|
(g) => g.id == gameId,
|
|
|
|
|
orElse: () => throw Exception("Game not found: $gameId")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 게임 화면으로 이동 (네비게이터 키를 안 쓰고 있어서 간단히 처리 불가, 아래 설명 참조)
|
|
|
|
|
// 실제로는 GlobalKey<NavigatorState>를 쓰거나, 현재 context를 찾아야 함.
|
|
|
|
|
// MVP에서는 LobbyScreen 내부에서 처리하는 것이 안전함.
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-21 17:58:56 +09:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
2025-11-21 18:04:15 +09:00
|
|
|
title: 'PlayWith',
|
2025-11-21 17:58:56 +09:00
|
|
|
theme: ThemeData(
|
2025-11-21 18:04:15 +09:00
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
|
useMaterial3: true,
|
2025-11-21 17:58:56 +09:00
|
|
|
),
|
2025-11-21 18:04:15 +09:00
|
|
|
home: const IntroScreen(),
|
2025-11-21 17:58:56 +09:00
|
|
|
);
|
|
|
|
|
}
|
2025-11-21 18:04:15 +09:00
|
|
|
}
|