MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / mergeServiceStatistics

Method mergeServiceStatistics

source/game/StarStatistics.cpp:173–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173void Statistics::mergeServiceStatistics() {
174 if (!m_service || !m_service->initialized() || m_service->error()) return;
175
176 // Publish achievements we unlocked when the platform service was unavailable.
177 StringSet serviceAchievements = m_service->achievementsUnlocked();
178 for (String const& achievement : m_achievements.difference(serviceAchievements)) {
179 m_service->unlockAchievement(achievement);
180 }
181 // Locally store all the achievements we unlocked in a different install:
182 m_achievements.addAll(serviceAchievements);
183
184 // Publish our local statistics, in case we made progress while the service
185 // was unavailable.
186 for (auto const& stat : m_stats) {
187 m_service->setStat(stat.first, stat.second.type, stat.second.value);
188 }
189
190 // However, don't _pull_ stats from the service - not all stats are recorded
191 // so inconsistencies will creep in if we try. For example, if the service
192 // is recording the number of poptop kills but not the total number of kills,
193 // we could end up with a situation like "2 total kills, 8 poptops killed."
194
195 // The best we can do is let the client be authoritative over its stats and
196 // have the service validate changes it receives to make sure they only
197 // ever increase.
198
199 m_service->flush();
200}
201
202LuaCallbacks Statistics::makeStatisticsCallbacks() {
203 LuaCallbacks callbacks;

Callers

nothing calls this directly

Calls 8

achievementsUnlockedMethod · 0.80
initializedMethod · 0.45
errorMethod · 0.45
differenceMethod · 0.45
unlockAchievementMethod · 0.45
addAllMethod · 0.45
setStatMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected