Moved away from singleton pattern
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -5,11 +5,11 @@ import 'package:wolf_3d_gui/screens/game_select_screen.dart';
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await Wolf3d.I.init();
|
||||
final Wolf3d wolf3d = await Wolf3d().init();
|
||||
|
||||
runApp(
|
||||
const MaterialApp(
|
||||
home: GameSelectScreen(),
|
||||
MaterialApp(
|
||||
home: GameSelectScreen(wolf3d: wolf3d),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@ import 'package:wolf_3d_flutter/wolf_3d.dart';
|
||||
import 'package:wolf_3d_gui/screens/game_screen.dart';
|
||||
|
||||
class DifficultyScreen extends StatefulWidget {
|
||||
final Wolf3d wolf3d;
|
||||
|
||||
const DifficultyScreen({
|
||||
super.key,
|
||||
required this.wolf3d,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -13,24 +16,25 @@ class DifficultyScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DifficultyScreenState extends State<DifficultyScreen> {
|
||||
bool get isShareware => Wolf3d.I.activeGame.version == GameVersion.shareware;
|
||||
bool get isShareware =>
|
||||
widget.wolf3d.activeGame.version == GameVersion.shareware;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Wolf3d.I.audio.stopMusic();
|
||||
widget.wolf3d.audio.stopMusic();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startGame(Difficulty difficulty, {bool showGallery = false}) {
|
||||
Wolf3d.I.audio.stopMusic();
|
||||
widget.wolf3d.audio.stopMusic();
|
||||
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => GameScreen(
|
||||
data: Wolf3d.I.activeGame,
|
||||
data: widget.wolf3d.activeGame,
|
||||
difficulty: difficulty,
|
||||
startingEpisode: Wolf3d.I.activeEpisode,
|
||||
audio: Wolf3d.I.audio,
|
||||
startingEpisode: widget.wolf3d.activeEpisode,
|
||||
audio: widget.wolf3d.audio,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -59,8 +63,6 @@ class _DifficultyScreenState extends State<DifficultyScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// --- Difficulty Buttons ---
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: Difficulty.values.length,
|
||||
|
||||
@@ -6,7 +6,9 @@ import 'package:wolf_3d_gui/screens/sprite_gallery.dart';
|
||||
import 'package:wolf_3d_gui/screens/vga_gallery.dart';
|
||||
|
||||
class EpisodeScreen extends StatefulWidget {
|
||||
const EpisodeScreen({super.key});
|
||||
final Wolf3d wolf3d;
|
||||
|
||||
const EpisodeScreen({super.key, required this.wolf3d});
|
||||
|
||||
@override
|
||||
State<EpisodeScreen> createState() => _EpisodeScreenState();
|
||||
@@ -16,21 +18,21 @@ class _EpisodeScreenState extends State<EpisodeScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Wolf3d.I.audio.playMenuMusic();
|
||||
widget.wolf3d.audio.playMenuMusic();
|
||||
}
|
||||
|
||||
void _selectEpisode(int index) {
|
||||
Wolf3d.I.setActiveEpisode(index);
|
||||
widget.wolf3d.setActiveEpisode(index);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DifficultyScreen(),
|
||||
builder: (context) => DifficultyScreen(wolf3d: widget.wolf3d),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<Episode> episodes = Wolf3d.I.activeGame.episodes;
|
||||
final List<Episode> episodes = widget.wolf3d.activeGame.episodes;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.teal,
|
||||
@@ -43,7 +45,7 @@ class _EpisodeScreenState extends State<EpisodeScreen> {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return VgaGallery(images: Wolf3d.I.vgaImages);
|
||||
return VgaGallery(images: widget.wolf3d.vgaImages);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -55,7 +57,9 @@ class _EpisodeScreenState extends State<EpisodeScreen> {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return SpriteGallery(sprites: Wolf3d.I.sprites);
|
||||
return SpriteGallery(
|
||||
wolf3d: widget.wolf3d,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -4,25 +4,27 @@ import 'package:wolf_3d_flutter/wolf_3d.dart';
|
||||
import 'package:wolf_3d_gui/screens/episode_screen.dart';
|
||||
|
||||
class GameSelectScreen extends StatelessWidget {
|
||||
const GameSelectScreen({super.key});
|
||||
final Wolf3d wolf3d;
|
||||
|
||||
const GameSelectScreen({super.key, required this.wolf3d});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: ListView.builder(
|
||||
itemCount: Wolf3d.I.availableGames.length,
|
||||
itemCount: wolf3d.availableGames.length,
|
||||
itemBuilder: (context, i) {
|
||||
final WolfensteinData data = Wolf3d.I.availableGames[i];
|
||||
final WolfensteinData data = wolf3d.availableGames[i];
|
||||
final GameVersion version = data.version;
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(version.name),
|
||||
onTap: () {
|
||||
Wolf3d.I.setActiveGame(data);
|
||||
wolf3d.setActiveGame(data);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const EpisodeScreen(),
|
||||
builder: (context) => EpisodeScreen(wolf3d: wolf3d),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -5,11 +5,11 @@ import 'package:wolf_3d_flutter/wolf_3d.dart';
|
||||
import 'package:wolf_3d_renderer/wolf_3d_asset_painter.dart';
|
||||
|
||||
class SpriteGallery extends StatelessWidget {
|
||||
final List<Sprite> sprites;
|
||||
final Wolf3d wolf3d;
|
||||
|
||||
const SpriteGallery({super.key, required this.sprites});
|
||||
const SpriteGallery({super.key, required this.wolf3d});
|
||||
|
||||
bool get isShareware => Wolf3d.I.activeGame.version == GameVersion.shareware;
|
||||
bool get isShareware => wolf3d.activeGame.version == GameVersion.shareware;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -25,9 +25,8 @@ class SpriteGallery extends StatelessWidget {
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
),
|
||||
itemCount: sprites.length,
|
||||
itemCount: wolf3d.sprites.length,
|
||||
itemBuilder: (context, index) {
|
||||
// --- Check which enemy owns this sprite ---
|
||||
String label = "Sprite Index: $index";
|
||||
for (final enemy in EnemyType.values) {
|
||||
if (enemy.claimsSpriteIndex(index, isShareware: isShareware)) {
|
||||
@@ -36,14 +35,10 @@ class SpriteGallery extends StatelessWidget {
|
||||
isShareware: isShareware,
|
||||
);
|
||||
|
||||
// Appends the enum name (e.g., "guard", "dog")
|
||||
label += "\n${enemy.name}";
|
||||
|
||||
// Appends the animation name
|
||||
if (animation != null) {
|
||||
label += "\n${animation.name}";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +56,7 @@ class SpriteGallery extends StatelessWidget {
|
||||
Expanded(
|
||||
child: AspectRatio(
|
||||
aspectRatio: 4 / 3,
|
||||
child: WolfAssetPainter.sprite(sprites[index]),
|
||||
child: WolfAssetPainter.sprite(wolf3d.sprites[index]),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user