Added colors and textures

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-13 16:46:20 +01:00
parent 8ecc8e2fd4
commit 464a22e1f3
8 changed files with 388 additions and 66 deletions

View File

@@ -0,0 +1,42 @@
import 'dart:typed_data';
import 'package:wolf_dart/classes/matrix.dart';
class VswapParser {
/// Extracts the 64x64 wall textures from VSWAP.WL1
static List<Matrix<int>> parseWalls(ByteData vswap) {
// 1. Read Header
int chunks = vswap.getUint16(0, Endian.little);
int spriteStart = vswap.getUint16(2, Endian.little);
// int soundStart = vswap.getUint16(4, Endian.little); // We don't need this yet
// 2. Read Offsets (Where does each chunk start in the file?)
List<int> offsets = [];
for (int i = 0; i < spriteStart; i++) {
offsets.add(vswap.getUint32(6 + (i * 4), Endian.little));
}
// 3. Extract the Wall Textures
List<List<List<int>>> textures = [];
// Walls are chunks 0 through (spriteStart - 1)
for (int i = 0; i < spriteStart; i++) {
int offset = offsets[i];
if (offset == 0) continue; // Empty chunk
// Walls are always exactly 64x64 pixels (4096 bytes)
// Note: Wolf3D stores pixels in COLUMN-MAJOR order (Top to bottom, then left to right)
List<List<int>> texture = List.generate(64, (_) => List.filled(64, 0));
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
int byteIndex = offset + (x * 64) + y;
texture[x][y] = vswap.getUint8(byteIndex);
}
}
textures.add(texture);
}
return textures;
}
}

View File

@@ -1,24 +1,29 @@
import 'package:flutter/services.dart';
import 'package:wolf_dart/classes/matrix.dart';
import 'package:wolf_dart/features/map/vswap_parser.dart';
import 'package:wolf_dart/features/map/wolf_level.dart';
import 'package:wolf_dart/features/map/wolf_map_parser.dart';
class WolfMap {
/// The fully parsed and decompressed levels from the game files.
final List<WolfLevel> levels;
final List<Matrix<int>> textures;
// A private constructor so we can only instantiate this from the async loader
WolfMap._(this.levels);
WolfMap._(this.levels, this.textures);
/// Asynchronously loads the map files and parses them into a new WolfMap instance.
static Future<WolfMap> load() async {
// 1. Load the binary data
final mapHead = await rootBundle.load("assets/MAPHEAD.WL1");
final gameMaps = await rootBundle.load("assets/GAMEMAPS.WL1");
final vswap = await rootBundle.load("assets/VSWAP.WL1");
// 2. Parse the data using the parser we just built
final parsedLevels = WolfMapParser.parseMaps(mapHead, gameMaps);
final parsedTextures = VswapParser.parseWalls(vswap);
// 3. Return the populated instance!
return WolfMap._(parsedLevels);
return WolfMap._(parsedLevels, parsedTextures);
}
}