about summary refs log tree commit diff stats
path: root/data/maps/the_orb/rooms/R Room.txtpb
blob: a01726af65777098ed4ecb0308aa3288059e5d01 (plain) (blame)
1
2
3
4
5
name: "R Room"
letters {
  key: "r"
  path: "Components/Collectables/r"
}
olor: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "tracker_config.h"

#include <yaml-cpp/yaml.h>

#include <fstream>

#include "global.h"

void TrackerConfig::Load() {
  try {
    YAML::Node file = YAML::LoadFile(filename_);

    connection_details.ap_server = file["ap_server"].as<std::string>();
    connection_details.ap_player = file["ap_player"].as<std::string>();
    connection_details.ap_password = file["ap_password"].as<std::string>();
    asked_to_check_for_updates = file["asked_to_check_for_updates"].as<bool>();
    should_check_for_updates = file["should_check_for_updates"].as<bool>();
    hybrid_areas = file["hybrid_areas"].as<bool>();
    if (file["show_hunt_panels"] && file["show_hunt_panels"].as<bool>()) {
      visible_panels = kHUNT_PANELS;
    }

    if (file["connection_history"]) {
      for (const auto& connection : file["connection_history"]) {
        connection_history.push_back(ConnectionDetails{
          .ap_server = connection["ap_server"].as<std::string>(),
          .ap_player = connection["ap_player"].as<std::string>(),
          .ap_password = connection["ap_password"].as<std::string>()
        });
      }
    }

    ipc_address = file["ipc_address"].as<std::string>();
    track_position = file["track_position"].as<bool>();
    visible_panels =
        static_cast<VisiblePanels>(file["visible_panels"].as<int>());
  } catch (const std::exception&) {
    // It's fine if the file can't be loaded.
  }
}

void TrackerConfig::Save() {
  YAML::Node output;
  output["ap_server"] = connection_details.ap_server;
  output["ap_player"] = connection_details.ap_player;
  output["ap_password"] = connection_details.ap_password;
  output["asked_to_check_for_updates"] = asked_to_check_for_updates;
  output["should_check_for_updates"] = should_check_for_updates;
  output["hybrid_areas"] = hybrid_areas;
  
  output.remove("connection_history");
  for (const ConnectionDetails& details : connection_history) {
    YAML::Node connection;
    connection["ap_server"] = details.ap_server;
    connection["ap_player"] = details.ap_player;
    connection["ap_password"] = details.ap_password;

    output["connection_history"].push_back(connection);
  }

  output["ipc_address"] = ipc_address;
  output["track_position"] = track_position;
  output["visible_panels"] = static_cast<int>(visible_panels);

  std::ofstream filewriter(filename_);
  filewriter << output;
}

TrackerConfig& GetTrackerConfig() {
  static TrackerConfig* instance =
      new TrackerConfig(GetAbsolutePath("config.yaml"));
  return *instance;
}