-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiFrameAFrameHandler.js
More file actions
41 lines (29 loc) · 1.1 KB
/
iFrameAFrameHandler.js
File metadata and controls
41 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
handler for receiving messages from the page (this is in the iframe aframe)
*/
window.onmessage = function (msg) {
// console.log(msg)
/**
*
* @type {PlayerPosUpdate}
*/
const message = JSON.parse(msg.data)
if (message.kind === 'playerPosUpdate') {
for (let i = 0; i < message.positions.length; i++) {
const positionUpdate = message.positions[i];
const token = document.querySelector('#player-token-' + i)
// console.log(token)
if (i === message.activePlayerIndex) {
const diceValueText = document.querySelector('#dice-value')
//undefined to not modify value?
diceValueText.object3D.position.set(positionUpdate.x + message.diceValueTextOffsetX, message.gameTokenSize, positionUpdate.y + message.diceValueTextOffsetY)
const textProp = diceValueText.getAttribute('text')
diceValueText.setAttribute('text', {
...textProp,
value: message.leftDiveValue + '/' + message.rolledDiceValue
})
}
token.object3D.position.set(positionUpdate.x, message.gameTokenSize / 2, positionUpdate.y)
}
}
}