Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
doom committed Oct 9, 2023
1 parent ba59cd4 commit 7af8d72
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
7 changes: 5 additions & 2 deletions code/controllers/subsystem/minimap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 27 additions & 2 deletions tgui/packages/tgui/interfaces/CanvasLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -136,6 +147,8 @@ export class CanvasLayer extends Component {
return;
}

const prevColor = line[0][4];

this.ctx.clearRect(
0,
0,
Expand All @@ -161,7 +174,8 @@ export class CanvasLayer extends Component {
});
});

this.setState({ selection: this.props.prevColor });
this.setState({ selection: prevColor });
this.props.onUndo(prevColor);
return;
}

Expand Down Expand Up @@ -208,6 +222,17 @@ export class CanvasLayer extends Component {
}

render() {
return <canvas ref={this.canvasRef} width={650} height={590} />;
// edge case where a new user joins and tries to draw on the canvas before they cached the png
return (
<div>
{this.state.mapLoad ? (
<canvas ref={this.canvasRef} width={650} height={590} />
) : (
<h2>
Please wait a few minutes before attempting to access the canvas
</h2>
)}
</div>
);
}
}
20 changes: 14 additions & 6 deletions tgui/packages/tgui/interfaces/TacticalMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ const colorOptions = [

const colors: Record<string, string> = {
'black': '#000000',
'red': '#FC0000',
'orange': '#F59A07',
'blue': '#0561F5',
'purple': '#C002FA',
'red': '#fc0000',
'orange': '#f59a07',
'blue': '#0561f5',
'purple': '#c002fa',
'green': '#02c245',
'brown': '#5C351E',
'brown': '#5c351e',
};

export const TacticalMap = (props, context) => {
Expand Down Expand Up @@ -175,6 +175,11 @@ const DrawMapPanel = (props, context) => {
return dataSelection;
}
};
const findColorValue = (oldValue: string) => {
return (Object.keys(colors) as Array<string>).find(
(key) => colors[key] === (oldValue as string)
);
};

return (
<>
Expand Down Expand Up @@ -237,6 +242,7 @@ const DrawMapPanel = (props, context) => {
selected={data.toolbarColorSelection}
color={data.toolbarColorSelection}
onSelected={(value) => act('selectColor', { color: value })}
displayText={data.toolbarColorSelection}
/>
</Stack.Item>
</Stack>
Expand Down Expand Up @@ -264,8 +270,10 @@ const DrawMapPanel = (props, context) => {
selection={handleColorSelection(data.toolbarUpdatedSelection)}
actionQueueChange={data.actionQueueChange}
imageSrc={data.newCanvasFlatImage}
prevColor={handleColorSelection(data.toolbarColorSelection)}
onImageExport={handleTacMapExport}
onUndo={(value) =>
act('selectColor', { color: findColorValue(value) })
}
/>
</Section>
</>
Expand Down

0 comments on commit 7af8d72

Please sign in to comment.