Files
wolf_dart/lib/screens/sprite_gallery.dart
2026-03-15 19:36:37 +01:00

94 lines
2.8 KiB
Dart

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_renderer/color_palette.dart';
class SpriteGallery extends StatelessWidget {
final List<Sprite> sprites;
const SpriteGallery({super.key, required this.sprites});
@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)) {
final EnemyAnimation? animation = enemy.getAnimationFromSprite(
index,
);
// Appends the enum name (e.g., "guard", "dog")
label += "\n${enemy.name}";
// Appends the animation name
if (animation != null) {
label += "\n${animation.name}";
}
// Append the Map IDs for level editing reference
int staticBase = enemy.mapData.baseId;
label +=
"\nStat: $staticBase (E), ${staticBase + 1} (M), ${staticBase + 2} (H)";
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[x][y];
if (colorByte != 255) {
// Skip transparency
canvas.drawRect(
Rect.fromLTWH(x * pixelSize, y * pixelSize, pixelSize, pixelSize),
Paint()..color = ColorPalette.vga[colorByte],
);
}
}
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}