Skip to content

Commit

Permalink
WIP: ESLint first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
kpal81xd committed Aug 6, 2024
1 parent 426c4f1 commit 64c52f1
Show file tree
Hide file tree
Showing 481 changed files with 6,354 additions and 5,869 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"@babel/eslint-parser": "^7.24.1",
"@babel/preset-env": "^7.24.4",
"@playcanvas/canvas-mock": "^1.0.1",
"@playcanvas/eslint-config": "^1.7.1",
"@playcanvas/eslint-config": "^1.7.4",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-strip": "^3.0.4",
Expand Down
13 changes: 7 additions & 6 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import * as fs from 'node:fs';
import { version, revision } from './utils/rollup-version-revision.mjs';
import { buildTarget } from './utils/rollup-build-target.mjs';


// unofficial package plugins
import dts from 'rollup-plugin-dts';

// custom plugins
import { runTsc } from './utils/plugins/rollup-run-tsc.mjs';
import { typesFixup } from './utils/plugins/rollup-types-fixup.mjs';
import { buildTarget } from './utils/rollup-build-target.mjs';
import { version, revision } from './utils/rollup-version-revision.mjs';

/** @typedef {import('rollup').RollupOptions} RollupOptions */

const BLUE_OUT = '\x1b[34m';
const RED_OUT = '\x1b[31m';
const BOLD_OUT = `\x1b[1m`;
const REGULAR_OUT = `\x1b[22m`;
const RESET_OUT = `\x1b[0m`;
const BOLD_OUT = '\x1b[1m';
const REGULAR_OUT = '\x1b[22m';
const RESET_OUT = '\x1b[0m';

/**
* @type {['release', 'debug', 'profiler', 'min']}
Expand Down Expand Up @@ -53,7 +54,7 @@ const TYPES_TARGET = [{
const envTarget = process.env.target ? process.env.target.toLowerCase() : null;

const title = [
`Building PlayCanvas Engine`,
'Building PlayCanvas Engine',
`version ${BOLD_OUT}v${version}${REGULAR_OUT}`,
`revision ${BOLD_OUT}${revision}${REGULAR_OUT}`,
`target ${BOLD_OUT}${envTarget ?? 'all'}${REGULAR_OUT}`
Expand Down
72 changes: 36 additions & 36 deletions scripts/animation/tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,47 +271,47 @@ Tween.prototype.start = function (idx) {
updateProperty(startValue);

tweenInstances[idx] = new TWEEN.Tween(startValue)
.to(endValue, tween.duration)
.easing(easingFunc)
.onStart(function (obj) {
if (tween.startEvent !== '') {
app.fire(tween.startEvent);
}
})
.onStop(function (obj) {
if (tween.stopEvent !== '') {
app.fire(tween.stopEvent);
}
tweenInstances[idx] = null;
})
.onUpdate(function (obj) {
updateProperty(obj);
.to(endValue, tween.duration)
.easing(easingFunc)
.onStart((obj) => {
if (tween.startEvent !== '') {
app.fire(tween.startEvent);
}
})
.onStop((obj) => {
if (tween.stopEvent !== '') {
app.fire(tween.stopEvent);
}
tweenInstances[idx] = null;
})
.onUpdate((obj) => {
updateProperty(obj);

if (tween.updateEvent !== '') {
app.fire(tween.updateEvent);
}
})
.onComplete(function (obj) {
if (tween.completeEvent !== '') {
app.fire(tween.completeEvent);
}
tweenInstances[idx] = null;
})
.onRepeat(function (obj) {
if (tween.repeatEvent !== '') {
app.fire(tween.repeatEvent);
}
})
.repeat(tween.repeat === -1 ? Infinity : tween.repeat)
.repeatDelay(tween.repeatDelay)
.yoyo(tween.yoyo)
.delay(tween.delay)
.start();
if (tween.updateEvent !== '') {
app.fire(tween.updateEvent);
}
})
.onComplete((obj) => {
if (tween.completeEvent !== '') {
app.fire(tween.completeEvent);
}
tweenInstances[idx] = null;
})
.onRepeat((obj) => {
if (tween.repeatEvent !== '') {
app.fire(tween.repeatEvent);
}
})
.repeat(tween.repeat === -1 ? Infinity : tween.repeat)
.repeatDelay(tween.repeatDelay)
.yoyo(tween.yoyo)
.delay(tween.delay)
.start();
};

// We have to update the tween.js engine somewhere once a frame...
if (pc.Application.getApplication()) {
pc.Application.getApplication().on('update', function (dt) {
pc.Application.getApplication().on('update', (dt) => {
TWEEN.update();
});
}
4 changes: 2 additions & 2 deletions scripts/camera/first-person-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,15 @@

GamePadInputScript.attributes.add('deadZoneLow', {
title: 'Low Dead Zone',
description: "Radial thickness of inner dead zone of pad's joysticks. This dead zone ensures that all pads report a value of 0 for each joystick axis when untouched.",
description: 'Radial thickness of inner dead zone of pad\'s joysticks. This dead zone ensures that all pads report a value of 0 for each joystick axis when untouched.',
type: 'number',
min: 0,
max: 0.4,
default: 0.1
});
GamePadInputScript.attributes.add('deadZoneHigh', {
title: 'High Dead Zone',
description: "Radial thickness of outer dead zone of pad's joysticks. This dead zone ensures that all pads can reach the -1 and 1 limits of each joystick axis.",
description: 'Radial thickness of outer dead zone of pad\'s joysticks. This dead zone ensures that all pads can reach the -1 and 1 limits of each joystick axis.',
type: 'number',
min: 0,
max: 0.4,
Expand Down
10 changes: 6 additions & 4 deletions scripts/camera/fly-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ FlyCamera.attributes.add('mode', {
type: 'number',
default: 0,
enum: [{
"Lock": 0
'Lock': 0
}, {
"Drag": 1
'Drag': 1
}]
});

Expand Down Expand Up @@ -63,11 +63,13 @@ FlyCamera.prototype.update = function (dt) {

FlyCamera.prototype.onMouseMove = function (event) {
if (!this.mode) {
if (!pc.Mouse.isPointerLocked())
if (!pc.Mouse.isPointerLocked()) {
return;
}
} else {
if (!this.lmbDown)
if (!this.lmbDown) {
return;
}
}


Expand Down
18 changes: 9 additions & 9 deletions scripts/camera/orbit-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ OrbitCamera.attributes.add('frameOnStart', {

// Property to get and set the distance between the pivot point and camera
// Clamped between this.distanceMin and this.distanceMax
Object.defineProperty(OrbitCamera.prototype, "distance", {
Object.defineProperty(OrbitCamera.prototype, 'distance', {
get: function () {
return this._targetDistance;
},
Expand All @@ -43,7 +43,7 @@ Object.defineProperty(OrbitCamera.prototype, "distance", {

// Property to get and set the camera orthoHeight
// Clamped above 0
Object.defineProperty(OrbitCamera.prototype, "orthoHeight", {
Object.defineProperty(OrbitCamera.prototype, 'orthoHeight', {
get: function () {
return this.entity.camera.orthoHeight;
},
Expand All @@ -57,7 +57,7 @@ Object.defineProperty(OrbitCamera.prototype, "orthoHeight", {
// Property to get and set the pitch of the camera around the pivot point (degrees)
// Clamped between this.pitchAngleMin and this.pitchAngleMax
// When set at 0, the camera angle is flat, looking along the horizon
Object.defineProperty(OrbitCamera.prototype, "pitch", {
Object.defineProperty(OrbitCamera.prototype, 'pitch', {
get: function () {
return this._targetPitch;
},
Expand All @@ -69,7 +69,7 @@ Object.defineProperty(OrbitCamera.prototype, "pitch", {


// Property to get and set the yaw of the camera around the pivot point (degrees)
Object.defineProperty(OrbitCamera.prototype, "yaw", {
Object.defineProperty(OrbitCamera.prototype, 'yaw', {
get: function () {
return this._targetYaw;
},
Expand All @@ -94,7 +94,7 @@ Object.defineProperty(OrbitCamera.prototype, "yaw", {


// Property to get and set the world position of the pivot point that the camera orbits around
Object.defineProperty(OrbitCamera.prototype, "pivotPoint", {
Object.defineProperty(OrbitCamera.prototype, 'pivotPoint', {
get: function () {
return this._pivotPoint;
},
Expand Down Expand Up @@ -244,7 +244,7 @@ OrbitCamera.prototype.initialize = function () {
}
});

this.on('destroy', function () {
this.on('destroy', () => {
window.removeEventListener('resize', onWindowResize, false);
});
};
Expand Down Expand Up @@ -294,23 +294,23 @@ OrbitCamera.prototype._checkAspectRatio = function () {
OrbitCamera.prototype._buildAabb = function (entity) {
var i, m, meshInstances = [];

var renders = entity.findComponents("render");
var renders = entity.findComponents('render');
for (i = 0; i < renders.length; i++) {
var render = renders[i];
for (m = 0; m < render.meshInstances.length; m++) {
meshInstances.push(render.meshInstances[m]);
}
}

var models = entity.findComponents("model");
var models = entity.findComponents('model');
for (i = 0; i < models.length; i++) {
var model = models[i];
for (m = 0; m < model.meshInstances.length; m++) {
meshInstances.push(model.meshInstances[m]);
}
}

var gsplats = entity.findComponents("gsplat");
var gsplats = entity.findComponents('gsplat');
for (i = 0; i < gsplats.length; i++) {
var gsplat = gsplats[i];
var instance = gsplat.instance;
Expand Down
36 changes: 21 additions & 15 deletions scripts/parsers/obj-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Object.assign(ObjModelParser.prototype, {
indices: []
}
};
var group = "default"; // current group
var lines = input.split("\n");
var group = 'default'; // current group
var lines = input.split('\n');
var verts = [], normals = [], uvs = [];
var i;

Expand Down Expand Up @@ -71,10 +71,12 @@ Object.assign(ObjModelParser.prototype, {
for (p = 1; p < parts.length; p++) {
r = this._parseIndices(parts[p]);
parsed[group].verts.push(verts[r[0] * 3], verts[r[0] * 3 + 1], verts[r[0] * 3 + 2]); // expand uvs from indices
if (r[1] * 2 < uvs.length)
parsed[group].uvs.push(uvs[r[1] * 2], uvs[r[1] * 2 + 1]); // expand uvs from indices
if (r[2] * 3 < normals.length)
parsed[group].normals.push(normals[r[2] * 3], normals[r[2] * 3 + 1], normals[r[2] * 3 + 2]); // expand normals from indices
if (r[1] * 2 < uvs.length) {
parsed[group].uvs.push(uvs[r[1] * 2], uvs[r[1] * 2 + 1]);
} // expand uvs from indices
if (r[2] * 3 < normals.length) {
parsed[group].normals.push(normals[r[2] * 3], normals[r[2] * 3 + 1], normals[r[2] * 3 + 2]);
} // expand normals from indices
}

} else if (parts.length === 5) {
Expand All @@ -84,13 +86,15 @@ Object.assign(ObjModelParser.prototype, {
p = order[o];
r = this._parseIndices(parts[p]);
parsed[group].verts.push(verts[r[0] * 3], verts[r[0] * 3 + 1], verts[r[0] * 3 + 2]); // expand uvs from indices
if (r[1] * 2 < uvs.length)
parsed[group].uvs.push(uvs[r[1] * 2], uvs[r[1] * 2 + 1]); // expand uvs from indices
if (r[2] * 3 < normals.length)
parsed[group].normals.push(normals[r[2] * 3], normals[r[2] * 3 + 1], normals[r[2] * 3 + 2]); // expand normals from indices
if (r[1] * 2 < uvs.length) {
parsed[group].uvs.push(uvs[r[1] * 2], uvs[r[1] * 2 + 1]);
} // expand uvs from indices
if (r[2] * 3 < normals.length) {
parsed[group].normals.push(normals[r[2] * 3], normals[r[2] * 3 + 1], normals[r[2] * 3 + 2]);
} // expand normals from indices
}
} else {
console.error(pc.string.format("OBJ uses unsupported {0}-gons", parts.length - 1));
console.error(pc.string.format('OBJ uses unsupported {0}-gons', parts.length - 1));
}
}
}
Expand All @@ -103,15 +107,17 @@ Object.assign(ObjModelParser.prototype, {
var currentGroup = parsed[groupNames[i]];
if (!currentGroup.verts.length) continue;
if (currentGroup.verts.length > 65535) {
console.warn("Warning: mesh with more than 65535 vertices");
console.warn('Warning: mesh with more than 65535 vertices');
}

var geom = new pc.Geometry();
geom.positions = currentGroup.verts;
if (currentGroup.normals.length > 0)
if (currentGroup.normals.length > 0) {
geom.normals = currentGroup.normals;
if (currentGroup.uvs.length > 0)
}
if (currentGroup.uvs.length > 0) {
geom.uvs = currentGroup.uvs;
}

var mesh = pc.Mesh.fromGeometry(this._device, geom);

Expand All @@ -126,7 +132,7 @@ Object.assign(ObjModelParser.prototype, {

_parseIndices: function (str) {
var result = [];
var indices = str.split("/");
var indices = str.split('/');
for (var i = 0; i < 3; i++) {
if (indices[i]) {
result[i] = parseInt(indices[i], 10) - 1; // convert to 0-indexed
Expand Down
2 changes: 1 addition & 1 deletion scripts/physics/action-physics-reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ActionPhysicsReset.prototype.postInitialize = function () {
app.on(this.event, reset);
}

this.on('attr:event', function (value, prev) {
this.on('attr:event', (value, prev) => {
if (prev && prev.length > 0) {
app.off(prev, reset);
}
Expand Down
12 changes: 6 additions & 6 deletions scripts/physics/render-physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ RenderPhysics.attributes.add('castShadows', {
RenderPhysics.prototype.initialize = function () {
// Handle attribute change events
this.on('attr:castShadows', function (value, prev) {
this.debugRoot.children.forEach(function (child) {
this.debugRoot.children.forEach((child) => {
child.model.castShadows = value;
});
}, this);
this.on('attr:opacity', function (value, prev) {
this.debugRoot.children.forEach(function (child) {
child.model.meshInstances.forEach(function (meshInstance) {
this.debugRoot.children.forEach((child) => {
child.model.meshInstances.forEach((meshInstance) => {
var material = meshInstance.material;
material.opacity = value;
material.update();
Expand All @@ -50,7 +50,7 @@ RenderPhysics.prototype.initialize = function () {

this.on('disable', function () {
var collisionComponents = this.app.root.findComponents('collision');
collisionComponents.forEach(function (collision) {
collisionComponents.forEach((collision) => {
if (collision.hasOwnProperty('_debugShape')) {
delete collision._debugShape;
}
Expand All @@ -70,7 +70,7 @@ RenderPhysics.prototype.createModel = function (mesh, material) {

RenderPhysics.prototype.postUpdate = function (dt) {
// For any existing debug shapes, mark them as not updated (yet)
this.debugRoot.children.forEach(function (child) {
this.debugRoot.children.forEach((child) => {
child.updated = false;
});

Expand Down Expand Up @@ -217,7 +217,7 @@ RenderPhysics.prototype.postUpdate = function (dt) {

// If a debug shape was not updated this frame, the source collision component
// isn't around any more so we can delete it
this.debugRoot.children.forEach(function (child) {
this.debugRoot.children.forEach((child) => {
if (!child.updated) {
delete child._collision._debugShape;
delete child._collision;
Expand Down
Loading

0 comments on commit 64c52f1

Please sign in to comment.