Moved everything to a monorepo and fixed the CLI app rendering
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
94
apps/wolf_3d_gui/lib/screens/difficulty_screen.dart
Normal file
94
apps/wolf_3d_gui/lib/screens/difficulty_screen.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
|
||||
import 'package:wolf_3d_flutter/wolf_3d.dart';
|
||||
import 'package:wolf_3d_renderer/wolf_3d_ascii_renderer.dart';
|
||||
|
||||
class DifficultyScreen extends StatefulWidget {
|
||||
const DifficultyScreen({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DifficultyScreen> createState() => _DifficultyScreenState();
|
||||
}
|
||||
|
||||
class _DifficultyScreenState extends State<DifficultyScreen> {
|
||||
bool get isShareware => Wolf3d.I.activeGame.version == GameVersion.shareware;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Wolf3d.I.audio.stopMusic();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startGame(Difficulty difficulty, {bool showGallery = false}) {
|
||||
Wolf3d.I.audio.stopMusic();
|
||||
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => WolfAsciiRenderer(
|
||||
Wolf3d.I.activeGame,
|
||||
difficulty: difficulty,
|
||||
startingEpisode: Wolf3d.I.activeEpisode,
|
||||
audio: Wolf3d.I.audio,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: Colors.red[900],
|
||||
onPressed: () => _startGame(Difficulty.bringEmOn, showGallery: true),
|
||||
child: const Icon(Icons.bug_report, color: Colors.white),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'HOW TOUGH ARE YOU?',
|
||||
style: TextStyle(
|
||||
color: Colors.red,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: 'Courier',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// --- Difficulty Buttons ---
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: Difficulty.values.length,
|
||||
itemBuilder: (context, index) {
|
||||
final Difficulty difficulty = Difficulty.values[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blueGrey[900],
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(300, 50),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
onPressed: () => _startGame(difficulty),
|
||||
child: Text(
|
||||
difficulty.title,
|
||||
style: const TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
115
apps/wolf_3d_gui/lib/screens/episode_screen.dart
Normal file
115
apps/wolf_3d_gui/lib/screens/episode_screen.dart
Normal file
@@ -0,0 +1,115 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
|
||||
import 'package:wolf_3d_flutter/wolf_3d.dart';
|
||||
import 'package:wolf_3d_gui/screens/difficulty_screen.dart';
|
||||
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});
|
||||
|
||||
@override
|
||||
State<EpisodeScreen> createState() => _EpisodeScreenState();
|
||||
}
|
||||
|
||||
class _EpisodeScreenState extends State<EpisodeScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Wolf3d.I.audio.playMenuMusic();
|
||||
}
|
||||
|
||||
void _selectEpisode(int index) {
|
||||
Wolf3d.I.setActiveEpisode(index);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DifficultyScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<Episode> episodes = Wolf3d.I.activeGame.episodes;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.teal,
|
||||
floatingActionButtonLocation:
|
||||
FloatingActionButtonLocation.miniCenterFloat,
|
||||
floatingActionButton: Row(
|
||||
children: [
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return VgaGallery(images: Wolf3d.I.vgaImages);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text('VGA Gallery'),
|
||||
),
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return SpriteGallery(sprites: Wolf3d.I.sprites);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text('Sprites'),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'WHICH EPISODE TO PLAY?',
|
||||
style: TextStyle(
|
||||
color: Colors.red,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: 'Courier',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: episodes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final Episode episode = episodes[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
horizontal: 32.0,
|
||||
),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blueGrey[900],
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(300, 60),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
onPressed: () => _selectEpisode(index),
|
||||
child: Text(
|
||||
episode.name,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
35
apps/wolf_3d_gui/lib/screens/game_select_screen.dart
Normal file
35
apps/wolf_3d_gui/lib/screens/game_select_screen.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
|
||||
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});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: ListView.builder(
|
||||
itemCount: Wolf3d.I.availableGames.length,
|
||||
itemBuilder: (context, i) {
|
||||
final WolfensteinData data = Wolf3d.I.availableGames[i];
|
||||
final GameVersion version = data.version;
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(version.name),
|
||||
onTap: () {
|
||||
Wolf3d.I.setActiveGame(data);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const EpisodeScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
92
apps/wolf_3d_gui/lib/screens/sprite_gallery.dart
Normal file
92
apps/wolf_3d_gui/lib/screens/sprite_gallery.dart
Normal file
@@ -0,0 +1,92 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
|
||||
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
|
||||
import 'package:wolf_3d_flutter/wolf_3d.dart';
|
||||
|
||||
class SpriteGallery extends StatelessWidget {
|
||||
final List<Sprite> sprites;
|
||||
|
||||
const SpriteGallery({super.key, required this.sprites});
|
||||
|
||||
bool get isShareware => Wolf3d.I.activeGame.version == GameVersion.shareware;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Sprite Gallery"),
|
||||
automaticallyImplyLeading: true,
|
||||
),
|
||||
backgroundColor: Colors.black,
|
||||
body: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 8,
|
||||
),
|
||||
itemCount: 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)) {
|
||||
final EnemyAnimation? animation = enemy.getAnimationFromSprite(
|
||||
index,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 10),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Expanded(
|
||||
child: CustomPaint(
|
||||
painter: SingleSpritePainter(sprite: sprites[index]),
|
||||
size: const Size(64, 64),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SingleSpritePainter extends CustomPainter {
|
||||
final Sprite sprite;
|
||||
SingleSpritePainter({required this.sprite});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
double pixelSize = size.width / 64;
|
||||
for (int x = 0; x < 64; x++) {
|
||||
for (int y = 0; y < 64; y++) {
|
||||
int colorByte = sprite.pixels[x * 64 + y];
|
||||
if (colorByte != 255) {
|
||||
// Skip transparency
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(x * pixelSize, y * pixelSize, pixelSize, pixelSize),
|
||||
Paint()..color = Color(ColorPalette.vga32Bit[colorByte]),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
||||
}
|
||||
95
apps/wolf_3d_gui/lib/screens/vga_gallery.dart
Normal file
95
apps/wolf_3d_gui/lib/screens/vga_gallery.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
|
||||
|
||||
class VgaGallery extends StatelessWidget {
|
||||
final List<VgaImage> images;
|
||||
|
||||
const VgaGallery({super.key, required this.images});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text("VGA Image Gallery")),
|
||||
backgroundColor: Colors.black,
|
||||
body: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 150,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
),
|
||||
itemCount: images.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Index: $index\n${images[index].width} x ${images[index].height}",
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: CustomPaint(
|
||||
painter: VgaPainter(image: images[index]),
|
||||
// Scale it up so tiny fonts are readable
|
||||
size: Size(
|
||||
images[index].width * 2.0,
|
||||
images[index].height * 2.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class VgaPainter extends CustomPainter {
|
||||
final VgaImage image;
|
||||
VgaPainter({required this.image});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
int planeWidth = image.width ~/ 4;
|
||||
int planeSize = planeWidth * image.height;
|
||||
|
||||
double pixelW = size.width / image.width;
|
||||
double pixelH = size.height / image.height;
|
||||
final Paint paint = Paint()..isAntiAlias = false;
|
||||
|
||||
for (int y = 0; y < image.height; y++) {
|
||||
for (int x = 0; x < image.width; x++) {
|
||||
int plane = x % 4;
|
||||
int sx = x ~/ 4;
|
||||
int colorByte =
|
||||
image.pixels[(plane * planeSize) + (y * planeWidth) + sx];
|
||||
|
||||
if (colorByte != 255) {
|
||||
int abgr = ColorPalette.vga32Bit[colorByte];
|
||||
|
||||
// Extract the bytes
|
||||
int r = abgr & 0xFF;
|
||||
int g = (abgr >> 8) & 0xFF;
|
||||
int b = (abgr >> 16) & 0xFF;
|
||||
int a = (abgr >> 24) & 0xFF;
|
||||
|
||||
// Repack them as ARGB for Flutter's Color object
|
||||
int argb = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
|
||||
paint.color = Color(argb);
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(x * pixelW, y * pixelH, pixelW + 0.5, pixelH + 0.5),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||
}
|
||||
Reference in New Issue
Block a user