import React from "react"; import { OverlayReturn, Store, StoreEvents } from "../../lib/store"; import { Storage } from "../../lib/storage"; import { Coordinates } from "../../lib/coordinates"; import { Palette } from "../../lib/palette"; import { Menu } from "./menu"; import { MovableWindow } from "./movableWindow"; import { Minimap } from "./minimap"; import { Overlay } from "./overlay"; import { debounce } from "lodash"; import styled from "styled-components"; import { MuralEx } from "../../interfaces"; import { PieCharts } from "./pixelCharts"; import { TC_LOGO } from "../../assets"; const Img = styled.img` width: 25px; margin-right: 5px; display: inline; pointer-events: none; touch-action: none; `; interface StoreSettings { opacity: number; collapsed: boolean; } interface Props { store: Store; storage: Storage; cords: Coordinates; palette: Palette; } interface State extends StoreSettings{ selected?: MuralEx; overlays: number[]; showCharts: boolean; phantomOverlay: number; overlayModify?: OverlayReturn; } export class Main extends React.Component { private readonly STORAGE_KEY = "__OPACITY_SETTINGS"; private destroyed = false; constructor(props: Props) { super(props); this.state = { showCharts: false, overlays: [], phantomOverlay: -1, opacity: 50, collapsed: false, }; } componentDidMount() { this.props.store.on(StoreEvents.Any, this.update); this.update(); this.props.storage.getItem(this.STORAGE_KEY).then(data => { if (data !== null && !this.destroyed) { this.setState(data); } }); } componentWillUnmount() { this.destroyed = true; this.actualSave({collapsed: this.state.collapsed, opacity: this.state.opacity}); } actualSave(settings: StoreSettings) { return this.props.storage.setItem(this.STORAGE_KEY, settings); } save = debounce((opacity: number) => { this.actualSave({collapsed: this.state.collapsed, opacity}); }, 1000); opacityChange = (opacity: number) => { this.setState({ opacity }); this.save(opacity); }; update = () => { this.setState({ selected: this.props.store.selected, overlays: this.props.store.overlays, overlayModify: this.props.store.overlayModify, }); }; renderMap() { if (this.state.selected) { return ; } return null; } title() { return TC-Logo Overlay ; } render() { return <> {this.state.showCharts ? : null} this.setState({showCharts: !this.state.showCharts})} onOpacityChange={this.opacityChange} cords={this.props.cords} store={this.props.store} storage={this.props.storage} palette={this.props.palette} opacity={this.state.opacity} collapsed={this.state.collapsed} onCollapsedChanged={collapsed => { this.setState({collapsed}); this.actualSave({opacity: this.state.opacity, collapsed}); }} /> {this.renderMap()} {this.state.overlays.map((o, i) => )} {this.props.store.murals[this.state.phantomOverlay] ? : null } {this.state.overlayModify ? { this.state.overlayModify!.cb(name, x, y, confirm); }} /> : null} ; } }