diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-12 00:28:50 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-12 00:28:50 +0100 |
| commit | 808294adad3f378ad8d66b698acf8df7f49c2302 (patch) | |
| tree | cfd11a1395a8ad482311969f86abbbad97e7e0b4 /server/lib/core/settings.dart | |
| parent | f6955e34489c79f6d5b764cb6a39b1387366b433 (diff) | |
Phase 1: headless game engine on the server (M1)
Complete mechanical port of the reference app's game engine to
server/lib/core/ so later phases are UI-only:
- models/ (7), state/ (GameState + 18 part files), methods/ (7),
game_methods, 79 command files, enums, card_stack, stat_calculator,
action_handler (index, 250-deep history, save-per-action, undo/redo),
disk-based game_data, l10n, translation_service, service_locator
- ValueNotifier/ChangeNotifier removed in favor of plain fields with a
minimal GameState listener hook for the Phase 2 broadcast layer;
shared_preferences replaced by the SaveStore abstraction
(InMemory for tests, File-backed for bin/main.dart)
- command registry: 82 entries mapping wire names to constructors with
arg validation; live-object args (loot/ability cards, figure lists)
travel as id/name/nr and resolve against live state, enums by name,
injected singletons never serialize
- line_builder ported to Phase 1 scope: stat_applier + minimal
LineBuilder (isElement, tokens); widget rendering deferred to Phase 4
- ported test suite: 81 test files, 562 tests green (command tests 1:1
with the reference, resource tests, registry smoke tests)
- new headless integration test drives a full round: scenario setup,
characters + standee, secret-initiative gate, draw, every figure's
turn (incl. undo/redo), next round, round 2, round 3
- PORTING.md: the conventions contract used for the port
- bin/main.dart boots the engine (file save store, assets/data) before
serving; pubspec gains built_collection, collection, get_it, intl
- dart format drift on pre-existing net/test files from the current
formatter (whitespace only)
dart analyze warning-free; dart test 562/562.
Diffstat (limited to 'server/lib/core/settings.dart')
| -rw-r--r-- | server/lib/core/settings.dart | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/server/lib/core/settings.dart b/server/lib/core/settings.dart new file mode 100644 index 0000000..1f48a87 --- /dev/null +++ b/server/lib/core/settings.dart @@ -0,0 +1,251 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:x_haven_server/core/commands/load_character_save_command.dart'; +import 'package:x_haven_server/core/commands/load_save_command.dart'; +import 'package:x_haven_server/core/service_locator.dart'; + +import 'enums.dart'; +import 'state/game_state.dart'; + +/// Server-side settings. +/// +/// Ported from the reference app with the Flutter-specific parts removed: +/// no `ValueNotifier`s (plain fields), no window management, no +/// shared_preferences persistence (server settings persistence lands in +/// Phase 6). The `server`/`client` network settings are gone — this process +/// is always the server. +class Settings { + static const double _kDesktopBarScale = 1.6; + + double userScalingMainList = 1.0; + double userScalingBars = + (Platform.isWindows || Platform.isLinux || Platform.isMacOS) + ? _kDesktopBarScale + : 1.0; + double userScalingMenus = 1.0; + bool fullScreen = true; + bool darkMode = false; + bool noInit = true; + bool noStandees = false; + bool randomStandees = false; + bool noCalculation = false; + bool expireConditions = true; + bool hideLootDeck = false; + bool shimmer = Platform.isWindows || Platform.isLinux || Platform.isMacOS; + + /// Opt-in display power saving, in escalating tiers. Defaults to + /// [PowerMode.normal]: the higher tiers trade away polish or convenience, so + /// they are the user's choice to make. + /// + /// Most of the codebase should not read this directly — use + /// `reducePowerEnabled()` in `ui_utils.dart`, which asks the narrower + /// question "may I degrade visual quality?". + PowerMode powerMode = PowerMode.normal; + bool showScenarioNames = true; + bool showCustomContent = true; + bool showSectionsInMainView = true; + bool showReminders = true; + bool autoAddStandees = true; + bool autoAddSpawns = true; + bool showAmdDeck = true; + bool showBattleGoalReminder = true; + bool fhHazTerrainCalcInOGGloom = true; + bool showCharacterAMD = true; + bool enableHeathWheel = true; + + //used for both initiative and search menus + bool softNumpadInput = false; + + Style style = Style.original; + String locale = 'en'; + + final Map<String, String> saves = {}; + final Map<String, String> characterSaves = {}; + + void loadSave(String saveName, {GameState? gameState}) { + String? save = saves[saveName]; + if (save != null) { + final gs = gameState ?? getIt<GameState>(); + gs.action(LoadSaveCommand(saveName, save, gameState: gs)); + } + } + + void saveState(String saveName, {GameState? gameState}) { + saves[saveName] = (gameState ?? getIt<GameState>()).toString(); + } + + void deleteSave(String saveName) { + saves.remove(saveName); + } + + void loadCharacterSave(String saveName, {GameState? gameState}) { + String? save = characterSaves[saveName]; + if (save != null) { + final gs = gameState ?? getIt<GameState>(); + gs.action(LoadCharacterSaveCommand(saveName, save, gameState: gs)); + } + } + + void saveCharacterState(String saveName, Character character) { + characterSaves['$saveName\n${character.id}'] = character.toSave(); + } + + void deleteCharacterSave(String saveId) { + characterSaves.remove(saveId); + } + + /// Applies a settings JSON previously produced by [toString]. + /// + /// Ported from the reference app's `loadFromDisk` field parsing, minus the + /// network/settings persistence parts. (Server settings persistence lands + /// in Phase 6.) + void loadFromData(String state) { + Map<String, dynamic> data = jsonDecode(state); + + if (data["userScalingMainList"] != null) { + userScalingMainList = (data["userScalingMainList"] as num).toDouble(); + } + if (data["userScalingBars"] != null) { + userScalingBars = (data["userScalingBars"] as num).toDouble(); + } + if (data["userScalingMenus"] != null) { + userScalingMenus = (data["userScalingMenus"] as num).toDouble(); + } + if (data["fullScreen"] != null) { + fullScreen = data["fullScreen"] as bool; + } + if (data["softNumpadInput"] != null) { + softNumpadInput = data["softNumpadInput"] as bool; + } + if (data["darkMode"] != null) { + darkMode = data["darkMode"] as bool; + } + if (data["noInit"] != null) { + noInit = data["noInit"] as bool; + } + if (data["noStandees"] != null) { + noStandees = data["noStandees"] as bool; + } + if (data["randomStandees"] != null) { + randomStandees = data["randomStandees"] as bool; + } + if (data["noCalculation"] != null) { + noCalculation = data["noCalculation"] as bool; + } + if (data["hideLootDeck"] != null) { + hideLootDeck = data["hideLootDeck"] as bool; + } + if (data["style"] != null) { + style = Style.values[data["style"] as int]; + } + if (data["expireConditions"] != null) { + expireConditions = data["expireConditions"] as bool; + } + + if (data["shimmer"] != null) { + shimmer = data["shimmer"] as bool; + } + final powerModeIdx = data["powerMode"] as int?; + if (powerModeIdx != null && + powerModeIdx >= 0 && + powerModeIdx < PowerMode.values.length) { + powerMode = PowerMode.values[powerModeIdx]; + } + if (data["showScenarioNames"] != null) { + showScenarioNames = data["showScenarioNames"] as bool; + } + if (data["showCustomContent"] != null) { + showCustomContent = data["showCustomContent"] as bool; + } + + if (data["showSectionsInMainView"] != null) { + showSectionsInMainView = data["showSectionsInMainView"] as bool; + } + + if (data["showReminders"] != null) { + showReminders = data["showReminders"] as bool; + } + + if (data["autoAddStandees"] != null) { + autoAddStandees = data["autoAddStandees"] as bool; + } + + if (data["autoAddSpawns"] != null) { + autoAddSpawns = data["autoAddSpawns"] as bool; + } + + if (data["showAmdDeck"] != null) { + showAmdDeck = data["showAmdDeck"] as bool; + } + + if (data["showBattleGoalReminder"] != null) { + showBattleGoalReminder = data["showBattleGoalReminder"] as bool; + } + + if (data["fhHazTerrainCalcInOGGloom"] != null) { + fhHazTerrainCalcInOGGloom = data["fhHazTerrainCalcInOGGloom"] as bool; + } + + if (data["showCharacterAMD"] != null) { + showCharacterAMD = data["showCharacterAMD"] as bool; + } + + if (data["enableHeathWheel"] != null) { + enableHeathWheel = data["enableHeathWheel"] as bool; + } + + if (data["locale"] != null) { + locale = data["locale"] as String; + } + + if (data["saves"] != null) { + Map<String, dynamic> map = data["saves"] as Map<String, dynamic>; + for (final key in map.keys) { + saves[key] = map[key] as String; + } + } + + if (data["characterSaves"] != null) { + Map<String, dynamic> map = data["characterSaves"] as Map<String, dynamic>; + for (final key in map.keys) { + characterSaves[key] = map[key] as String; + } + } + } + + @override + String toString() { + return '{' + '"userScalingMainList": $userScalingMainList, ' + '"userScalingBars": $userScalingBars, ' + '"userScalingMenus": $userScalingMenus, ' + '"fullScreen": $fullScreen, ' + '"softNumpadInput": $softNumpadInput, ' + '"noInit": $noInit, ' + '"noStandees": $noStandees, ' + '"randomStandees": $randomStandees, ' + '"noCalculation": $noCalculation, ' + '"expireConditions": $expireConditions, ' + '"hideLootDeck": $hideLootDeck, ' + '"style": ${style.index}, ' + '"darkMode": $darkMode, ' + '"shimmer": $shimmer, ' + '"powerMode": ${powerMode.index}, ' + '"showScenarioNames": $showScenarioNames, ' + '"showCustomContent": $showCustomContent, ' + '"showSectionsInMainView": $showSectionsInMainView, ' + '"showReminders": $showReminders, ' + '"autoAddStandees": $autoAddStandees, ' + '"autoAddSpawns": $autoAddSpawns, ' + '"showAmdDeck": $showAmdDeck, ' + '"showBattleGoalReminder": $showBattleGoalReminder, ' + '"fhHazTerrainCalcInOGGloom": $fhHazTerrainCalcInOGGloom, ' + '"showCharacterAMD": $showCharacterAMD, ' + '"enableHeathWheel": $enableHeathWheel, ' + '"locale": "$locale", ' + '"saves": ${jsonEncode(saves)}, ' + '"characterSaves": ${jsonEncode(characterSaves)} ' + '}'; + } +} |
