Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Update dependencies #303

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@discordjs/uws": "10.149.0",
"ammo.js": "kripken/ammo.js#ac08f42d3995cfa2b719aa8a9bb5b766c7f63404",
"better-sqlite3": "^6.0.1",
"better-sqlite3": "^7.4.3",
"body-parser": "^1.18.2",
"colors": "^1.2.1",
"compression": "^1.7.2",
Expand All @@ -44,16 +44,16 @@
"js-cookie": "^2.2.0",
"msgpack-lite": "^0.1.26",
"mustache-express": "^1.2.5",
"pako": "^1.0.10",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"pako": "^2.0.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"reconnecting-websocket": "^4.4.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"semver": "^7.1.0",
"stats-js": "^1.0.0",
"styled-components": "^5.1.0",
"three": "^0.123.0",
"three": "^0.132.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Three.js has breaking changes (which we get warnings about when building the client), causing the editor to break:
image

"uWebSockets.js": "uNetworking/uWebSockets.js#v17.3.0"
},
"optionalDependencies": {
Expand Down
18 changes: 15 additions & 3 deletions src/client/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ function inIframe() {
}
}

function getParsedUserDataCookie() {
try {
const cookie = Cookies.get("user_data");
if (cookie) {
return JSON.parse(cookie);
}
} catch (err) {
console.warn("Could not parse user_data cookie. Will assume it was empty...", err);
}
}

domReady.then(() => {
// String formatted timestamp
let timestamp = function() {
Expand All @@ -45,7 +56,7 @@ domReady.then(() => {
let chatMessageTemplate = document.getElementById("messageTemplate");

// Check for former authentication
cookieData = Cookies.getJSON("user_data");
cookieData = getParsedUserDataCookie();
checkAuthentication();

let lastMessageSent = Date.now();
Expand Down Expand Up @@ -181,7 +192,7 @@ function authenticationWindow() {
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event) {
if (event.data && event.data.success && event.origin === window.location.origin) {
cookieData = Cookies.getJSON("user_data");
cookieData = getParsedUserDataCookie();
authWindow.close();
checkAuthentication();

Expand Down Expand Up @@ -226,7 +237,8 @@ function checkAuthentication() {
expires: days,
path: "/",
domain: window.location.hostname,
secure: config.ssl
secure: config.ssl,
SameSite: "Strict"
});
cookieData = response.tokenBody;
}
Expand Down
5 changes: 3 additions & 2 deletions src/client/chat/discord-api-redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ domReady.then(() => {
let user_data = JSON.parse(response);

let days = (user_data.expires_in / 62400) - 0.1; // seconds to days minus some slack
Cookies.set("user_data", user_data, {
Cookies.set("user_data", response, {
expires: days,
path: "/",
domain: window.location.hostname,
secure: config.ssl
secure: config.ssl,
sameSite: "strict"
});

window.opener.postMessage({
Expand Down
5 changes: 5 additions & 0 deletions src/client/editor/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export function setEditorLogElement(el) {
}

export function editorLog(message, type = "info") {
if (console[type]) {
console[type](message);
} else {
console.info(message);
}
element.insertAdjacentHTML(
"beforeend",
`<div class='${type}'>[${currentTimeString()}] ${message}</div>`
Expand Down
49 changes: 16 additions & 33 deletions src/client/editor/models.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
Vector3,
Matrix4,
Geometry,
BufferGeometry,
Group
} from "three";
import * as BufferGeometryUtils from "three/examples/jsm/utils/BufferGeometryUtils.js";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader.js";
import { ConvexGeometry } from "three/examples/jsm/geometries/ConvexGeometry";
Expand Down Expand Up @@ -160,13 +159,10 @@ Model.prototype.getConvexHull = function() {
let vertexArray = _getVertices(this.sceneObject);
this.convexHull = new ConvexGeometry(vertexArray); // Could throw an error if input is not valid
if(this.convexHull) {
this.projectData.convexData = [];
for(let i = 0; i < this.convexHull.vertices.length; i++) {
this.projectData.convexData.push(this.convexHull.vertices[i].x);
this.projectData.convexData.push(this.convexHull.vertices[i].y);
this.projectData.convexData.push(this.convexHull.vertices[i].z);
}
this.convexHull = new BufferGeometry().fromGeometry(this.convexHull);
// Clone the data
this.projectData.convexData = Float32Array.from(
this.convexHull.attributes.position.array
);
} else {
this.convexHull = false;
}
Expand All @@ -178,27 +174,25 @@ Model.prototype.getConvexHull = function() {
return this.convexHull;
};

// Recursive function: Returns one Geometry object of all combined geometries within the passed object
// Recursive function: Returns one BufferGeometry object of all combined geometries within the passed object
function _combineGeometry(obj) {
let geo = new Geometry();
let geo;

// obj.matrix isn't guaranteed to be up-to-date
let matrix = new Matrix4().identity();
matrix = matrix.compose(obj.position, obj.quaternion, obj.scale);

if(obj.type === "Mesh") {
let objGeo = obj.geometry;
// BufferGeometry needs to be converted before merging
if(objGeo.type === "BufferGeometry") {
objGeo = new Geometry().fromBufferGeometry(objGeo);
}
objGeo.mergeVertices(); // Never hurts, right?
geo.merge(objGeo, matrix);
geo = BufferGeometryUtils.mergeVertices(obj.geometry).applyMatrix4(matrix);
}

for(let c = 0; c < obj.children.length; c++) {
let childGeo = _combineGeometry(obj.children[c]);
geo.merge(childGeo, matrix);
const childGeo = _combineGeometry(obj.children[c]);
if (geo) {
geo.merge(childGeo);
} else {
geo = childGeo;
}
}

return geo;
Expand All @@ -211,20 +205,9 @@ Model.prototype.getConcaveGeometry = function() {
this.concaveGeo = _combineGeometry(this.sceneObject);
if(this.concaveGeo) {
this.projectData.concaveData = {
vertices: [],
indices: []
vertices: Float32Array.from(this.concaveGeo.attributes.position.array),
indices: Float32Array.from(this.concaveGeo.index.array)
};
for(let i = 0; i < this.concaveGeo.vertices.length; i++) {
this.projectData.concaveData.vertices.push(this.concaveGeo.vertices[i].x);
this.projectData.concaveData.vertices.push(this.concaveGeo.vertices[i].y);
this.projectData.concaveData.vertices.push(this.concaveGeo.vertices[i].z);
}
for(let i = 0; i < this.concaveGeo.faces.length; i++) {
this.projectData.concaveData.indices.push(this.concaveGeo.faces[i].a);
this.projectData.concaveData.indices.push(this.concaveGeo.faces[i].b);
this.projectData.concaveData.indices.push(this.concaveGeo.faces[i].c);
}
this.concaveGeo = new BufferGeometry().fromGeometry(this.concaveGeo);
} else {
this.concaveGeo = false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/client/editor/prefabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Group,
Vector3,
Mesh,
Geometry,
BufferGeometry,
BoxBufferGeometry,
SphereBufferGeometry,
CylinderBufferGeometry,
Expand Down Expand Up @@ -473,7 +473,7 @@ PrefabCollider.prototype.setShape = function(shapeType) {
model: null,
convex: true
};
this.sceneObject.geometry = new Geometry();
this.sceneObject.geometry = new BufferGeometry();
break;
default:
console.error(`Attempted to set unknown collider shape type ${shapeType}`);
Expand Down Expand Up @@ -524,7 +524,7 @@ PrefabCollider.prototype.setModel = function(modelName) {
// Remove from references
if(this.colliderData.model) {
delete modelsTab.models[this.colliderData.model].prefabEntities[this.uuid];
this.sceneObject.geometry = new Geometry();
this.sceneObject.geometry = new BufferGeometry();
this.colliderData.model = null;
this.colliderData.convex = true;
}
Expand Down Expand Up @@ -561,7 +561,7 @@ PrefabCollider.prototype.setConvex = function(isConvex) {
editorLog(`Failed to switch collider to ${isConvex ? "convex" : "concave"}.`, "error");
// Reset collider data so it stays valid
delete modelsTab.models[this.colliderData.model].prefabEntities[this.uuid];
this.sceneObject.geometry = new Geometry();
this.sceneObject.geometry = new BufferGeometry();
this.colliderData.model = null;
this.colliderData.convex = true;
}
Expand Down
20 changes: 15 additions & 5 deletions src/client/user-state.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import * as Cookies from "js-cookie";
import Cookies from "js-cookie";

function getParsedUserDataCookie() {
try {
const cookie = Cookies.get("user_data");
if (cookie) {
return JSON.parse(cookie);
}
} catch (err) {
console.warn("Could not parse user_data cookie. Will assume it was empty...", err);
}
}

window.addEventListener("message", function(event) {
// Don't parse anything that isn't ours
if (event.origin !== window.location.origin) return;

// If the authorization state has changed, update the user data
if (event.data === userState.AUTH_CHANGED) {
userState.data = Cookies.getJSON("user_data");
userState.data = getParsedUserDataCookie();
}
}, false);

let userState = {
const userState = {
AUTH_CHANGED: 0,

data: Cookies.getJSON("user_data")
data: getParsedUserDataCookie()
};

export { userState };
Loading