Preserve state when switching renderers
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -33,10 +33,7 @@ class _GameScreenState extends State<GameScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_input = Wolf3dFlutterInput();
|
||||
|
||||
// The Host Screen owns the engine lifecycle
|
||||
_engine = WolfEngine(
|
||||
data: widget.data,
|
||||
difficulty: widget.difficulty,
|
||||
@@ -45,7 +42,6 @@ class _GameScreenState extends State<GameScreen> {
|
||||
input: _input,
|
||||
onGameWon: () => Navigator.of(context).pop(),
|
||||
);
|
||||
|
||||
_engine.init();
|
||||
}
|
||||
|
||||
@@ -54,20 +50,17 @@ class _GameScreenState extends State<GameScreen> {
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
// Render the active view
|
||||
_useAsciiMode
|
||||
? WolfAsciiRenderer(engine: _engine)
|
||||
: WolfFlutterRenderer(engine: _engine),
|
||||
|
||||
// Invisible listener to trap the 'Tab' key and swap renderers
|
||||
// TAB listener
|
||||
Focus(
|
||||
autofocus: false,
|
||||
autofocus: true,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.tab) {
|
||||
setState(() {
|
||||
_useAsciiMode = !_useAsciiMode;
|
||||
});
|
||||
setState(() => _useAsciiMode = !_useAsciiMode);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
@@ -75,16 +68,21 @@ class _GameScreenState extends State<GameScreen> {
|
||||
child: const SizedBox.shrink(),
|
||||
),
|
||||
|
||||
// Optional: A little UI hint
|
||||
// Loading Overlay
|
||||
if (!_engine.isInitialized)
|
||||
Container(
|
||||
color: Colors.black,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Colors.teal),
|
||||
),
|
||||
),
|
||||
|
||||
Positioned(
|
||||
top: 16,
|
||||
right: 16,
|
||||
child: Text(
|
||||
'Press TAB to swap renderers',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: 12,
|
||||
),
|
||||
'TAB: Swap Renderer',
|
||||
style: TextStyle(color: Colors.white.withValues(alpha: 0.5)),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user