import { Component } from 'inferno'; import { useBackend } from '../backend'; import { Box, Button, Icon, LabeledList, Section, Slider } from '../components'; import { Window } from '../layouts'; export const BombTester = (props, context) => { const { act, data } = useBackend(context); const { simulating, mode, tank1, tank1ref, tank2, tank2ref, canister, sim_canister_output } = data; return ( {(simulating && ) || (
{(tank1 && ( )) || ( )} {(tank2 && ( )) || ( )} act('canister_scan')} icon="search"> Scan }> {(canister && {canister}) || No tank connected.} {canister && ( act('set_can_pressure', { pressure: val })} /> )}
)}
); }; class BombTesterSimulation extends Component { constructor(props) { super(props); const BOUND_X = 340; const BOUND_Y = 205; const MOVEMENT_SPEED = 2; let startRight = Math.random() > 0.5; let startBottom = Math.random() > 0.5; this.state = { x: startRight ? BOUND_X : 0, y: startBottom ? BOUND_Y : 0, reverseX: false, reverseY: false, }; this.process = setInterval(() => { this.setState((prevState) => { const state = { ...prevState }; if (state.reverseX) { if (state.x - MOVEMENT_SPEED < -5) { state.reverseX = false; state.x += MOVEMENT_SPEED; } else { state.x -= MOVEMENT_SPEED; } } else { if (state.x + MOVEMENT_SPEED > BOUND_X) { state.reverseX = true; state.x -= MOVEMENT_SPEED; } else { state.x += MOVEMENT_SPEED; } } if (state.reverseY) { if (state.y - MOVEMENT_SPEED < -20) { state.reverseY = false; state.y += MOVEMENT_SPEED; } else { state.y -= MOVEMENT_SPEED; } } else { if (state.y + MOVEMENT_SPEED > BOUND_Y) { state.reverseY = true; state.y -= MOVEMENT_SPEED; } else { state.y += MOVEMENT_SPEED; } } return state; }); }, 1); } componentWillUnmount() { clearInterval(this.process); } render() { const { x, y } = this.state; const newStyle = { position: 'relative', 'left': x + 'px', 'top': y + 'px', }; return (
); } }