settings.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #pragma once
  2. #include <string_view>
  3. #include "../../state/account/account_state.h"
  4. #include "../../state/activity/defaults/definition.h"
  5. #include "../../state/investment/investment.h"
  6. #include "../../state/unlocks/definition.h"
  7. #include "../logging/log.h"
  8. #include "client/definition.h"
  9. #include "server/definition.h"
  10. #include "steam/definition.h"
  11. namespace sunrise::core::settings {
  12. /**
  13. * Layout version of the settings file this build writes and expects.
  14. * Raise it when a key is renamed, removed, changes meaning, or must take a new default.
  15. * Adding a key needs no raise, because a missing key already takes its default.
  16. */
  17. inline constexpr std::uint32_t kSettingsVersion = 8;
  18. /** Parsed read-only process settings. */
  19. struct Settings {
  20. /**
  21. * Layout version the file was written against. Zero means the key was missing, which is
  22. * every file written before versioning. Checked against kSettingsVersion at load.
  23. */
  24. std::uint32_t version{};
  25. /** Core-owned sink and channel policy. */
  26. log::Settings logging;
  27. /** Options used only by the Client layer. */
  28. client::Settings client;
  29. /** Options used only by the Server layer. */
  30. server::Settings server;
  31. /** Options used only by the Steam compatibility layer. */
  32. steam::Settings steam;
  33. /** Complete authored account State, or an empty account. */
  34. state::AccountState initialAccount;
  35. /** Small local destination fallback published when State starts. */
  36. state::activity::defaults::ActivityDefaults initialActivityDefaults;
  37. /** Authored acquired-flag and objective policy published into the account object. */
  38. state::unlocks::Table initialUnlocks;
  39. /** Authored family-5 unlock overrides. Only the two override lists are authored here. */
  40. state::Family5State initialFamily5;
  41. };
  42. /** @return The complete default settings. */
  43. [[nodiscard]] Settings defaults() noexcept;
  44. /**
  45. * Parses supported JSON settings on top of the defaults.
  46. * @param json Complete settings text.
  47. * @param output Receives the settings only after the whole document is valid.
  48. * @return True when the document matches the supported settings.
  49. */
  50. [[nodiscard]] bool parse(std::string_view json, Settings& output) noexcept;
  51. /**
  52. * Loads the settings file next to the module when it is there.
  53. * @param module Loaded DLL, used to find the settings path.
  54. * @return True when defaults or a valid settings file are active.
  55. */
  56. [[nodiscard]] bool initialize(void* module) noexcept;
  57. /** Resets active settings to the fixed defaults. */
  58. void shutdown() noexcept;
  59. /** @return Active read-only Core settings. */
  60. [[nodiscard]] const Settings& get() noexcept;
  61. } // namespace sunrise::core::settings