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

summaryrefslogtreecommitdiff
path: root/source/game/StarPlayerLog.cpp
blob: 6b2b21af8877029b85b1a542919942416e3d7528 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "StarPlayerLog.hpp"
#include "StarJsonExtra.hpp"

namespace Star {

PlayerLog::PlayerLog() {
  m_deathCount = 0;
  m_playTime = 0;
  m_introComplete = false;
  m_scannedObjects = StringSet();
  m_radioMessages = StringSet();
  m_cinematics = StringSet();
}

PlayerLog::PlayerLog(Json const& json) {
  m_deathCount = json.getInt("deathCount");
  m_playTime = json.getDouble("playTime");
  m_introComplete = json.getBool("introComplete");
  m_scannedObjects = jsonToStringSet(json.get("scannedObjects"));
  m_radioMessages = jsonToStringSet(json.get("radioMessages"));
  m_cinematics = jsonToStringSet(json.get("cinematics"));

  for (auto pair : json.get("collections").iterateObject())
    m_collections[pair.first] = jsonToStringSet(pair.second);
}

Json PlayerLog::toJson() const {
  auto collections = JsonObject();
  for (auto pair : m_collections)
    collections[pair.first] = jsonFromStringSet(pair.second);

  return JsonObject{{"deathCount", m_deathCount},
      {"playTime", m_playTime},
      {"introComplete", m_introComplete},
      {"scannedObjects", jsonFromStringSet(m_scannedObjects)},
      {"radioMessages", jsonFromStringSet(m_radioMessages)},
      {"cinematics", jsonFromStringSet(m_cinematics)},
      {"collections", collections}};
}

int PlayerLog::deathCount() const {
  return m_deathCount;
}

void PlayerLog::addDeathCount(int deaths) {
  m_deathCount += deaths;
}

double PlayerLog::playTime() const {
  return m_playTime;
}

void PlayerLog::addPlayTime(double elapsedTime) {
  m_playTime += elapsedTime;
}

bool PlayerLog::introComplete() const {
  return m_introComplete;
}

void PlayerLog::setIntroComplete(bool complete) {
  m_introComplete = complete;
}

StringSet PlayerLog::scannedObjects() const {
  return m_scannedObjects;
}

bool PlayerLog::addScannedObject(String const& objectName) {
  return m_scannedObjects.add(objectName);
}

void PlayerLog::removeScannedObject(String const& objectName) {
  m_scannedObjects.remove(objectName);
}

void PlayerLog::clearScannedObjects() {
  m_scannedObjects.clear();
}

StringSet PlayerLog::radioMessages() const {
  return m_radioMessages;
}

bool PlayerLog::addRadioMessage(String const& messageName) {
  return m_radioMessages.add(messageName);
}

void PlayerLog::clearRadioMessages() {
  m_radioMessages.clear();
}

StringSet PlayerLog::cinematics() const {
  return m_cinematics;
}

bool PlayerLog::addCinematic(String const& cinematic) {
  return m_cinematics.add(cinematic);
}

void PlayerLog::clearCinematics() {
  m_cinematics.clear();
}

StringList PlayerLog::collections() const {
  return m_collections.keys();
}

StringSet PlayerLog::collectables(String const& collection) const {
  if (!m_collections.contains(collection))
    return {};

  return m_collections.get(collection);
}

bool PlayerLog::addCollectable(String const& collection, String const& collectable) {
  if (!m_collections.contains(collection))
    m_collections[collection] = {};

  return m_collections[collection].add(collectable);
}

void PlayerLog::clearCollectables(String const& collection) {
  m_collections.remove(collection);
}

}