Skip to content

Commit

Permalink
Inhibbitors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Nov 30, 2023
1 parent 68d68b0 commit ba88a69
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
6 changes: 6 additions & 0 deletions client/src/client/services/media/objects/Channel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export class Channel {
this.updateVolume();
}

setMediaMuted(muted) {
this.sounds.forEach((sound) => {
sound.setMediaMuted(muted);
});
}

setChannelVolume(newVolume, cancelFade = true) {
this.channelVolume = newVolume;
this.updateVolume(cancelFade);
Expand Down
20 changes: 20 additions & 0 deletions client/src/client/services/media/objects/Mixer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class Mixer {
// execute the function and remove it from the map
this.destructionHandlers = {};

// set with channel tags and scores
// if scores are over 1, then the channel will be muted
this.inhibbitors = {};

// loop over channels and call tick()
setInterval(() => {
this.tick();
Expand Down Expand Up @@ -43,6 +47,22 @@ export class Mixer {
}
delete this.destructionHandlers[key];
});

// go over all channels and check if they should be inhibited
this.channels.forEach((channel) => {
let score = 0;
channel.tags.forEach((value, tag) => {
if (this.inhibbitors[tag] != null) {
score += this.inhibbitors[tag];
}
});

if (score > 1) {
channel.setChannelVolume(0);
} else {
channel.setChannelVolume(100);
}
});
}

whenFinished(channelId, handler) {
Expand Down
7 changes: 7 additions & 0 deletions client/src/client/services/media/objects/Sound.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ export class Sound extends AudioSourceProcessor {
this.controller.connect(node);
}

setMediaMuted(muted) {
this.whenInitialized(() => {
// override mute state
this.soundElement.muted = muted;
});
}

registerMixer(mixer, channel) {
this.mixer = mixer;
this.channel = channel;
Expand Down
5 changes: 2 additions & 3 deletions client/src/client/services/world/objects/SpeakerPlayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ export class SpeakerPlayer {
async initialize() {
const createdChannel = new Channel(this.id);
createdChannel.trackable = true;
createdChannel.setTag('SPEAKER');
createdChannel.setTag(this.id);
this.channel = createdChannel;
const createdMedia = new Sound(this.source);
this.media = createdMedia;
createdChannel.mixer = MediaManager.mixer;

createdChannel.addSound(createdMedia);
MediaManager.mixer.addChannel(createdChannel);

Expand All @@ -41,8 +42,6 @@ export class SpeakerPlayer {
createdMedia.startDate(this.startInstant, true);
}
await createdMedia.finalize();
createdChannel.setTag(this.id);
createdChannel.setTag('SPECIAL');
MediaManager.mixer.updateCurrent();

if (this.doPickup) {
Expand Down

0 comments on commit ba88a69

Please sign in to comment.