redef class GameEntity
+ # Statistics for this entity.
+ fun stats: GameStats is abstract
+
# Load statistics for this `MEntity` if any.
fun load_statistics: nullable GameStats do
var key = self.key / "statistics"
var json = game.store.load_object(key)
return new GameStats.from_json(game, json)
end
-
- # Save statistics under this `MEntity`.
- fun save_statistics(stats: GameStats) do
- game.store.store_object(key / stats.key, stats.to_json)
- end
end
redef class Game
- # Statistics for this game instance.
- var stats: GameStats is lazy do
+ redef var stats is lazy do
return load_statistics or else new GameStats(game)
end
redef fun save do
super
- save_statistics(stats)
+ stats.save_in(self)
end
redef fun pretty do
redef class Player
- # Statistics for this player.
- var stats: GameStats is lazy do
+ redef var stats is lazy do
return load_statistics or else new GameStats(game)
end
redef fun save do
super
- save_statistics(stats)
+ stats.save_in(self)
end
redef fun pretty do
class StatisticsReactor
super GameReactor
- redef fun react_event(game, e) do
- super # log events
- e.react_stats_event(game)
- end
+ redef fun react_event(game, e) do e.react_stats_event(game)
end
redef class GithubEvent