<commit_before>// File is written using JS Standard Style with the exception that indentation
// should be *tabs*. Set your preferred number of spaces in your editor, not the
// source file.
//
// https://github.com/JedWatson/happiness

// Prevent global leakage
(function() {
	// Expose Phaser to the local context
	// TODO: Convert this to a require statement once Phaser supports it - https://github.com/photonstorm/phaser/issues/1974
	let Phaser = window.Phaser
	let { List, Record, Stack } = require("immutable")
	let simplifySpline = require("simplify-js")
	let sampleSize = require("lodash/sampleSize")
	let sortBy = require("lodash/sortBy")
	let unionWith = require("lodash/unionWith")
	let identicalComparator = (a, b) => {
		a === b
	}

	let playerSessions = new List()
	let currentGhostSessions = new List()
	let currentSession

	let game
	let debugKey
	let springs
	let player
	let platforms
	let ghosts
	let ground
	let ledge
	let cursors
	let switchButton
	let map
	let tiles
	let layer
	let gameStartTime

	// Starting Coordinates
	let startPosition = [0, 20]

	// Player states
	const BALL = 'ball'
	const SPRING = 'spring'
	let playerState = BALL

	// Spring behavior
	const VERTICAL_SPRING_FORCE = 700
	const HORIZONTAL_SPRING_FORCE = 700

	// Player behavior
	const GROUND_MOVEMENT_FORCE = 40
	const AIR_MOVEMENT_FORCE = 10

	const MAXIMUM_PLAYER_VELOCITY = 6
	const MINIMUM_PLAYER_VELOCITY = -1 * MAXIMUM_PLAYER_VELOCITY

	window.onload = initializeGame

	function initializeGame() {
		if (window.innerWidth === 0 || window.innerHeight === 0) {
			return setTimeout(initializeGame, 16)
		}

		game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '', { preload, create, update })
	}

	function preload() {
		game.load.image('ground', 'assets/sprites/platform.png')
		game.load.image('ball', 'assets/sprites/orb-blue.png', 50, 50)
		game.load.image('ball2', 'assets/sprites/orb-red.png', 50, 50)
		game.load.image('line', 'assets/sprites/line.PNG', 200, 4)
		game.load.tilemap('map', 'assets/tilemaps/maps/ninja-tilemap.json', null, Phaser.Tilemap.TILED_JSON)
		game.load.image('kenney', 'assets/tilemaps/tiles/kenney.png')
		game.load.image('spring', 'assets/sprites/spring-4-small.png')
	}

	function create() {
		// Set up initial system environment
		game.physics.startSystem(Phaser.Physics.NINJA)
		game.stage.backgroundColor = 0x4488cc

		// Add tilemap and tilemap physics
		map = game.add.tilemap('map')
		map.addTilesetImage('kenney')
		layer = map.createLayer('Tile Layer 1')
		layer.resizeWorld()
		let slopeMap = { '32': 1, '77': 1, '95': 2, '36': 3, '137': 3, '140': 2 }
		tiles = game.physics.ninja.convertTilemap(map, layer, slopeMap)

		// Add player and initialize ninja physics on it
		player = game.add.sprite.apply(game.add, startPosition.concat('ball'))

		game.physics.ninja.enable(player)

		player.body.collideWorldBounds = true
		player.body.bounce = 0.2

		// Game camera follows player
		game.camera.follow(player)

		// Add cursors
		cursors = game.input.keyboard.createCursorKeys()
		debugKey = game.input.keyboard.addKey(Phaser.KeyCode.W)
		switchButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)

		// Add group for ground and standard ledges and config
		platforms = game.add.group()

		// Add springs group and capabilites
		springs = game.add.group()

		currentSession = new Stack()
		currentSession = currentSession.unshift({ t: 0, x: player.x, y: player.y, state: BALL })

		// Create the ghosted player objects
		ghosts = game.add.group()

		currentGhostSessions = playerSessions
		currentGhostSessions.forEach((p_session) => {
			let position = p_session.first()
			let ghost = ghosts.create(position.x, position.y, 'ball')
			ghost.anchor.x = 0.5
			ghost.anchor.y = 0.5
		})

		gameStartTime = Date.now()
	}

	function update() {
		let now = getElapsedTime()

		// Update the ghosted player objects' positions
		currentGhostSessions.forEach((p_session, p_index) => {
			let nextPosition
			let previousPosition
			let deltaTimeToNextState
			let deltaPercentage
			let ghostPosition
			let ghost

			ghost = ghosts.getChildAt(p_index)

			nextPosition = p_session.first()

			if (nextPosition === undefined) {
				currentGhostSessions = currentGhostSessions.splice(p_index, 1)
				return
			}

			p_session = p_session.shift()

			// Check if the position
			if (nextPosition.t === now) {
				applyState(ghost, nextPosition)

				currentGhostSessions.set(p_index, p_session)
				return
			}

			// Find the next and previous ghost states
			while (nextPosition !== undefined && nextPosition.t < now) {
				previousPosition = nextPosition
				nextPosition = p_session.first()
				p_session = p_session.shift()
			}

			// Handle the end of the Stack
			if (nextPosition === undefined) {
				applyState(ghost, previousPosition)

				currentGhostSessions = currentGhostSessions.splice(p_index, 1)
				return
			}

			// Handle a perfect match
			if (nextPosition.t === now) {
				applyState(ghost, nextPosition)<commit_msg>Fixed a bug that caused completed ghosts to alter their final position<commit_after>// File is written using JS Standard Style with the exception that indentation
// should be *tabs*. Set your preferred number of spaces in your editor, not the
// source file.
//
// https://github.com/JedWatson/happiness

// Prevent global leakage
(function() {
	// Expose Phaser to the local context
	// TODO: Convert this to a require statement once Phaser supports it - https://github.com/photonstorm/phaser/issues/1974
	let Phaser = window.Phaser
	let { List, Record, Stack } = require("immutable")
	let simplifySpline = require("simplify-js")
	let sampleSize = require("lodash/sampleSize")
	let sortBy = require("lodash/sortBy")
	let unionWith = require("lodash/unionWith")
	let identicalComparator = (a, b) => {
		a === b
	}

	let playerSessions = new List()
	let currentGhostSessions = new List()
	let currentSession

	let game
	let debugKey
	let springs
	let player
	let platforms
	let ghosts
	let ground
	let ledge
	let cursors
	let switchButton
	let map
	let tiles
	let layer
	let gameStartTime

	// Starting Coordinates
	let startPosition = [0, 20]

	// Player states
	const BALL = 'ball'
	const SPRING = 'spring'
	let playerState = BALL

	// Spring behavior
	const VERTICAL_SPRING_FORCE = 700
	const HORIZONTAL_SPRING_FORCE = 700

	// Player behavior
	const GROUND_MOVEMENT_FORCE = 40
	const AIR_MOVEMENT_FORCE = 10

	const MAXIMUM_PLAYER_VELOCITY = 6
	const MINIMUM_PLAYER_VELOCITY = -1 * MAXIMUM_PLAYER_VELOCITY

	window.onload = initializeGame

	function initializeGame() {
		if (window.innerWidth === 0 || window.innerHeight === 0) {
			return setTimeout(initializeGame, 16)
		}

		game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '', { preload, create, update })
	}

	function preload() {
		game.load.image('ground', 'assets/sprites/platform.png')
		game.load.image('ball', 'assets/sprites/orb-blue.png', 50, 50)
		game.load.image('ball2', 'assets/sprites/orb-red.png', 50, 50)
		game.load.image('line', 'assets/sprites/line.PNG', 200, 4)
		game.load.tilemap('map', 'assets/tilemaps/maps/ninja-tilemap.json', null, Phaser.Tilemap.TILED_JSON)
		game.load.image('kenney', 'assets/tilemaps/tiles/kenney.png')
		game.load.image('spring', 'assets/sprites/spring-4-small.png')
	}

	function create() {
		// Set up initial system environment
		game.physics.startSystem(Phaser.Physics.NINJA)
		game.stage.backgroundColor = 0x4488cc

		// Add tilemap and tilemap physics
		map = game.add.tilemap('map')
		map.addTilesetImage('kenney')
		layer = map.createLayer('Tile Layer 1')
		layer.resizeWorld()
		let slopeMap = { '32': 1, '77': 1, '95': 2, '36': 3, '137': 3, '140': 2 }
		tiles = game.physics.ninja.convertTilemap(map, layer, slopeMap)

		// Add player and initialize ninja physics on it
		player = game.add.sprite.apply(game.add, startPosition.concat('ball'))

		game.physics.ninja.enable(player)

		player.body.collideWorldBounds = true
		player.body.bounce = 0.2

		// Game camera follows player
		game.camera.follow(player)

		// Add cursors
		cursors = game.input.keyboard.createCursorKeys()
		debugKey = game.input.keyboard.addKey(Phaser.KeyCode.W)
		switchButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)

		// Add group for ground and standard ledges and config
		platforms = game.add.group()

		// Add springs group and capabilites
		springs = game.add.group()

		currentSession = new Stack()
		currentSession = currentSession.unshift({ t: 0, x: player.x, y: player.y, state: BALL })

		// Create the ghosted player objects
		ghosts = game.add.group()

		currentGhostSessions = playerSessions
		currentGhostSessions.forEach((p_session) => {
			let position = p_session.first()
			let ghost = ghosts.create(position.x, position.y, 'ball')
			ghost.anchor.x = 0.5
			ghost.anchor.y = 0.5
		})

		gameStartTime = Date.now()
	}

	function update() {
		let now = getElapsedTime()

		// Update the ghosted player objects' positions
		currentGhostSessions.forEach((p_session, p_index) => {
			let nextPosition
			let previousPosition
			let deltaTimeToNextState
			let deltaPercentage
			let ghostPosition
			let ghost

			ghost = ghosts.getChildAt(p_index)

			nextPosition = p_session.first()

			if (nextPosition === undefined) {
				return
			}

			p_session = p_session.shift()

			// Check if the position
			if (nextPosition.t === now) {
				applyState(ghost, nextPosition)

				currentGhostSessions.set(p_index, p_session)
				return
			}

			// Find the next and previous ghost states
			while (nextPosition !== undefined && nextPosition.t < now) {
				previousPosition = nextPosition
				nextPosition = p_session.first()
				p_session = p_session.shift()
			}

			// Handle the end of the Stack
			if (nextPosition === undefined) {
				applyState(ghost, previousPosition)

				return
			}

			// Handle a perfect match
			if (nextPosition.t === now) {
				applyState(ghost, nextPosition)
{'fraction_non_alphanumeric': 0.11581381321001306, 'fraction_numerical': 0.014275661003317583, 'mean_word_length': 3.768935762224353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 4, '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': '172187', 'n_tokens_mistral': 3743, 'n_tokens_neox': 3252, 'n_words': 838}