De-coupled remaining aspects of game into packages
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
31
packages/wolf_3d_flutter/.gitignore
vendored
Normal file
31
packages/wolf_3d_flutter/.gitignore
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
/pubspec.lock
|
||||
**/doc/api/
|
||||
.dart_tool/
|
||||
.flutter-plugins-dependencies
|
||||
/build/
|
||||
/coverage/
|
||||
10
packages/wolf_3d_flutter/.metadata
Normal file
10
packages/wolf_3d_flutter/.metadata
Normal file
@@ -0,0 +1,10 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: "ff37bef603469fb030f2b72995ab929ccfc227f0"
|
||||
channel: "stable"
|
||||
|
||||
project_type: package
|
||||
3
packages/wolf_3d_flutter/CHANGELOG.md
Normal file
3
packages/wolf_3d_flutter/CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## 0.0.1
|
||||
|
||||
* TODO: Describe initial release.
|
||||
1
packages/wolf_3d_flutter/LICENSE
Normal file
1
packages/wolf_3d_flutter/LICENSE
Normal file
@@ -0,0 +1 @@
|
||||
TODO: Add your license here.
|
||||
39
packages/wolf_3d_flutter/README.md
Normal file
39
packages/wolf_3d_flutter/README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
<!--
|
||||
This README describes the package. If you publish this package to pub.dev,
|
||||
this README's contents appear on the landing page for your package.
|
||||
|
||||
For information about how to write a good package README, see the guide for
|
||||
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
|
||||
|
||||
For general information about developing packages, see the Dart guide for
|
||||
[creating packages](https://dart.dev/guides/libraries/create-packages)
|
||||
and the Flutter guide for
|
||||
[developing packages and plugins](https://flutter.dev/to/develop-packages).
|
||||
-->
|
||||
|
||||
TODO: Put a short description of the package here that helps potential users
|
||||
know whether this package might be useful for them.
|
||||
|
||||
## Features
|
||||
|
||||
TODO: List what your package can do. Maybe include images, gifs, or videos.
|
||||
|
||||
## Getting started
|
||||
|
||||
TODO: List prerequisites and provide or point to information on how to
|
||||
start using the package.
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Include short and useful examples for package users. Add longer examples
|
||||
to `/example` folder.
|
||||
|
||||
```dart
|
||||
const like = 'sample';
|
||||
```
|
||||
|
||||
## Additional information
|
||||
|
||||
TODO: Tell users more about the package: where to find more information, how to
|
||||
contribute to the package, how to file issues, what response they can expect
|
||||
from the package authors, and more.
|
||||
4
packages/wolf_3d_flutter/analysis_options.yaml
Normal file
4
packages/wolf_3d_flutter/analysis_options.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
# Additional information about this file can be found at
|
||||
# https://dart.dev/guides/language/analysis-options
|
||||
15
packages/wolf_3d_flutter/lib/audio/audio_adaptor.dart
Normal file
15
packages/wolf_3d_flutter/lib/audio/audio_adaptor.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
|
||||
import 'package:wolf_3d_engine/wolf_3d_engine.dart';
|
||||
import 'package:wolf_3d_flutter/wolf_3d.dart';
|
||||
|
||||
class FlutterAudioAdapter implements EngineAudio {
|
||||
@override
|
||||
void playLevelMusic(WolfLevel level) {
|
||||
Wolf3d.I.audio.playLevelMusic(level);
|
||||
}
|
||||
|
||||
@override
|
||||
void stopMusic() {
|
||||
Wolf3d.I.audio.stopMusic();
|
||||
}
|
||||
}
|
||||
111
packages/wolf_3d_flutter/lib/wolf_3d.dart
Normal file
111
packages/wolf_3d_flutter/lib/wolf_3d.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wolf_3d_data/wolf_3d_data.dart';
|
||||
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
|
||||
import 'package:wolf_3d_synth/wolf_3d_synth.dart';
|
||||
|
||||
class Wolf3d {
|
||||
Wolf3d._();
|
||||
static final Wolf3d _instance = Wolf3d._();
|
||||
static Wolf3d get I => _instance;
|
||||
|
||||
// --- State ---
|
||||
final List<WolfensteinData> availableGames = [];
|
||||
WolfensteinData? _activeGame;
|
||||
|
||||
// --- Core Systems ---
|
||||
final WolfAudio audio = WolfAudio();
|
||||
|
||||
// --- Getters ---
|
||||
WolfensteinData get activeGame {
|
||||
if (_activeGame == null) {
|
||||
throw StateError("No active game selected. Call setActiveGame() first.");
|
||||
}
|
||||
return _activeGame!;
|
||||
}
|
||||
|
||||
// --- Episode ---
|
||||
int _activeEpisode = 0;
|
||||
|
||||
int get activeEpisode => _activeEpisode;
|
||||
|
||||
void setActiveEpisode(int episodeIndex) {
|
||||
_activeEpisode = episodeIndex;
|
||||
}
|
||||
|
||||
// Convenience getters for the active game's assets
|
||||
List<WolfLevel> get levels => activeGame.episodes[activeEpisode].levels;
|
||||
List<Sprite> get walls => activeGame.walls;
|
||||
List<Sprite> get sprites => activeGame.sprites;
|
||||
List<PcmSound> get sounds => activeGame.sounds;
|
||||
List<AdLibSound> get adLibSounds => activeGame.adLibSounds;
|
||||
List<ImfMusic> get music => activeGame.music;
|
||||
List<VgaImage> get vgaImages => activeGame.vgaImages;
|
||||
|
||||
// --- Actions ---
|
||||
void setActiveGame(WolfensteinData game) {
|
||||
_activeGame = game;
|
||||
audio.activeGame = game;
|
||||
}
|
||||
|
||||
/// Initializes the engine by loading available game data.
|
||||
Future<void> init({String? directory}) async {
|
||||
await audio.init();
|
||||
availableGames.clear();
|
||||
|
||||
// 1. Bundle asset loading (migrated from GameSelectScreen)
|
||||
final versionsToTry = [
|
||||
(version: GameVersion.retail, path: 'retail'),
|
||||
(version: GameVersion.shareware, path: 'shareware'),
|
||||
];
|
||||
|
||||
for (final version in versionsToTry) {
|
||||
try {
|
||||
final ext = version.version.fileExtension;
|
||||
final folder = 'assets/${version.path}';
|
||||
|
||||
final data = WolfensteinLoader.loadFromBytes(
|
||||
version: version.version,
|
||||
vswap: await _tryLoad('$folder/VSWAP.$ext'),
|
||||
mapHead: await _tryLoad('$folder/MAPHEAD.$ext'),
|
||||
gameMaps: await _tryLoad('$folder/GAMEMAPS.$ext'),
|
||||
vgaDict: await _tryLoad('$folder/VGADICT.$ext'),
|
||||
vgaHead: await _tryLoad('$folder/VGAHEAD.$ext'),
|
||||
vgaGraph: await _tryLoad('$folder/VGAGRAPH.$ext'),
|
||||
audioHed: await _tryLoad('$folder/AUDIOHED.$ext'),
|
||||
audioT: await _tryLoad('$folder/AUDIOT.$ext'),
|
||||
);
|
||||
|
||||
availableGames.add(data);
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. External side-loading (non-web)
|
||||
if (!kIsWeb) {
|
||||
try {
|
||||
final externalGames = await WolfensteinLoader.discover(
|
||||
directoryPath: directory,
|
||||
recursive: true,
|
||||
);
|
||||
for (var entry in externalGames.entries) {
|
||||
if (!availableGames.any((g) => g.version == entry.key)) {
|
||||
availableGames.add(entry.value);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("External discovery failed: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<ByteData?> _tryLoad(String path) async {
|
||||
try {
|
||||
return await rootBundle.load(path);
|
||||
} catch (e) {
|
||||
debugPrint("Asset not found: $path");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
5
packages/wolf_3d_flutter/lib/wolf_3d_flutter.dart
Normal file
5
packages/wolf_3d_flutter/lib/wolf_3d_flutter.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
/// A Calculator.
|
||||
class Calculator {
|
||||
/// Returns [value] plus 1.
|
||||
int addOne(int value) => value + 1;
|
||||
}
|
||||
60
packages/wolf_3d_flutter/pubspec.yaml
Normal file
60
packages/wolf_3d_flutter/pubspec.yaml
Normal file
@@ -0,0 +1,60 @@
|
||||
name: wolf_3d_flutter
|
||||
description: "A new Flutter package project."
|
||||
version: 0.0.1
|
||||
homepage:
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.1
|
||||
flutter: ">=1.17.0"
|
||||
|
||||
resolution: workspace
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
wolf_3d_data: any
|
||||
wolf_3d_data_types: any
|
||||
wolf_3d_synth: any
|
||||
wolf_3d_engine: any
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^6.0.0
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
# The following section is specific to Flutter packages.
|
||||
flutter:
|
||||
|
||||
# To add assets to your package, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
#
|
||||
# For details regarding assets in packages, see
|
||||
# https://flutter.dev/to/asset-from-package
|
||||
#
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/to/resolution-aware-images
|
||||
|
||||
# To add custom fonts to your package, add a fonts section here,
|
||||
# in this "flutter" section. Each entry in this list should have a
|
||||
# "family" key with the font family name, and a "fonts" key with a
|
||||
# list giving the asset and other descriptors for the font. For
|
||||
# example:
|
||||
# fonts:
|
||||
# - family: Schyler
|
||||
# fonts:
|
||||
# - asset: fonts/Schyler-Regular.ttf
|
||||
# - asset: fonts/Schyler-Italic.ttf
|
||||
# style: italic
|
||||
# - family: Trajan Pro
|
||||
# fonts:
|
||||
# - asset: fonts/TrajanPro.ttf
|
||||
# - asset: fonts/TrajanPro_Bold.ttf
|
||||
# weight: 700
|
||||
#
|
||||
# For details regarding fonts in packages, see
|
||||
# https://flutter.dev/to/font-from-package
|
||||
Reference in New Issue
Block a user