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";
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2017-02-16 19:52:11 +01:00
|
|
|
/* Faction Invitation Pop-up box */
|
2017-08-30 19:44:29 +02:00
|
|
|
function factionInvitationBoxClose() {
|
2021-09-05 01:09:30 +02:00
|
|
|
var factionInvitationBox = document.getElementById(
|
|
|
|
"faction-invitation-box-container",
|
|
|
|
);
|
|
|
|
factionInvitationBox.style.display = "none";
|
2017-02-16 19:52:11 +01:00
|
|
|
}
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
function factionInvitationBoxOpen() {
|
2021-09-05 01:09:30 +02:00
|
|
|
var factionInvitationBox = document.getElementById(
|
|
|
|
"faction-invitation-box-container",
|
|
|
|
);
|
|
|
|
factionInvitationBox.style.display = "flex";
|
2017-02-16 19:52:11 +01:00
|
|
|
}
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
function factionInvitationSetText(txt) {
|
2021-09-05 01:09:30 +02:00
|
|
|
var textBox = document.getElementById("faction-invitation-box-text");
|
|
|
|
textBox.innerHTML = txt;
|
2017-02-16 19:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//ram argument is in GB
|
2017-08-30 19:44:29 +02:00
|
|
|
function factionInvitationBoxCreate(faction) {
|
2021-09-05 01:09:30 +02:00
|
|
|
factionInvitationSetText(
|
|
|
|
"You have received a faction invitation from " + faction.name,
|
|
|
|
);
|
|
|
|
faction.alreadyInvited = true;
|
|
|
|
Player.factionInvitations.push(faction.name);
|
2018-03-03 22:05:33 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (routing.isOn(Page.Factions)) {
|
|
|
|
Engine.loadFactionsContent();
|
|
|
|
}
|
2017-07-27 04:56:14 +02:00
|
|
|
|
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;
|
2017-02-16 19:52:11 +01:00
|
|
|
});
|
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;
|
|
|
|
});
|
2017-07-27 04:56:14 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
var noButton = clearEventListeners("faction-invitation-box-no");
|
|
|
|
noButton.addEventListener("click", function () {
|
|
|
|
factionInvitationBoxClose();
|
|
|
|
return false;
|
|
|
|
});
|
2017-07-27 04:56:14 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
factionInvitationBoxOpen();
|
2017-07-27 04:56:14 +02:00
|
|
|
}
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
export { factionInvitationBoxCreate };
|