#
# Used to load achievements from storage.
init from_json(game: Game, json: JsonObject) do
- init(game, json["id"].to_s, json["name"].to_s, json["desc"].to_s, json["reward"].as(Int))
+ init(game,
+ json["id"].as(String),
+ json["name"].as(String),
+ json["desc"].as(String),
+ json["reward"].as(Int))
end
redef fun to_json do
json["desc"] = desc
json["reward"] = reward
json["game"] = game.key
+ var owner = self.owner
if owner != null then json["owner"] = owner.key
return json
end
redef class GameEntity
+ # Register a new game event for this entity.
fun add_event(event: GameEvent) do
event.owner = self
event.save
#
# Used to load events from json storage.
init from_json(game: Game, json: JsonObject) do
- init(game, json["kind"].to_s, json["data"].as(JsonObject))
- internal_id = json["internal_id"].to_s
- time = new ISODate.from_string(json["time"].to_s)
+ init(game, json["kind"].as(String), json["data"].as(JsonObject))
+ internal_id = json["internal_id"].as(String)
+ time = new ISODate.from_string(json["time"].as(String))
end
redef fun to_json do
json["time"] = time.to_s
json["data"] = data
json["game"] = game.key
+ var owner = self.owner
if owner != null then json["owner"] = owner.key
return json
end
#
# Used to load players from saved data.
init from_json(game: Game, json: JsonObject) do
- init(game, json["name"].to_s)
+ init(game, json["name"].as(String))
nitcoins = json["nitcoins"].as(Int)
end