diff --git a/code/controllers/subsystem/minimap.dm b/code/controllers/subsystem/minimap.dm index 5d9f12d09fb8..045e121af74d 100644 --- a/code/controllers/subsystem/minimap.dm +++ b/code/controllers/subsystem/minimap.dm @@ -754,8 +754,11 @@ SUBSYSTEM_DEF(minimaps) . = TRUE if ("selectColor") - toolbar_color_selection = params["color"] - toolbar_updated_selection = toolbar_color_selection + + var/newColor = params["color"] + if(newColor) + toolbar_color_selection = newColor + toolbar_updated_selection = newColor action_queue_change += 1 . = TRUE diff --git a/tgui/packages/tgui/interfaces/CanvasLayer.js b/tgui/packages/tgui/interfaces/CanvasLayer.js index 939f93c9de14..2e9d1bffae88 100644 --- a/tgui/packages/tgui/interfaces/CanvasLayer.js +++ b/tgui/packages/tgui/interfaces/CanvasLayer.js @@ -10,6 +10,7 @@ export class CanvasLayer extends Component { // using this.state prevents unpredictable behavior this.state = { selection: this.props.selection, + mapLoad: true, }; // needs to be of type png of jpg @@ -37,6 +38,14 @@ export class CanvasLayer extends Component { this.img.src = this.imageSrc; + this.img.onload = () => { + this.setState({ mapLoad: true }); + }; + + this.img.onerror = () => { + this.setState({ mapLoad: false }); + }; + this.drawCanvas(); this.canvasRef.current.addEventListener('mousedown', this.handleMouseDown); @@ -45,6 +54,8 @@ export class CanvasLayer extends Component { } componentWillUnmount() { + // otherwise we get a runtime + if (!this.state.mapLoad) return; this.canvasRef.current.removeEventListener( 'mousedown', this.handleMouseDown @@ -136,6 +147,8 @@ export class CanvasLayer extends Component { return; } + const prevColor = line[0][4]; + this.ctx.clearRect( 0, 0, @@ -161,7 +174,8 @@ export class CanvasLayer extends Component { }); }); - this.setState({ selection: this.props.prevColor }); + this.setState({ selection: prevColor }); + this.props.onUndo(prevColor); return; } @@ -208,6 +222,17 @@ export class CanvasLayer extends Component { } render() { - return ; + // edge case where a new user joins and tries to draw on the canvas before they cached the png + return ( +