Migrate all Dart packages to a single wolf_3d_dart package
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
48
packages/wolf_3d_dart/lib/src/input/cli_input.dart
Normal file
48
packages/wolf_3d_dart/lib/src/input/cli_input.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'package:wolf_3d_dart/wolf_3d_entities.dart';
|
||||
import 'package:wolf_3d_dart/src/input/wolf_3d_input.dart';
|
||||
|
||||
class CliInput extends Wolf3dInput {
|
||||
// Pending buffer for asynchronous stdin events
|
||||
bool _pForward = false;
|
||||
bool _pBackward = false;
|
||||
bool _pLeft = false;
|
||||
bool _pRight = false;
|
||||
bool _pFire = false;
|
||||
bool _pInteract = false;
|
||||
WeaponType? _pWeapon;
|
||||
|
||||
/// Call this directly from the stdin listener to queue inputs for the next frame
|
||||
void handleKey(List<int> bytes) {
|
||||
String char = String.fromCharCodes(bytes).toLowerCase();
|
||||
|
||||
if (char == 'w') _pForward = true;
|
||||
if (char == 's') _pBackward = true;
|
||||
if (char == 'a') _pLeft = true;
|
||||
if (char == 'd') _pRight = true;
|
||||
|
||||
// --- NEW MAPPINGS ---
|
||||
if (char == 'j') _pFire = true;
|
||||
if (char == ' ') _pInteract = true;
|
||||
|
||||
if (char == '1') _pWeapon = WeaponType.knife;
|
||||
if (char == '2') _pWeapon = WeaponType.pistol;
|
||||
if (char == '3') _pWeapon = WeaponType.machineGun;
|
||||
if (char == '4') _pWeapon = WeaponType.chainGun;
|
||||
}
|
||||
|
||||
@override
|
||||
void update() {
|
||||
// 1. Move pending inputs to the active state
|
||||
isMovingForward = _pForward;
|
||||
isMovingBackward = _pBackward;
|
||||
isTurningLeft = _pLeft;
|
||||
isTurningRight = _pRight;
|
||||
isFiring = _pFire;
|
||||
isInteracting = _pInteract;
|
||||
requestedWeapon = _pWeapon;
|
||||
|
||||
// 2. Wipe the pending slate clean for the next frame
|
||||
_pForward = _pBackward = _pLeft = _pRight = _pFire = _pInteract = false;
|
||||
_pWeapon = null;
|
||||
}
|
||||
}
|
||||
27
packages/wolf_3d_dart/lib/src/input/wolf_3d_input.dart
Normal file
27
packages/wolf_3d_dart/lib/src/input/wolf_3d_input.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:wolf_3d_dart/wolf_3d_engine.dart';
|
||||
import 'package:wolf_3d_dart/wolf_3d_entities.dart';
|
||||
|
||||
abstract class Wolf3dInput {
|
||||
bool isMovingForward = false;
|
||||
bool isMovingBackward = false;
|
||||
bool isTurningLeft = false;
|
||||
bool isTurningRight = false;
|
||||
bool isInteracting = false;
|
||||
bool isFiring = false;
|
||||
WeaponType? requestedWeapon;
|
||||
|
||||
/// Called once per frame by the game loop to refresh the state.
|
||||
void update();
|
||||
|
||||
/// Exports the current state as a clean DTO for the engine.
|
||||
/// Subclasses do not need to override this.
|
||||
EngineInput get currentInput => EngineInput(
|
||||
isMovingForward: isMovingForward,
|
||||
isMovingBackward: isMovingBackward,
|
||||
isTurningLeft: isTurningLeft,
|
||||
isTurningRight: isTurningRight,
|
||||
isFiring: isFiring,
|
||||
isInteracting: isInteracting,
|
||||
requestedWeapon: requestedWeapon,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user