     return keys
 
 
-.factory 'games', ($http, $q, loggedUser, currentGame, gameConverter, gameHistory, gameTime) ->
+.factory 'games', ($http, $q, $location, loggedUser, currentGame, gameConverter, gameHistory, gameTime) ->
 
   saveInfo = ->
     $http.post('/games', currentGame.info)
       .then (savedGame) ->
         currentGame.info = savedGame.data
         currentGame.version.gameId = currentGame.info.id
+        $http.get("/users?id=#{currentGame.info.ownerId}")
+      .then (creator) ->
+        currentGame.creator = creator.data.username
 
   updateInfo = ->
     $http.put('/games', currentGame.info)

    propertyNames = @propertyNames
    $http.get("/assets/games/#{gameName}.json")
      .error((error) ->
          # TODO Where does this line go ? showMessage(MessageType.Error, "Cannot load game files")
          deferred.reject error
        )
      .success((game) ->

    $http.post('/game-versions', gameConverter.convertGameVersionToEmbeddedJson(currentGame.version))
      .then (savedGameVersion) -> currentGame.version = gameConverter.convertGameVersionFromEmbeddedJson(savedGameVersion.data)

  saveActions:
    none:
      name: 'No Action'
      execute: -> console.log 'games.saveActions.none executed'
    saveNewVersion:
      name: 'Save'
      execute: -> updateInfo().then(saveVersion)
    fork:
      name: 'Fork'
      execute: ->
        # Removing the game ID will make the server provide a new one
        delete currentGame.info.id
        saveInfo().then -> 
          $location.path("/game/#{currentGame.version.gameId}/edit")
          saveVersion()

  loadJson: (gameName) ->
    deferred = $q.defer()
