#ifndef STAR_STATISTICS_HPP #define STAR_STATISTICS_HPP #include "StarVersioningDatabase.hpp" #include "StarStatisticsDatabase.hpp" #include "StarLuaComponents.hpp" #include "StarStatisticsService.hpp" namespace Star { STAR_CLASS(Statistics); class Statistics { public: Statistics(String const& storageDirectory, StatisticsServicePtr service = {}); void writeStatistics(); Json stat(String const& name, Json def = {}) const; Maybe statType(String const& name) const; bool achievementUnlocked(String const& name) const; void recordEvent(String const& name, Json const& fields); bool reset(); void update(); private: struct Stat { static Stat fromJson(Json const& json); Json toJson() const; String type; Json value; }; void processEvent(String const& name, Json const& fields); // setStat and unlockAchievement must be kept private as some platforms' // services don't implement the API calls these correspond to. void setStat(String const& name, String const& type, Json const& value); void unlockAchievement(String const& name); bool checkAchievement(String const& achievementName); void readStatistics(); void mergeServiceStatistics(); LuaCallbacks makeStatisticsCallbacks(); template Maybe runStatScript(StringList const& scripts, Json const& config, String const& functionName, V&&... args); StatisticsServicePtr m_service; String m_storageDirectory; bool m_initialized; List> m_pendingEvents; StringSet m_pendingAchievementChecks; StringMap m_stats; StringSet m_achievements; LuaRootPtr m_luaRoot; }; } #endif