Moved data loading to parser. Added remaining shareware data.
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:wolf_3d_data/wolf_3d_data.dart';
|
||||
import 'package:wolf_dart/features/map/door.dart';
|
||||
import 'package:wolf_dart/features/entities/door.dart';
|
||||
|
||||
class DoorManager {
|
||||
// Key is '$x,$y'
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wolf_3d_data/wolf_3d_data.dart';
|
||||
|
||||
class WolfMap {
|
||||
/// The fully parsed and decompressed levels from the game files.
|
||||
final List<WolfLevel> levels;
|
||||
final List<Sprite> textures;
|
||||
final List<Sprite> sprites;
|
||||
|
||||
// A private constructor so we can only instantiate this from the async loader
|
||||
WolfMap._(
|
||||
this.levels,
|
||||
this.textures,
|
||||
this.sprites,
|
||||
);
|
||||
|
||||
/// Asynchronously loads the map files and parses them into a new WolfMap instance.
|
||||
static Future<WolfMap> loadShareware() 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 = WLParser.parseMaps(
|
||||
mapHead,
|
||||
gameMaps,
|
||||
isShareware: true,
|
||||
);
|
||||
final parsedTextures = WLParser.parseWalls(vswap);
|
||||
final parsedSprites = WLParser.parseSprites(vswap);
|
||||
|
||||
// 3. Return the populated instance!
|
||||
return WolfMap._(
|
||||
parsedLevels,
|
||||
parsedTextures,
|
||||
parsedSprites,
|
||||
);
|
||||
}
|
||||
|
||||
/// Asynchronously loads the map files and parses them into a new WolfMap instance.
|
||||
static Future<WolfMap> loadRetail() async {
|
||||
// 1. Load the binary data
|
||||
final mapHead = await rootBundle.load("assets/MAPHEAD.WL6");
|
||||
final gameMaps = await rootBundle.load("assets/GAMEMAPS.WL6");
|
||||
final vswap = await rootBundle.load("assets/VSWAP.WL6");
|
||||
|
||||
// 2. Parse the data using the parser we just built
|
||||
final parsedLevels = WLParser.parseMaps(mapHead, gameMaps);
|
||||
final parsedTextures = WLParser.parseWalls(vswap);
|
||||
final parsedSprites = WLParser.parseSprites(vswap);
|
||||
|
||||
// 3. Return the populated instance!
|
||||
return WolfMap._(
|
||||
parsedLevels,
|
||||
parsedTextures,
|
||||
parsedSprites,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wolf_3d_data/wolf_3d_data.dart';
|
||||
import 'package:wolf_dart/classes/coordinate_2d.dart';
|
||||
import 'package:wolf_dart/features/difficulty/difficulty.dart';
|
||||
@@ -13,7 +14,6 @@ import 'package:wolf_dart/features/entities/entity_registry.dart';
|
||||
import 'package:wolf_dart/features/entities/map_objects.dart';
|
||||
import 'package:wolf_dart/features/entities/pushwall_manager.dart';
|
||||
import 'package:wolf_dart/features/input/input_manager.dart';
|
||||
import 'package:wolf_dart/features/map/wolf_map.dart';
|
||||
import 'package:wolf_dart/features/player/player.dart';
|
||||
import 'package:wolf_dart/features/renderer/raycast_painter.dart';
|
||||
import 'package:wolf_dart/features/renderer/weapon_painter.dart';
|
||||
@@ -44,8 +44,9 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
|
||||
late Ticker _gameLoop;
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
late WolfMap gameMap;
|
||||
late WolfensteinData gameData;
|
||||
late Level currentLevel;
|
||||
late WolfLevel activeLevel;
|
||||
|
||||
final double fov = math.pi / 3;
|
||||
|
||||
@@ -64,15 +65,22 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
}
|
||||
|
||||
Future<void> _initGame(bool isShareware) async {
|
||||
gameMap = isShareware
|
||||
? await WolfMap.loadShareware()
|
||||
: await WolfMap.loadRetail();
|
||||
currentLevel = gameMap.levels[0].wallGrid;
|
||||
gameData = await WLParser.loadAsync(
|
||||
(filename) => rootBundle.load('assets/retail/$filename'),
|
||||
);
|
||||
|
||||
print('Detected Game Version: ${gameData.version.name}');
|
||||
print('Loaded ${gameData.levels.length} levels!');
|
||||
print('Loaded ${gameData.vgaImages.length} images!');
|
||||
|
||||
// Get the first level out of the data class
|
||||
activeLevel = gameData.levels.first;
|
||||
|
||||
// Set up your grids directly from the active level
|
||||
currentLevel = activeLevel.wallGrid;
|
||||
final Level objectLevel = activeLevel.objectGrid;
|
||||
|
||||
doorManager.initDoors(currentLevel);
|
||||
|
||||
final Level objectLevel = gameMap.levels[0].objectGrid;
|
||||
|
||||
pushwallManager.initPushwalls(currentLevel, objectLevel);
|
||||
|
||||
for (int y = 0; y < 64; y++) {
|
||||
@@ -108,7 +116,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
x + 0.5,
|
||||
y + 0.5,
|
||||
widget.difficulty,
|
||||
gameMap.sprites.length,
|
||||
gameData.sprites.length,
|
||||
isSharewareMode: isShareware,
|
||||
);
|
||||
|
||||
@@ -354,7 +362,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
entity.x,
|
||||
entity.y,
|
||||
widget.difficulty,
|
||||
gameMap.sprites.length,
|
||||
gameData.sprites.length,
|
||||
);
|
||||
|
||||
if (droppedAmmo != null) {
|
||||
@@ -403,7 +411,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
}
|
||||
|
||||
if (widget.showSpriteGallery) {
|
||||
return SpriteGallery(sprites: gameMap.sprites);
|
||||
return SpriteGallery(sprites: gameData.sprites);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
@@ -429,12 +437,12 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
),
|
||||
painter: RaycasterPainter(
|
||||
map: currentLevel,
|
||||
textures: gameMap.textures,
|
||||
textures: gameData.walls,
|
||||
player: player,
|
||||
fov: fov,
|
||||
doorOffsets: doorManager.getOffsetsForRenderer(),
|
||||
entities: entities,
|
||||
sprites: gameMap.sprites,
|
||||
sprites: gameData.sprites,
|
||||
activePushwall: pushwallManager.activePushwall,
|
||||
),
|
||||
),
|
||||
@@ -451,9 +459,9 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
child: CustomPaint(
|
||||
painter: WeaponPainter(
|
||||
sprite:
|
||||
gameMap.sprites[player.currentWeapon
|
||||
gameData.sprites[player.currentWeapon
|
||||
.getCurrentSpriteIndex(
|
||||
gameMap.sprites.length,
|
||||
gameData.sprites.length,
|
||||
)],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user