aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx')
-rw-r--r--src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
index cd1ff17dd..ae674d604 100644
--- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
+++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
@@ -6,8 +6,9 @@ import QuestionMarkIcon from '@mui/icons-material/QuestionMark';
import ReplayIcon from '@mui/icons-material/Replay';
import { Box, Button, Checkbox, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControl, FormControlLabel, FormGroup, IconButton, LinearProgress, Stack } from '@mui/material';
import Typography from '@mui/material/Typography';
-import { action, computed, IReactionDisposer, observable, reaction } from 'mobx';
+import { IReactionDisposer, action, computed, observable, reaction } from 'mobx';
import { observer } from 'mobx-react';
+import * as React from 'react';
import { NumListCast } from '../../../../fields/Doc';
import { List } from '../../../../fields/List';
import { BoolCast, NumCast, StrCast } from '../../../../fields/Types';
@@ -15,11 +16,10 @@ import { ViewBoxAnnotatableComponent } from '../../DocComponent';
import { FieldView, FieldViewProps } from './../FieldView';
import './PhysicsSimulationBox.scss';
import InputField from './PhysicsSimulationInputField';
-import * as questions from './PhysicsSimulationQuestions.json';
-import * as tutorials from './PhysicsSimulationTutorial.json';
+import questions from './PhysicsSimulationQuestions.json';
+import tutorials from './PhysicsSimulationTutorial.json';
import Wall from './PhysicsSimulationWall';
import Weight from './PhysicsSimulationWeight';
-import React = require('react');
interface IWallProps {
length: number;
@@ -81,14 +81,14 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<FieldViewP
// semi-Constants
xMin = 0;
yMin = 0;
- xMax = this.props.PanelWidth() * 0.6;
- yMax = this.props.PanelHeight();
+ xMax = this._props.PanelWidth() * 0.6;
+ yMax = this._props.PanelHeight();
color = `rgba(0,0,0,0.5)`;
radius = 50;
wallPositions: IWallProps[] = [];
@computed get circularMotionRadius() {
- return (NumCast(this.dataDoc.circularMotionRadius, 150) * this.props.PanelWidth()) / 1000;
+ return (NumCast(this.dataDoc.circularMotionRadius, 150) * this._props.PanelWidth()) / 1000;
}
@computed get gravity() {
return NumCast(this.dataDoc.simulation_gravity, -9.81);
@@ -191,21 +191,22 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<FieldViewP
componentDidMount() {
// Setup and update simulation
- this._widthDisposer = reaction(() => [this.props.PanelWidth(), this.props.PanelHeight()], this.setupSimulation, { fireImmediately: true });
+ this._widthDisposer = reaction(() => [this._props.PanelWidth(), this._props.PanelHeight()], this.setupSimulation, { fireImmediately: true });
// Create walls
this.wallPositions = [
{ length: 100, xPos: 0, yPos: 0, angleInDegrees: 0 },
{ length: 100, xPos: 0, yPos: 100, angleInDegrees: 0 },
{ length: 100, xPos: 0, yPos: 0, angleInDegrees: 90 },
- { length: 100, xPos: (this.xMax / this.props.PanelWidth()) * 100, yPos: 0, angleInDegrees: 90 },
+ { length: 100, xPos: (this.xMax / this._props.PanelWidth()) * 100, yPos: 0, angleInDegrees: 90 },
];
}
- componentDidUpdate() {
- if (this.xMax !== this.props.PanelWidth() * 0.6 || this.yMax != this.props.PanelHeight()) {
- this.xMax = this.props.PanelWidth() * 0.6;
- this.yMax = this.props.PanelHeight();
+ componentDidUpdate(prevProps: Readonly<FieldViewProps>) {
+ super.componentDidUpdate(prevProps);
+ if (this.xMax !== this._props.PanelWidth() * 0.6 || this.yMax != this._props.PanelHeight()) {
+ this.xMax = this._props.PanelWidth() * 0.6;
+ this.yMax = this._props.PanelHeight();
this.setupSimulation();
}
}
@@ -631,7 +632,7 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<FieldViewP
// Default setup for pendulum simulation
setupPendulum = () => {
- const length = (300 * this.props.PanelWidth()) / 1000;
+ const length = (300 * this._props.PanelWidth()) / 1000;
const angle = 30;
const x = length * Math.cos(((90 - angle) * Math.PI) / 180);
const y = length * Math.sin(((90 - angle) * Math.PI) / 180);
@@ -807,8 +808,8 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<FieldViewP
const commonWeightProps = {
pause: this.pause,
paused: BoolCast(this.dataDoc.simulation_paused),
- panelWidth: this.props.PanelWidth,
- panelHeight: this.props.PanelHeight,
+ panelWidth: this._props.PanelWidth,
+ panelHeight: this._props.PanelHeight,
resetRequest: this.resetRequest,
xMax: this.xMax,
xMin: this.xMin,
@@ -852,9 +853,9 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<FieldViewP
<div
style={{
position: 'fixed',
- left: 0.1 * this.props.PanelWidth() + 'px',
- top: 0.95 * this.props.PanelHeight() + 'px',
- width: 0.5 * this.props.PanelWidth() + 'px',
+ left: 0.1 * this._props.PanelWidth() + 'px',
+ top: 0.95 * this._props.PanelHeight() + 'px',
+ width: 0.5 * this._props.PanelWidth() + 'px',
}}>
<LinearProgress />
</div>
@@ -922,8 +923,8 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<FieldViewP
</div>
<div
className="mechanicsSimulationEquationContainer"
- onWheel={e => this.props.isContentActive() && e.stopPropagation()}
- style={{ overflow: 'auto', height: `${Math.max(1, 800 / this.props.PanelWidth()) * 100}%`, transform: `scale(${Math.min(1, this.props.PanelWidth() / 850)})` }}>
+ onWheel={e => this._props.isContentActive() && e.stopPropagation()}
+ style={{ overflow: 'auto', height: `${Math.max(1, 800 / this._props.PanelWidth()) * 100}%`, transform: `scale(${Math.min(1, this._props.PanelWidth() / 850)})` }}>
<div className="mechanicsSimulationControls">
<Stack direction="row" spacing={1}>
{this.dataDoc.simulation_paused && this.simulationMode != 'Tutorial' && (