feat: Implement platform-specific persistence for renderer settings and save games
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -12,9 +12,7 @@ import 'package:wolf_3d_dart/wolf_3d_engine.dart';
|
||||
class CliRendererSettingsPersistence extends RendererSettingsPersistence
|
||||
with JsonRendererSettingsPersistence {
|
||||
CliRendererSettingsPersistence({String? filePath})
|
||||
: _filePath =
|
||||
filePath ??
|
||||
'${Platform.environment['HOME'] ?? '.'}/.wolf3d_cli_settings.json';
|
||||
: _filePath = filePath ?? '${_platformConfigDir()}/settings.json';
|
||||
|
||||
final String _filePath;
|
||||
|
||||
@@ -40,3 +38,21 @@ class CliRendererSettingsPersistence extends RendererSettingsPersistence
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String _platformConfigDir() {
|
||||
if (Platform.isLinux) {
|
||||
final String xdg = Platform.environment['XDG_CONFIG_HOME'] ?? '';
|
||||
final String home = Platform.environment['HOME'] ?? '.';
|
||||
return xdg.isNotEmpty ? '$xdg/wolf3d' : '$home/.config/wolf3d';
|
||||
}
|
||||
if (Platform.isMacOS) {
|
||||
final String home = Platform.environment['HOME'] ?? '.';
|
||||
return '$home/Library/Application Support/wolf3d';
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
final String appData = Platform.environment['APPDATA'] ?? '.';
|
||||
return '$appData/wolf3d';
|
||||
}
|
||||
final String home = Platform.environment['HOME'] ?? '.';
|
||||
return '$home/.config/wolf3d';
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ import 'package:wolf_3d_dart/wolf_3d_engine.dart';
|
||||
/// `SAVEGAM{slot}.{ext}` where `{ext}` follows the active game version.
|
||||
class CliSaveGamePersistence implements SaveGamePersistence {
|
||||
CliSaveGamePersistence({String? directoryPath})
|
||||
: _directoryPath =
|
||||
directoryPath ??
|
||||
'${Platform.environment['HOME'] ?? '.'}/.wolf3d_saves';
|
||||
: _directoryPath = directoryPath ?? '${_platformConfigDir()}/saves';
|
||||
|
||||
final String _directoryPath;
|
||||
|
||||
@@ -66,3 +64,21 @@ class CliSaveGamePersistence implements SaveGamePersistence {
|
||||
return '$_directoryPath/SAVEGAM$normalizedSlot.${version.fileExtension}';
|
||||
}
|
||||
}
|
||||
|
||||
String _platformConfigDir() {
|
||||
if (Platform.isLinux) {
|
||||
final String xdg = Platform.environment['XDG_CONFIG_HOME'] ?? '';
|
||||
final String home = Platform.environment['HOME'] ?? '.';
|
||||
return xdg.isNotEmpty ? '$xdg/wolf3d' : '$home/.config/wolf3d';
|
||||
}
|
||||
if (Platform.isMacOS) {
|
||||
final String home = Platform.environment['HOME'] ?? '.';
|
||||
return '$home/Library/Application Support/wolf3d';
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
final String appData = Platform.environment['APPDATA'] ?? '.';
|
||||
return '$appData/wolf3d';
|
||||
}
|
||||
final String home = Platform.environment['HOME'] ?? '.';
|
||||
return '$home/.config/wolf3d';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user