bitburner-src/utils/FactionInvitationBox.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-09-05 01:09:30 +02:00
import { joinFaction } from "../src/Faction/FactionHelpers";
import { Engine } from "../src/engine";
import { Player } from "../src/Player";
import { clearEventListeners } from "./uiHelpers/clearEventListeners";
import { Page, routing } from "../src/ui/navigationTracking";
/* Faction Invitation Pop-up box */
function factionInvitationBoxClose() {
2021-09-09 05:47:34 +02:00
var factionInvitationBox = document.getElementById("faction-invitation-box-container");
2021-09-05 01:09:30 +02:00
factionInvitationBox.style.display = "none";
}
function factionInvitationBoxOpen() {
2021-09-09 05:47:34 +02:00
var factionInvitationBox = document.getElementById("faction-invitation-box-container");
2021-09-05 01:09:30 +02:00
factionInvitationBox.style.display = "flex";
}
function factionInvitationSetText(txt) {
2021-09-05 01:09:30 +02:00
var textBox = document.getElementById("faction-invitation-box-text");
textBox.innerHTML = txt;
}
//ram argument is in GB
function factionInvitationBoxCreate(faction) {
2021-09-09 05:47:34 +02:00
factionInvitationSetText("You have received a faction invitation from " + faction.name);
2021-09-05 01:09:30 +02:00
faction.alreadyInvited = true;
Player.factionInvitations.push(faction.name);
2021-09-05 01:09:30 +02:00
if (routing.isOn(Page.Factions)) {
Engine.loadFactionsContent();
}
2021-09-05 01:09:30 +02:00
var newYesButton = clearEventListeners("faction-invitation-box-yes");
newYesButton.addEventListener("click", function () {
//Remove from invited factions
var i = Player.factionInvitations.findIndex((facName) => {
return facName === faction.name;
});
2021-09-05 01:09:30 +02:00
if (i === -1) {
console.error("Could not find faction in Player.factionInvitations");
}
joinFaction(faction);
factionInvitationBoxClose();
if (routing.isOn(Page.Factions)) {
Engine.loadFactionsContent();
}
return false;
});
2021-09-05 01:09:30 +02:00
var noButton = clearEventListeners("faction-invitation-box-no");
noButton.addEventListener("click", function () {
factionInvitationBoxClose();
return false;
});
2021-09-05 01:09:30 +02:00
factionInvitationBoxOpen();
}
2021-09-05 01:09:30 +02:00
export { factionInvitationBoxCreate };