Skip to content

Commit

Permalink
ESLint the JS files.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsamuels committed Mar 28, 2016
1 parent 0891182 commit f392efa
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 136 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rocket_league/static/js/vendor/**/*.js
96 changes: 47 additions & 49 deletions rocket_league/static/js/2d-rendering/main.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
"use strict";

if (!Detector.webgl) Detector.addGetWebGLMessage();
var clock = new THREE.Clock();

var camera, controls, scene, renderer;

var animData;
var mesh;
var stats;
var bottomSpacing = 100;
/*global Detector, THREE, r, Stats, currentFrame:true, maxFrame, positionReplayObjects, addStadium*/
'use strict'

if (!Detector.webgl) {
Detector.addGetWebGLMessage()
}

function init() {
let camera
let scene
let renderer
let stats

scene = new THREE.Scene();
function init () {
scene = new THREE.Scene()

renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0xffffff);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize('1248', '702', false);
renderer.shadowMap.enabled = true;
renderer = new THREE.WebGLRenderer()
renderer.setClearColor(0xffffff)
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize('1248', '702', false)
renderer.shadowMap.enabled = true

var container = document.querySelector('.sim-Outer');
container.appendChild(renderer.domElement);
const container = document.querySelector('.sim-Outer')
container.appendChild(renderer.domElement)
renderer.domElement.style.width = '100%'

camera = new THREE.PerspectiveCamera(2 * Math.atan( 8240 / ( 2 * 5000 ) ) * ( 180 / Math.PI ), 1248 / 702, 1, 30000);
camera.position.set(0, 0, 5000);
camera = new THREE.PerspectiveCamera(2 * Math.atan(8240 / (2 * 5000)) * (180 / Math.PI), 1248 / 702, 1, 30000)
camera.position.set(0, 0, 5000)
camera.rotation.set(0, 0, r(90))

// Add stats module.
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild(stats.domElement);
stats = new Stats()
stats.domElement.style.position = 'absolute'
stats.domElement.style.bottom = '0px'
stats.domElement.style.zIndex = 100
container.appendChild(stats.domElement)

// Add lighting.
const light = new THREE.DirectionalLight(0xffffff);
light.castShadow = true;
light.shadow.camera.left = -5000;
light.shadow.camera.right = 5000;
light.shadow.camera.top = 5000;
light.shadow.camera.bottom = -5000;
light.position.set(0, 0, 5000);
scene.add(light);

document.querySelector('.sim-Timeline_Outer').addEventListener('mousemove', function(e) {
const light = new THREE.DirectionalLight(0xffffff)
light.castShadow = true
light.shadow.camera.left = -5000
light.shadow.camera.right = 5000
light.shadow.camera.top = 5000
light.shadow.camera.bottom = -5000
light.position.set(0, 0, 5000)
scene.add(light)

document.querySelector('.sim-Timeline_Outer').addEventListener('mousemove', function (e) {
if (document.querySelector('.sim-Timeline_Outer') !== e.target) {
return;
return
}

document.querySelector('.sim-Timeline_Cursor').style.left = `${e.offsetX}px`
})

document.querySelector('.sim-Timeline_Outer').addEventListener('mousedown', function(e) {
document.querySelector('.sim-Timeline_Outer').addEventListener('mousedown', function (e) {
if (document.querySelector('.sim-Timeline_Outer') !== e.target) {
return;
return
}

// Convert the current position into a frame.
Expand All @@ -69,12 +67,12 @@ function init() {
animate()
}

function animate() {
function animate () {
if (typeof scene === 'undefined') {
return
}

stats.update();
stats.update()

if (typeof currentFrame !== 'undefined' && currentFrame >= 0) {
positionReplayObjects()
Expand All @@ -86,16 +84,16 @@ function animate() {
}
}

render();
render()

let fpsLimit = 30 // Cap at 30 FPS.
let timeoutDelay = 1000 / fpsLimit
const fpsLimit = 30 // Cap at 30 FPS.
const timeoutDelay = 1000 / fpsLimit

setTimeout(function() {
requestAnimationFrame(animate);
setTimeout(() => {
requestAnimationFrame(animate)
}, timeoutDelay)
}

function render() {
renderer.render(scene, camera);
function render () {
renderer.render(scene, camera)
}
89 changes: 36 additions & 53 deletions rocket_league/static/js/2d-rendering/objects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*global THREE, textureLoader, scene, r, teamData, actorData, carsLoading:true*/
'use strict'

function renderRect(width, height) {
var rectShape = new THREE.Shape()
function renderRect (width, height) {
const rectShape = new THREE.Shape()
rectShape.moveTo(-(width / 2), -(height / 2))
rectShape.lineTo(width / 2, -(height / 2))
rectShape.lineTo(width / 2, height / 2)
Expand All @@ -12,19 +13,19 @@ function renderRect(width, height) {
}

// Load the stadium outline.
function addStadium() {
var materials = [
function addStadium () {
const materials = [
new THREE.MeshLambertMaterial({
map: textureLoader.load('/static/img/2d-rendering/arena_fieldlines.png'),
transparent: true,
opacity: 0.5,
color: 0xffffff,
color: 0xffffff
}),
new THREE.MeshLambertMaterial({
map: textureLoader.load('/static/img/2d-rendering/arena_overlay2.png'),
transparent: true,
opacity: 0.7,
color: 0xffffff,
color: 0xffffff
}),
new THREE.MeshLambertMaterial({
map: textureLoader.load('/static/img/2d-rendering/arena_boost.png'),
Expand All @@ -34,19 +35,19 @@ function addStadium() {
})
]

var mesh = new THREE.SceneUtils.createMultiMaterialObject(
const mesh = new THREE.SceneUtils.createMultiMaterialObject(
new THREE.PlaneGeometry(8240, 12000),
materials
);
)

mesh.name = 'stadium'
mesh.castShadow = false;
mesh.receiveShadow = false;
mesh.castShadow = false
mesh.receiveShadow = false

scene.add(mesh);
scene.add(mesh)
}

function addCar(name, actor) {
function addCar (name, actor) {
console.log(`[${name}] Adding car`)
let color = 0xff0000

Expand All @@ -59,36 +60,27 @@ function addCar(name, actor) {
const mesh = new THREE.Mesh(
renderRect(74, 144),
new THREE.MeshBasicMaterial({ color })
);
)

mesh.name = name
mesh.matrixAutoUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.matrixAutoUpdate = true
mesh.castShadow = true
mesh.receiveShadow = true

console.log(`[${name}] Adding to scene`)

// Fix the rotation point.
var box = new THREE.Box3().setFromObject(mesh);
box.center(mesh.position); // this re-sets the mesh position
mesh.position.multiplyScalar(-1);
const box = new THREE.Box3().setFromObject(mesh)
box.center(mesh.position) // this re-sets the mesh position
mesh.position.multiplyScalar(-1)

scene.add(mesh);
scene.add(mesh)

// Reposition the car based on the latest data.
console.log(`[${name}] Setting initial position`)

mesh.position.set(
actor.x * -1,
actor.y,
actor.z
)

mesh.rotation.set(
0,
0,
r(90) + actor.pitch * Math.PI * -1
)
mesh.position.set(actor.x * -1, actor.y, actor.z)
mesh.rotation.set(0, 0, r(90) + actor.pitch * Math.PI * -1)

// Add the boost gauge.
/*
Expand Down Expand Up @@ -119,49 +111,40 @@ function addCar(name, actor) {
document.querySelector(`.sim-Boost-team${team}`).appendChild(outerElement)

console.log(`[${name}] Render complete`)
carsLoading = carsLoading.filter(function(e){ return e !== name })
carsLoading = carsLoading.filter(function (e) { return e !== name })
}

function addBall(name, actor) {
function addBall (name, actor) {
console.log(`[${name}] Adding ball`)

const mesh = new THREE.Mesh(
new THREE.CircleGeometry(91, 32),
new THREE.MeshLambertMaterial({
map: textureLoader.load('/static/img/2d-rendering/ball.png')
})
);
)

mesh.name = name
mesh.matrixAutoUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.matrixAutoUpdate = true
mesh.castShadow = true
mesh.receiveShadow = true
mesh.renderOrder = 1

console.log(`[${name}] Adding to scene`)

// Fix the rotation point.
var box = new THREE.Box3().setFromObject(mesh);
box.center(mesh.position); // this re-sets the mesh position
mesh.position.multiplyScalar(-1);
const box = new THREE.Box3().setFromObject(mesh)
box.center(mesh.position) // this re-sets the mesh position
mesh.position.multiplyScalar(-1)

scene.add(mesh);
scene.add(mesh)

// Reposition the car based on the latest data.
console.log(`[${name}] Setting initial position`)

mesh.position.set(
actor.x * -1,
actor.y,
actor.z
)

mesh.rotation.set(
0,
0,
actor.yaw * Math.PI
)
mesh.position.set(actor.x * -1, actor.y, actor.z)
mesh.rotation.set(0, 0, actor.yaw * Math.PI)

console.log(`[${name}] Render complete`)
carsLoading = carsLoading.filter(function(e){ return e !== name })
carsLoading = carsLoading.filter(function (e) { return e !== name })
}
Loading

0 comments on commit f392efa

Please sign in to comment.