<commit_before>###*
The <code>SaveState</code> module provides methods to save and restore the current engine state.

@name SaveState
@fieldOf Engine
@module

@param {Object} I Instance variables
@param {Object} self Reference to the engine
###
Engine.SaveState = (I, self) ->
  savedState = null

  #TODO      
  rewind: ->

  ###*
  Save the current game state and returns a JSON object representing that state.

  <code><pre>
  engine.bind 'step', ->
    if justPressed.s
      engine.saveState()
  </pre></code>

  @name saveState
  @methodOf Engine#
  @returns {Array} An array of the instance data of all objects in the game
  ###
  saveState: ->
    savedState = I.objects.map (object) ->
      Object.extend({}, object.I)

  ###*
  Loads the game state passed in, or the last saved state, if any.

  <code><pre>
  engine.bind 'step', ->
    if justPressed.l
      # loads the last saved state
      engine.loadState()

    if justPressed.o
      # removes all game objects, then reinstantiates 
      # them with the entityData passed in
      engine.loadState([{x: 40, y: 50, class: "Player"}, {x: 0, y: 0, class: "Enemy"}, {x: 500, y: 400, class: "Boss"}])
  </pre></code>

  @name loadState
  @methodOf Engine.SaveState#
  @param [newState] The game state to load.
  ###
  loadState: (newState) ->
    if newState ||= savedState
      I.objects.invoke "trigger", "remove"
      I.objects = []

      newState.each (objectData) ->
        self.add Object.extend({}, objectData)

  ###*
  Reloads the current engine state, useful for hotswapping code.

  <code><pre>
  engine.I.objects.each (object) ->
    # bring all objects to (0, 0) for some reason
    object.I.x = 0
    object.I.y = 0

  # reload all objects to make sure
  # they are at (0, 0)  
  engine.reload()
  </pre></code>

  @name reload
  @methodOf Engine.SaveState#
  ###
  reload: ->
    oldObjects = I.objects
    I.objects = []
<commit_msg>engine_selector<commit_after>###*
The <code>SaveState</code> module provides methods to save and restore the current engine state.

@name SaveState
@fieldOf Engine
@module

@param {Object} I Instance variables
@param {Object} self Reference to the engine
###
Engine.SaveState = (I, self) ->
  savedState = null

  #TODO      
  rewind: ->

  ###*
  Save the current game state and returns a JSON object representing that state.

  <code><pre>
  engine.bind 'step', ->
    if justPressed.s
      engine.saveState()
  </pre></code>

  @name saveState
  @methodOf Engine#
  @returns {Array} An array of the instance data of all objects in the game
  ###
  saveState: ->
    savedState = I.objects.map (object) ->
      Object.extend({}, object.I)

  ###*
  Loads the game state passed in, or the last saved state, if any.

  <code><pre>
  engine.bind 'step', ->
    if justPressed.l
      # loads the last saved state
      engine.loadState()

    if justPressed.o
      # removes all game objects, then reinstantiates 
      # them with the entityData passed in
      engine.loadState([{x: 40, y: 50, class: "Player"}, {x: 0, y: 0, class: "Enemy"}, {x: 500, y: 400, class: "Boss"}])
  </pre></code>

  @name loadState
  @methodOf Engine#
  @param [newState] The game state to load.
  ###
  loadState: (newState) ->
    if newState ||= savedState
      I.objects.invoke "trigger", "remove"
      I.objects = []

      newState.each (objectData) ->
        self.add Object.extend({}, objectData)

  ###*
  Reloads the current engine state, useful for hotswapping code.

  <code><pre>
  engine.I.objects.each (object) ->
    # bring all objects to (0, 0) for some reason
    object.I.x = 0
    object.I.y = 0

  # reload all objects to make sure
  # they are at (0, 0)  
  engine.reload()
  </pre></code>

  @name reload
  @methodOf Engine#
  ###
  reload: ->
    oldObjects = I.objects
    I.objects = []

{'fraction_non_alphanumeric': 0.1319371727748691, 'fraction_numerical': 0.009424083769633508, 'mean_word_length': 2.832497492477432, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '638877', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1234, 'n_words': 420}