Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarPlayerBlueprints.cpp
blob: 68daf2b8a61c7a8a11393636fb0069aa0c9c23fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "StarPlayerBlueprints.hpp"
#include "StarItemDescriptor.hpp"

namespace Star {

PlayerBlueprints::PlayerBlueprints() {}

PlayerBlueprints::PlayerBlueprints(Json const& variant) {
  m_knownBlueprints =
      transform<HashSet<ItemDescriptor>>(variant.get("knownBlueprints").toArray(), construct<ItemDescriptor>());
  m_newBlueprints =
      transform<HashSet<ItemDescriptor>>(variant.get("newBlueprints").toArray(), construct<ItemDescriptor>());
}

Json PlayerBlueprints::toJson() const {
  return JsonObject{{"knownBlueprints", transform<JsonArray>(m_knownBlueprints, mem_fn(&ItemDescriptor::toJson))},
      {"newBlueprints", transform<JsonArray>(m_newBlueprints, mem_fn(&ItemDescriptor::toJson))}};
}

bool PlayerBlueprints::isKnown(ItemDescriptor const& itemDescriptor) const {
  return m_knownBlueprints.contains(itemDescriptor.singular());
}

bool PlayerBlueprints::isNew(ItemDescriptor const& itemDescriptor) const {
  return m_newBlueprints.contains(itemDescriptor.singular());
}

void PlayerBlueprints::add(ItemDescriptor const& itemDescriptor) {
  if (m_knownBlueprints.add(itemDescriptor.singular()))
    m_newBlueprints.add(itemDescriptor.singular());
}

void PlayerBlueprints::markAsRead(ItemDescriptor const& itemDescriptor) {
  m_newBlueprints.remove(itemDescriptor.singular());
}

}