Skip to content

Commit c2f9ef4

Browse files
committed
Trying to fix fog of war bug that reveals the full map
1 parent 8bd6a84 commit c2f9ef4

File tree

4 files changed

+47
-28
lines changed

4 files changed

+47
-28
lines changed

client/src/pages/tabletop-page/tabletop-component/table-canvas/table-canvas.ts

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,30 @@ export default class TableCanvas extends SuperComponent<ITableCanvas>{
133133
for (let i = 0; i < this.fogOfWarShapes.length; i++) {
134134
switch (this.fogOfWarShapes[i].type){
135135
case "poly":
136-
this.fogctx.beginPath();
137-
this.fogctx.moveTo(this.fogOfWarShapes[i].points[0].x, this.fogOfWarShapes[i].points[0].y);
138-
for (let p = 1; p < this.fogOfWarShapes[i].points.length; p++){
139-
this.fogctx.lineTo(this.fogOfWarShapes[i].points[p].x, this.fogOfWarShapes[i].points[p].y);
136+
try {
137+
this.fogctx.beginPath();
138+
this.fogctx.moveTo(this.fogOfWarShapes[i].points[0].x, this.fogOfWarShapes[i].points[0].y);
139+
for (let p = 1; p < this.fogOfWarShapes[i].points.length; p++){
140+
this.fogctx.lineTo(this.fogOfWarShapes[i].points[p].x, this.fogOfWarShapes[i].points[p].y);
141+
}
142+
this.fogctx.closePath();
143+
this.fogctx.fill();
144+
} catch (e) {
145+
console.error("Render error:", e);
140146
}
141-
this.fogctx.closePath();
142-
this.fogctx.fill();
143147
break;
144148
case "rect":
145-
const width = this.fogOfWarShapes[i].points[1].x - this.fogOfWarShapes[i].points[0].x;
146-
const height = this.fogOfWarShapes[i].points[1].y - this.fogOfWarShapes[i].points[0].y
147-
this.fogctx.rect(this.fogOfWarShapes[i].points[0].x, this.fogOfWarShapes[i].points[0].y, width, height);
148-
this.fogctx.fill();
149+
try {
150+
const width = this.fogOfWarShapes[i].points[1].x - this.fogOfWarShapes[i].points[0].x;
151+
const height = this.fogOfWarShapes[i].points[1].y - this.fogOfWarShapes[i].points[0].y
152+
this.fogctx.rect(this.fogOfWarShapes[i].points[0].x, this.fogOfWarShapes[i].points[0].y, width, height);
153+
this.fogctx.fill();
154+
} catch (e) {
155+
console.error("Render error:", e);
156+
}
157+
break;
158+
default:
159+
console.error("How did you get here?");
149160
break;
150161
}
151162
}
@@ -244,28 +255,32 @@ export default class TableCanvas extends SuperComponent<ITableCanvas>{
244255

245256
if (!this.image) return;
246257

247-
// Always draw map first
248-
this.imgctx.drawImage(
249-
this.image,
250-
0, 0, this.w, this.h
251-
);
252-
253258
// Other
254259
this.renderGridLines();
255260
this.renderFogOfWar();
256-
261+
262+
// Always draw map first
257263
this.imgctx.drawImage(
258-
this.gridCanvas,
259-
0, 0,
260-
this.w, this.h
264+
this.image,
265+
0, 0, this.w, this.h
261266
);
267+
268+
if (this.renderGridLines) {
269+
this.imgctx.drawImage(
270+
this.gridCanvas,
271+
0, 0,
272+
this.w, this.h
273+
);
274+
}
262275

263276
// Always draw fog last
264-
this.imgctx.drawImage(
265-
this.fogCanvas,
266-
0, 0,
267-
this.w, this.h
268-
);
277+
if (this.renderFogOfWar) {
278+
this.imgctx.drawImage(
279+
this.fogCanvas,
280+
0, 0,
281+
this.w, this.h
282+
);
283+
}
269284
}
270285
}
271286
env.bind("table-canvas", TableCanvas);

server/views/layouts/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
66

7-
<title>Tabletopper v0.6.1</title>
7+
<title>Tabletopper v0.6.2</title>
88
<meta name="description" content="Jump into a D&D tabletop session with your friends, hassle free.">
99

1010
<link rel="icon" href="/static/favicon.png" sizes="any">

server/views/layouts/vtt.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
66

7-
<title>Tabletopper v0.6.1</title>
7+
<title>Tabletopper v0.6.2</title>
88
<meta name="description" content="Jump into a D&D tabletop session with your friends, hassle free.">
99

1010
<link rel="icon" href="/static/favicon.png" sizes="any">

wss/src/room.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class Room {
6666
}
6767

6868
public syncFog(shape):void{
69+
if (shape.points.length < 2) {
70+
console.log("Got malformed fog of war shape:", shape);
71+
return;
72+
}
6973
this.fogOfWarShapes.push(shape);
7074
this.broadcast("room:tabletop:fog:sync", {
7175
fogOfWarShapes: this.fogOfWarShapes,
@@ -105,7 +109,7 @@ class Room {
105109

106110
private decrementConditions() {
107111
let prev;
108-
if (this.activeInitiative - 1 < 0) {
112+
if (this.activeInitiative - < 0) {
109113
prev = this.initiative[this.initiative.length - 1];
110114
} else {
111115
prev = this.initiative[this.activeInitiative - 1];

0 commit comments

Comments
 (0)