Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1497 from Working-Title-MSFS-Mods/cj4-fix-warncau…
Browse files Browse the repository at this point in the history
…tion-sound

CJ4: Fix warning/caution tones
  • Loading branch information
dga711 authored Mar 6, 2022
2 parents 2a291eb + b8705bc commit 43bc237
Showing 1 changed file with 134 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3053,16 +3053,146 @@ class CJ4_SystemAnnunciations extends Cabin_Annunciations {
super();
this.rootElementName = "";
this.offStart = true;
this.warningTone = true;
this.warningToneNameZ = new Name_Z("WT_tone_warning");
this.cautionToneNameZ = new Name_Z("WT_tone_caution");
}
init(_root) {
super.init(_root);
this.annunciations = _root.querySelector(".SystemAnnunciations");
}

onUpdate(_dTime) {
if (!this.annunciations)
return;
super.onUpdate(_dTime);
onUpdate(_deltaTime) {
this.FrameCounterForAlternation++;
let masterWarningAcknowledged = SimVar.GetSimVarValue("MASTER WARNING ACKNOWLEDGED", "Bool");
let masterCautionAcknowledged = SimVar.GetSimVarValue("MASTER CAUTION ACKNOWLEDGED", "Bool");
for (let i = 0; i < this.allMessages.length; i++) {
let message = this.allMessages[i];
if (message.Visible && !message.Acknowledged) {
if (message.Type == Annunciation_MessageType.CAUTION && masterCautionAcknowledged) {
this.needReload = true;
message.Acknowledged = true;
if (this.firstAcknowledge && this.isAnnunciationsManager) {
if (this.gps.playInstrumentSound("aural_warning_ok"))
this.firstAcknowledge = false;
}
}
else if (message.Type == Annunciation_MessageType.WARNING && masterWarningAcknowledged) {
this.needReload = true;
message.Acknowledged = true;
}
}
}
for (var i = (this.FrameCounterForAlternation & 7); i < this.allMessages.length; i += 8) {
var message = this.allMessages[i];
var value = false;
if (message.Handler)
value = message.Handler() != 0;
if (value != message.Visible) {
this.needReload = true;
message.Visible = value;
message.Acknowledged = (this.gps.getTimeSinceStart() < 10000 && !this.offStart);
if (value) {
switch (message.Type) {
case Annunciation_MessageType.WARNING:
this.displayWarning.push(message);
break;
case Annunciation_MessageType.CAUTION:
this.displayCaution.push(message);
if (!message.Acknowledged && !this.isPlayingWarningTone && this.isAnnunciationsManager) {
let res = this.gps.playInstrumentSound("WT_tone_caution");
if (res)
this.isPlayingWarningTone = true;
}
break;
case Annunciation_MessageType.ADVISORY:
this.displayAdvisory.push(message);
break;
}
}
else {
switch (message.Type) {
case Annunciation_MessageType.WARNING:
for (let i = 0; i < this.displayWarning.length; i++) {
if (this.displayWarning[i].Text == message.Text) {
this.displayWarning.splice(i, 1);
break;
}
}
break;
case Annunciation_MessageType.CAUTION:
for (let i = 0; i < this.displayCaution.length; i++) {
if (this.displayCaution[i].Text == message.Text) {
this.displayCaution.splice(i, 1);
break;
}
}
break;
case Annunciation_MessageType.ADVISORY:
for (let i = 0; i < this.displayAdvisory.length; i++) {
if (this.displayAdvisory[i].Text == message.Text) {
this.displayAdvisory.splice(i, 1);
break;
}
}
break;
}
}
}
}
if (this.annunciations)
diffAndSetAttribute(this.annunciations, "state", this.gps.blinkGetState(800, 400) ? "Blink" : "None");
if (this.needReload) {
let warningOn = 0;
let cautionOn = 0;
let messages = "";
for (let i = this.displayWarning.length - 1; i >= 0; i--) {
messages += '<div class="Warning';
if (!this.displayWarning[i].Acknowledged) {
messages += '_Blink';
warningOn = 1;
}
messages += '">' + this.displayWarning[i].Text + "</div>";
}
for (let i = this.displayCaution.length - 1; i >= 0; i--) {
messages += '<div class="Caution';
if (!this.displayCaution[i].Acknowledged) {
messages += '_Blink';
cautionOn = 1;
}
messages += '">' + this.displayCaution[i].Text + "</div>";
}
for (let i = this.displayAdvisory.length - 1; i >= 0; i--) {
messages += '<div class="Advisory">' + this.displayAdvisory[i].Text + "</div>";
}
this.warningTone = warningOn > 0;
if (this.isAnnunciationsManager) {
let masterWarningActive = SimVar.GetSimVarValue("MASTER WARNING ACTIVE", "Bool");
if ((this.displayWarning.length > 0) != masterWarningActive || warningOn) {
SimVar.SetSimVarValue("K:MASTER_WARNING_SET", "Bool", (this.displayWarning.length > 0));
}
if (this.displayWarning.length > 0 && !warningOn) {
SimVar.SetSimVarValue("K:MASTER_WARNING_ACKNOWLEDGE", "Bool", 1);
}
let masterCautionActive = SimVar.GetSimVarValue("MASTER CAUTION ACTIVE", "Bool");
if ((this.displayCaution.length > 0) != masterCautionActive || cautionOn) {
SimVar.SetSimVarValue("K:MASTER_CAUTION_SET", "Bool", (this.displayCaution.length > 0));
}
if (this.displayCaution.length > 0 && !cautionOn) {
SimVar.SetSimVarValue("K:MASTER_CAUTION_ACKNOWLEDGE", "Bool", 1);
}
SimVar.SetSimVarValue("L:Generic_Master_Warning_Active", "Bool", warningOn);
SimVar.SetSimVarValue("L:Generic_Master_Caution_Active", "Bool", cautionOn);
}
if (this.annunciations)
diffAndSetHTML(this.annunciations, messages);
this.needReload = false;
}
if (this.warningTone && !this.isPlayingWarningTone && this.isAnnunciationsManager) {
let res = this.gps.playInstrumentSound("WT_tone_warning");
if (res)
this.isPlayingWarningTone = true;
}
}
}
class CJ4_SystemWarnings extends Cabin_Warnings {
Expand Down

0 comments on commit 43bc237

Please sign in to comment.