-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
204 lines (161 loc) · 5.86 KB
/
index.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
let informationBox = document.getElementById('informationBox')
let shieldItems = document.getElementsByClassName("shield-item")
let selectedCharacter = []
for (const item of shieldItems) {
item.addEventListener("click", e => {
item.classList.toggle('shild-item-focus')
if(item.classList.contains('shild-item-focus')){
selectedCharacter.push(item)
}else{
selectedCharacter = selectedCharacter.filter(i => i !== item)
}
if(selectedCharacter.length > 2){
informationBox.classList.add('invisable')
for (const schars of selectedCharacter) {
schars.classList.toggle('shild-item-focus')
}
selectedCharacter = []
document.getElementById('errorInstructions').classList.remove('warning')
setTimeout(() =>{
document.getElementById('errorInstructions').classList.add('warning')
}, 100)
}else{
informationBox.classList.remove('invisable')
showPlayerInfo (getCharacterByHTMLValue(item))
}
if(selectedCharacter.length == 2){
playButton.classList.remove('invisable')
playButtonListner = playButton.addEventListener('click', () => {
player1 = getCharacterByHTMLValue (selectedCharacter[0])
player2 = getCharacterByHTMLValue (selectedCharacter[1])
sessionStorage.setItem('player1', JSON.stringify(player1))
sessionStorage.setItem('player2', JSON.stringify(player2))
window.location.href = "board.html"
})
}else{
playButton.removeEventListener('click',playButtonListner)
playButton.classList.add('invisable')
}
})
}
function showPlayerInfo(character) {
document.getElementById('chracterName').innerText = character.name
document.getElementById('ancestralWeapons').innerText = character.ancestralWeapons
document.getElementById('coatOfArms').innerText = character.coatOfArms
document.getElementById('house').innerText = character.house
document.getElementById('charcterAlias').innerText = character.alias
document.getElementById('characterTitle').innerText = character.title
document.getElementById('houseWords').innerText = character.words
}
function getCharacterByHTMLValue(item) {
switch (item.getAttribute('value')) {
case 'jon': return playableCharacters[0]
case 'dineris': return playableCharacters[1]
case 'tyrian': return playableCharacters[2]
case 'brian': return playableCharacters[3]
}
}
let playButton = document.getElementById('playButton')
let playButtonListner = null
let player1
let player2
let playableCharacters =
[
{
name:"Jon Snow",
ID:583,
modefiers:[]
},
{
name:"Daenerys Targaryen",
ID:1303,
modefiers:[]
},
{
name:"Tyrion Lannister",
ID:1052,
modefiers:[]
},
{
name:"Brienne of Tarth",
ID:216,
modefiers:[]
}
]
function fetchCharacter(charcterObject){
let returnCharacter = {}
fetch('https://anapioficeandfire.com/api/characters/' + charcterObject.ID)
.then(respons => respons.json())
.then(json => {
charcterObject.name = json.name
charcterObject.title = (json.titles.length != 0) ? json.titles[0] : "None"
charcterObject.alias = (json.aliases.length
!= 0) ? json.aliases[0] : "None"
fetch(json.allegiances[0])
.then(respons => respons.json())
.then(json => {
charcterObject.house = json.name
charcterObject.coatOfArms = json.coatOfArms
charcterObject.words = json.words
charcterObject.ancestralWeapons = json.ancestralWeapons
// console.log(returnCharacter);
// charcterObject.stats = charcterObject
})
.then( () => {
// console.log(charcterObject)
return charcterObject
})
})
.catch(error => console.log("ERROR MAN!: ",error))
}
for (let character of playableCharacters) {
character = fetchCharacter(character)
}
// playerOne = fetchCharacter(playableCharacters[1])
// playerTwo = fetchCharacter(playableCharacters[0])
// console.log(playerOne, " - ", playertwo);
// console.log("que passa: " ,JSON.stringify(playertwo))
// console.log(playerOne)
function fadeEffect(type) {
switch (type) {
case 'FADE_OUT':
break;
case 'FADE_INN':
break;
}
if(document.getElementById('fadeBox')){
let fadeBox = document.getElementById('fadeBox')
let parent = fadeBox.parentElement
console.log(parent)
parent.removeChild(fadeBox)
console.log(parent)
}
let fadeHtml = `
<style id="fadeAnimStyle">
#fadeBox{
top: 0;
left: 0;
position: absolute;
z-index: 9999;
width: 200%;
height: 200%;
background: black;
}
.fade-inn{
animation: anim-fade-inn 1s forwards
}
@keyframes anim-fade-inn{
0% {opacity: 1;}
100% {opacity: 0; z-index: -1;}
}
.fade-out{
animation: anim-fade-out 1s forwards
}
@keyframes anim-fade-out{
0% {opacity: 0;}
100% {opacity: 1; z-index: 9999;}
}
</style>
<div id="fadeBox" class="fade-out"></div>
`
}