Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change to characterhups for remote players #3704

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions character-hups.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ class CharacterHups extends EventTarget {
super();

this.player = player;
console.log(`character hups created`, player)

this.hups = [];

player.addEventListener('actionadd', e => {
const {action} = e;
const {type, actionId} = action;
// console.log('action add', action);
console.log('action add', action, player);

const oldHup = this.hups.find(hup => hup.type === type);
// console.log('got old hup', oldHup, actionId, this.hups.map(h => h.actionIds).flat());
Expand All @@ -117,17 +118,20 @@ class CharacterHups extends EventTarget {
let pendingVoices = 0;
newHup.addEventListener('voicequeue', () => {
pendingVoices++;
console.log(`voicequeue`, newHup)
newHup.clearDeadTimeout();
});
newHup.addEventListener('voiceend', () => {
if (--pendingVoices === 0) {
console.log(`voiceend`, newHup)
newHup.startDeadTimeout();
}
});
newHup.addEventListener('deadtimeout', () => {
newHup.destroy();
//newHup.destroy();

const index = this.hups.indexOf(newHup);
console.log(`A hups removed`, newHup, player)
this.hups.splice(index, 1);

this.dispatchEvent(new MessageEvent('hupremove', {
Expand All @@ -138,6 +142,8 @@ class CharacterHups extends EventTarget {
}));
});
this.hups.push(newHup);
console.log(`A hups added`, newHup, player)
console.log(`All hups`, this.hups, player)
this.dispatchEvent(new MessageEvent('hupadd', {
data: {
player,
Expand All @@ -150,7 +156,7 @@ class CharacterHups extends EventTarget {
player.addEventListener('actionremove', e => {
const {action} = e;
const {actionId} = action;
// console.log('action remove', action);
console.log('action remove', action, player);

const oldHup = this.hups.find(hup => hup.actionIds.includes(actionId));
if (oldHup) {
Expand Down
4 changes: 4 additions & 0 deletions diorama.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ const createPlayerDiorama = ({

const _render = () => {
if (autoCamera) {
// update character portrait position
target.updateMatrixWorld()
// set up side camera
target.matrixWorld.decompose(localVector, localQuaternion, localVector2);
const targetPosition = localVector;
Expand Down Expand Up @@ -852,6 +854,7 @@ const createPlayerDiorama = ({
destroy() {
const index = dioramas.indexOf(diorama);
if (index !== -1) {
console.log(`remove diorama`, target)
dioramas.splice(index, 1);
}
},
Expand All @@ -877,6 +880,7 @@ const createPlayerDiorama = ({
} */

if (!detached) {
console.log(`add diorama`, target)
dioramas.push(diorama);
}
return diorama;
Expand Down
10 changes: 8 additions & 2 deletions src/CharacterHups.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const CharacterHup = function(props) {
const player = hup.parent.player;
let diorama = chatDioramas.get(player);
if (diorama) {
console.log(`already have a diorama`,player)
diorama.resetCanvases();
diorama.addCanvas(canvas);
} else {
console.log(`create a diorama`, player)
diorama = dioramaManager.createPlayerDiorama({
target: player,
objects: [player.avatar.model],
Expand All @@ -49,6 +51,7 @@ const CharacterHup = function(props) {
}

return () => {
console.log(`destroy diorama from character hups`, player)
diorama.destroy();
chatDioramas.delete(player);
};
Expand All @@ -62,6 +65,7 @@ const CharacterHup = function(props) {
function transitionend() {
if (!localOpen) {
const hupIndex = hups.indexOf(hup);
console.log(`hup removed`, hup)
const newHups = hups.slice();
newHups.splice(hupIndex, 1);
setHups(newHups);
Expand All @@ -88,6 +92,7 @@ const CharacterHup = function(props) {
hup.addEventListener('voicestart', voicestart);
function destroy(e) {
const player = hup.parent.player;
console.log('hupdestroy', hup, player);
chatDioramas.delete(player);

setLocalOpen(false);
Expand Down Expand Up @@ -154,11 +159,12 @@ export default function CharacterHups({
useEffect(() => {
function hupadd(e) {
const newHups = hups.concat([e.data.hup]);
// console.log('new hups', newHups);
console.log('new hups', newHups);
setHups(newHups);
}
function hupremove(e) {
const oldHup = e.data.hup;
console.log('hupremove', oldHup, hups);
const index = hups.indexOf(oldHup);
const newHups = hups.slice();
newHups.splice(index, 1);
Expand Down Expand Up @@ -201,7 +207,7 @@ export default function CharacterHups({
}
for (const remotePlayer in remotePlayers) {
remotePlayer.characterHups.removeEventListener('hupadd', hupadd);
localPlayer.characterHups.removeEventListener('hupremove', hupremove);
remotePlayer.characterHups.removeEventListener('hupremove', hupremove);
}
};
}, [localPlayer, npcs, remotePlayers, hups]);
Expand Down