replay-viewer
Version:
Rocket League replay viewer React component and tooling
114 lines • 5.56 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import CircularProgress from "@mui/material/CircularProgress";
import Typography from "@mui/material/Typography";
import React, { Component } from "react";
import styled from "styled-components";
import { LoadingManager } from "three/src/loaders/LoadingManager";
import { GameManager } from "../../managers/GameManager";
import ErrorIcon from "./icons/ErrorIcon";
var GameManagerLoader = /** @class */ (function (_super) {
__extends(GameManagerLoader, _super);
function GameManagerLoader(props) {
var _this = _super.call(this, props) || this;
_this.handleProgress = function (_, loaded, total) {
var newPercent = Math.round((loaded / total) * 1000) / 10;
var percentLoaded = _this.state.percentLoaded;
var stateValue = newPercent > percentLoaded ? newPercent : percentLoaded;
_this.setState({
percentLoaded: stateValue,
});
};
_this.handleError = function (message) {
_this.setState({
error: "An error occurred while loading: ".concat(message),
});
};
_this.state = {
percentLoaded: 0,
loadingManager: props.options.loadingManager || new LoadingManager(),
};
_this.state.loadingManager.onProgress = _this.handleProgress;
if (!_this.state.loadingManager.onError) {
_this.state.loadingManager.onError = _this.handleError;
}
return _this;
}
GameManagerLoader.prototype.componentDidMount = function () {
var _this = this;
GameManager.builder(__assign(__assign({}, this.props.options), { loadingManager: this.state.loadingManager })).then(function (gameManager) {
_this.props.onLoad(gameManager);
_this.setState({
gameManager: gameManager,
});
});
};
GameManagerLoader.prototype.componentWillUnmount = function () {
GameManager.destruct();
};
GameManagerLoader.prototype.render = function () {
var children = this.props.children;
var gameManager = this.state.gameManager;
if (!gameManager) {
return (React.createElement(LoadingContainer, null,
React.createElement(CircularProgressContainer, null, this.renderIcon()),
React.createElement(Type, { variant: "caption" }, this.getHintText())));
}
return children;
};
GameManagerLoader.prototype.renderIcon = function () {
var _a = this.state, error = _a.error, percentLoaded = _a.percentLoaded;
if (error) {
return React.createElement(ErrorIcon, null);
}
var variant = percentLoaded === 100 ? "indeterminate" : "determinate";
return React.createElement(CircularProgress, { variant: variant, value: percentLoaded });
};
GameManagerLoader.prototype.getHintText = function () {
var _a = this.state, percentLoaded = _a.percentLoaded, error = _a.error;
if (error) {
return error;
}
else if (percentLoaded === 100) {
return "Building scene...";
}
else {
return "Importing assets: ".concat(percentLoaded, "%");
}
};
return GameManagerLoader;
}(Component));
var LoadingContainer = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n position: relative;\n text-align: center;\n"], ["\n width: 100%;\n position: relative;\n text-align: center;\n"])));
var CircularProgressContainer = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n width: 100%;\n height: 40px;\n display: flex;\n align-items: center;\n justify-content: center;\n"], ["\n width: 100%;\n height: 40px;\n display: flex;\n align-items: center;\n justify-content: center;\n"])));
var Type = styled(Typography)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: 100%;\n padding-top: 16px;\n"], ["\n width: 100%;\n padding-top: 16px;\n"])));
export default GameManagerLoader;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=GameManagerLoader.js.map