-
Notifications
You must be signed in to change notification settings - Fork 1
/
pokedex.js
153 lines (118 loc) · 4.6 KB
/
pokedex.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
function InitWebGLContext() {
var glCanvas = document.createElement("canvas");
// first, try standard WebGL context
var gl = glCanvas.getContext("webgl");
if (!gl) {
// if failed, try experimental one
gl = glCanvas.getContext("experimental-webgl");
}
if (!gl) {
alert("Your browser does not support WebGL");
return;
}
// here we get WebGL context -
// for demonstation let's show some info
console.log("WebGL version: " + gl.getParameter(gl.VERSION));
console.log("WebGL shader version: " + gl.getParameter(gl.SHADING_LANGUAGE_VERSION));
console.log("WebGL vendor: " + gl.getParameter(gl.VENDOR));
console.log("WebGL renderer: " + gl.getParameter(gl.RENDERER));
try {
f = gl.getSupportedExtensions()
} catch (m) {
f = "Extensions unavailable"
}
console.log("WebGL extensions: " + f);
console.log("WebGL num texture units: " + gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS));
console.log("WebGL max texture size: " + gl.getParameter(gl.MAX_TEXTURE_SIZE));
console.log("WebGL max cubemap size: " + gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE));
console.log("WebGL max vertex attribs: " + gl.getParameter(gl.MAX_VERTEX_ATTRIBS));
console.log("WebGL max vshader vectors: " + gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS));
console.log("WebGL max fshader vectors: " + gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS));
console.log("WebGL max varying vectors: " + gl.getParameter(gl.MAX_VARYING_VECTORS));
}
$(document).ready(function() {
InitWebGLContext();
$("#pokelist .scroll-content li").click(function() {
loadMonster('#'+$(this).attr('id'));
});
$("#tabs li").click(function() {
$('#tabs li').removeClass('active');
$(this).addClass('active');
$('.poketab').hide();
$('#poke'+$(this).attr('id')).show();
});
$(window).resize(function() {
$("#pokedex").css({
'position': 'absolute',
'top': (($('body').height()-$('#pokedex').height())/2)+'px',
'left': (($('body').width()-$('#pokedex').width())/2)+'px'
});
});
$(window).resize();
$('#totalcount').text($('.scroll-content li').length);
$('#totalcatch').text($('.scroll-content li .catch').length + ' (' + Math.round($('.scroll-content li .catch').length / $('.scroll-content li').length *100) +'%)');
var numPkmn = (window.location.hash!='')?window.location.hash.substr(0,1)+"num_"+window.location.hash.substr(1,4):'#num_001';
loadMonster(numPkmn);
$('#pokelist .scroll-content').scrollTo(numPkmn);
//permet de
x3d_element = document.getElementById('x3dom-logo');
});
function loadMonster(Number) {
// met à jour la liste
$('#pokelist .scroll-content li').removeClass('active');
$(Number).addClass('active');
num = $(Number).children('.pokelist_pokenum').text();
name = $(Number).children('.pokelist_pokename').text();
$('#block2 #pokename .title').text('#'+num+' '+name);
//créé le chemin avec en paramètre un timestamp (desactive le cache)
path = 'x3d/?n='+num+'&d='+new Date().getTime();
//charge un objet X3D dans la balise scene via Ajax
try {
$('#x3d').hide();
$('scene').load(path,function(){
$('scene').x3d('realign');
$('#x3d').show();
snd = new Audio();
if (typeof snd.canPlayType === "function") {
if(snd.canPlayType("audio/mpeg") !== "") {
snd.src = "Audio/Cries/mp3/"+num+".mp3";
} else if(snd.canPlayType("audio/wav") !== "") {
snd.src = "Audio/Cries/wav/"+num+".wav";
} else if(snd.canPlayType("audio/ogg") !== "") {
snd.src = "Audio/Cries/ogg/"+num+".ogg";
}
snd.play();
}
});
} catch(err){
console.log(err);
return false;
}
$.getJSON('stats/', {n:num}, function(data) {
//console.log(data);
$('#poketext').text(data.desc);
$('.levelbar').each(function(index) {
stat = parseInt(data.stats[index].base_stat);
$(this).css('width', Math.floor((stat/255)*100)+'%').attr('title', stat);
});
$('#pokemoves').html('');
html = '<tr>';
for(header in data.moves[0]){
html += '<th class="'+header+'">'+header+'</th>';
}
html += '</tr>';
$('#pokemoves').append(html);
$(data.moves).each(function(index) {
html = '<tr>';
for(move in this){
if (move == "type") {
html += '<td class="'+move+'"><img src="Graphics/types/'+this[move]+'.png" /></td>';
} else {
html += '<td class="'+move+'">'+this[move]+'</td>';
}
}
html += '</tr>';
$('#pokemoves').append(html);
});
});
}