blob: 22506809e05b0e9b57581e5db67ae3719c34a3fe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
import { ipcRenderer, shell } from 'electron';
import GameServer from './gameserver/server';
import { switchPage } from './CustomEvents';
let GameServerList:GameServer[] = null;
let SelectedGameserver:GameServer = null;
const playBtn:HTMLButtonElement = document.getElementById('play') as (HTMLButtonElement);
playBtn.addEventListener('click', () => {
SelectedGameserver.play();
});
const sidebarReference = document.getElementById('sidebar');
let clickableMenueEntries:HTMLElement[]=[];
function updateView(){
// This is for updating the ui to new data
if(GameServerList){
// Clear every thing out
while (sidebarReference.firstChild) {
sidebarReference.removeChild(sidebarReference.firstChild);
}
GameServerList.forEach((server)=>{
sidebarReference.appendChild(server.getMenuEntry());
});
//Switch page according localstorage:
if(GameServerList.length != 0){
const selectedServer = localStorage.getItem("selected_server");
if(selectedServer && selectedServer !==null ){
if(GameServerList.filter((server)=>server.name==selectedServer).length == 0){
localStorage.removeItem("selected_server");
switchPage("SERVER", GameServerList[0].name);
}else{
switchPage("SERVER", selectedServer);
}
}else{
//TODO ask if is on special page like global settings first
switchPage("SERVER", GameServerList[0].name);
}
}
}
}
const serverPage = document.getElementById('serverPage');
const switchPageEvent = document.createElement('span');
switchPageEvent.classList.add("switch-page-event");
switchPageEvent.addEventListener("site-changed", (event:CustomEvent)=>{
if(event.detail.sitetype === "SERVER"){
SelectedGameserver = GameServerList.filter((server)=>server.name==event.detail.page)[0];
localStorage.setItem("selected_server", SelectedGameserver.name);
while (serverPage.firstChild) {
serverPage.removeChild(serverPage.firstChild);
}
let page = SelectedGameserver.getPage(event.detail.subPage);
serverPage.appendChild(page);
// page.classList.add('animated');
// page.classList.add('fadeIn');
}else{
SelectedGameserver == null;
}
if(typeof(SelectedGameserver) === "undefined" || SelectedGameserver == null){
// No gameserver selected
playBtn.hidden = true;
}else{
// A gameserver is selected
playBtn.innerText=`Play ${SelectedGameserver.menuName}`;
playBtn.hidden = false;
}
setBackground();
});
document.getElementById("topbar").appendChild(switchPageEvent);
let peviousSelectedGameserver:any=null;
const contentBackground = document.getElementById('contentBackground');
function setBackground(){
if(peviousSelectedGameserver !== SelectedGameserver){
while (contentBackground.firstChild) {
contentBackground.removeChild(contentBackground.firstChild);
}
if(typeof(SelectedGameserver) === "undefined" || SelectedGameserver == null){
contentBackground.hidden=true;
contentBackground.classList.add('hidden');
}else{
if(SelectedGameserver.backgrounds[0] && !SelectedGameserver.backgrounds[0].isVideo){
const background1 = document.createElement('img');
background1.src = `./media/server/${SelectedGameserver.backgrounds[0].file}`;
contentBackground.appendChild(background1);
background1.classList.add('animated');
background1.classList.add('fadeIn');
}
contentBackground.appendChild(document.createElement('div'))
contentBackground.hidden=false;
contentBackground.classList.remove('hidden');
}
}
peviousSelectedGameserver = SelectedGameserver;
}
ipcRenderer.on('status-update', (event:any, status:any) => {
// Everything that isnt server view related is in index.ts
playBtn.disabled = status.playing;
})
import { GameServers } from './gameserver/data';
GameServerList = GameServers;
updateView();
|