import 'dart:typed_data';

typedef Matrix<T> = List<List<T>>;
typedef SpriteMap = Matrix<int>;

/// A 64x64 graphical asset (wall texture or enemy sprite).
class Sprite {
  /// 1D array of 8-bit palette indices (4096 total pixels).
  final Uint8List pixels;

  Sprite(this.pixels);

  /// Factory to convert a 2D [matrix] (x,y) into a 1D column-major array.
  ///
  /// In Wolf3D, textures are often stored/processed in columns (x * 64 + y)
  /// to optimize the vertical scaling used in raycasting.
  factory Sprite.fromMatrix(Matrix<int> matrix) {
    final pixels = Uint8List(64 * 64);
    for (int y = 0; y < 64; y++) {
      for (int x = 0; x < 64; x++) {
        // Linear index for vertical-strip rendering
        pixels[x * 64 + y] = matrix[x][y];
      }
    }
    return Sprite(pixels);
  }
}
