<commit_before>View = require 'views/base/view'
TILEDMap = require 'models/TILEDMap'
Player = require 'models/Player'
InputManager = require 'models/InputManager'
SoundManager = require 'models/SoundManager'
PhysicsManager = require 'models/PhysicsManager'
mediator = require 'mediator'
Std = require 'models/Std'
EntitySpawnManager = require 'models/EntitySpawnManager'
Level = require 'models/Level'


module.exports = class HomePageView extends View
  autoRender: yes
  className: 'home-page'
  container: '#page-container'

  initialize: (options) ->
    super
    new Std()
    @skipFrame = true

    # developement only, will be removed in release build
    mediator.PlayWithSounds = confirm("Load Sounds?")

    # the first level
    LEVEL = 'level1'
    mediator.levels[LEVEL] = new Level()

    @physicsManager = new PhysicsManager()
    @soundManager = new SoundManager() if mediator.PlayWithSounds
    @inputManager = new InputManager()

    @EntitySpawnManager = new EntitySpawnManager()

    @loadLevel(LEVEL)

    @subscribeEvent 'mapRendered:'+LEVEL, =>
      @publishEvent 'levelChangeTo:'+LEVEL

  loadLevel: (LEVEL) =>
    map = new TILEDMap("level":LEVEL)
    mediator.levels[LEVEL].gMap = map
    mediator.levels[LEVEL].gMap.load(LEVEL)

    if mediator.PlayWithSounds
      @soundManager.load(LEVEL)

    @subscribeEvent 'levelChangeTo:'+LEVEL, =>
      @setup(LEVEL)


  setup: (LEVEL) =>
    mediator.activeLevel = LEVEL
    @physicsManager.setup()
    @EntitySpawnManager.initialSpawn()
    if mediator.PlayWithSounds
      @subscribeEvent 'soundsLoaded:'+LEVEL, =>
        @soundManager.playSound(LEVEL+'theme',mediator.levels[LEVEL].soundList, 1, true)
        @soundManager.startBackgroundSounds()
        @soundManager.updateBackgroundSounds(mediator.player.position)

    window.requestAnimationFrame @doTheWork


  render: =>
    @canvas = document.createElement 'canvas'
    @ctx = @canvas.getContext '2d'
    @el.appendChild @canvas


  doTheWork: =>
    setTimeout =>
      window.requestAnimationFrame @doTheWork
      @handleInput()<commit_msg>Clear mediator.entities on lvl change<commit_after>View = require 'views/base/view'
TILEDMap = require 'models/TILEDMap'
Player = require 'models/Player'
InputManager = require 'models/InputManager'
SoundManager = require 'models/SoundManager'
PhysicsManager = require 'models/PhysicsManager'
mediator = require 'mediator'
Std = require 'models/Std'
EntitySpawnManager = require 'models/EntitySpawnManager'
Level = require 'models/Level'


module.exports = class HomePageView extends View
  autoRender: yes
  className: 'home-page'
  container: '#page-container'

  initialize: (options) ->
    super
    new Std()
    @skipFrame = true

    # developement only, will be removed in release build
    mediator.PlayWithSounds = confirm("Load Sounds?")

    # the first level
    LEVEL = 'level1'
    mediator.levels[LEVEL] = new Level()

    @physicsManager = new PhysicsManager()
    @soundManager = new SoundManager() if mediator.PlayWithSounds
    @inputManager = new InputManager()

    @EntitySpawnManager = new EntitySpawnManager()

    @loadLevel(LEVEL)

    @subscribeEvent 'mapRendered:'+LEVEL, =>
      @publishEvent 'levelChangeTo:'+LEVEL

  loadLevel: (LEVEL) =>
    map = new TILEDMap("level":LEVEL)
    mediator.levels[LEVEL].gMap = map
    mediator.levels[LEVEL].gMap.load(LEVEL)

    if mediator.PlayWithSounds
      @soundManager.load(LEVEL)

    @subscribeEvent 'levelChangeTo:'+LEVEL, =>
      @setup(LEVEL)


  setup: (LEVEL) =>
    mediator.activeLevel = LEVEL
    mediator.entities = []
    @physicsManager.setup()
    @EntitySpawnManager.initialSpawn()
    if mediator.PlayWithSounds
      @subscribeEvent 'soundsLoaded:'+LEVEL, =>
        @soundManager.playSound(LEVEL+'theme',mediator.levels[LEVEL].soundList, 1, true)
        @soundManager.startBackgroundSounds()
        @soundManager.updateBackgroundSounds(mediator.player.position)

    window.requestAnimationFrame @doTheWork


  render: =>
    @canvas = document.createElement 'canvas'
    @ctx = @canvas.getContext '2d'
    @el.appendChild @canvas


  doTheWork: =>
    setTimeout =>
      window.requestAnimationFrame @doTheWork
      @handleInput()
{'fraction_non_alphanumeric': 0.11142789261107151, 'fraction_numerical': 0.0014255167498218105, 'mean_word_length': 4.023866348448688, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 21, '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': '644033', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1239, 'n_words': 266}