|
@@ -1,417 +0,0 @@
|
1
|
|
-<html>
|
2
|
|
- <head>
|
3
|
|
- <meta charset="utf8">
|
4
|
|
- <script src="dice.js"></script>
|
5
|
|
- <script src="names.js"></script>
|
6
|
|
- <script src="l5r_data.js"></script>
|
7
|
|
- <script src="random_utils.js"></script>
|
8
|
|
- <script src="display.js"></script>
|
9
|
|
- <script src="l5r.js"></script>
|
10
|
|
- <script src="players.js"></script>
|
11
|
|
- <script>
|
12
|
|
-
|
13
|
|
- var npcs = [];
|
14
|
|
- var result = [];
|
15
|
|
- var result1 = [];
|
16
|
|
- var result2 = [];
|
17
|
|
- var current_target= 0;
|
18
|
|
-
|
19
|
|
- function target(){
|
20
|
|
- return characters.at(current_target) ;
|
21
|
|
- }
|
22
|
|
-
|
23
|
|
- var npc_summary = document.getElementById("npc.summary");
|
24
|
|
- function characterToLine(){
|
25
|
|
- let line = document.CreateElement('td');
|
26
|
|
- let cell = document.CreateElement('tr');
|
27
|
|
- }
|
28
|
|
-
|
29
|
|
- function generateNPC(){
|
30
|
|
- var newNPC = new Character();
|
31
|
|
- newNPC.generate( document.getElementById("npc-level").value );
|
32
|
|
- return newNPC;
|
33
|
|
- }
|
34
|
|
-
|
35
|
|
- function generateNPCs( size ){
|
36
|
|
- let result = [];
|
37
|
|
-
|
38
|
|
- for(let i = 0; i < size ; i++){
|
39
|
|
- result[i] = generateNPC( i );
|
40
|
|
- }
|
41
|
|
-
|
42
|
|
- return result;
|
43
|
|
- }
|
44
|
|
-
|
45
|
|
- function skirmish( size ){
|
46
|
|
- let npcs = generateNPCs( size );
|
47
|
|
-
|
48
|
|
- for(let i = 0; i < size ; i+=2){
|
49
|
|
- if( (npcs[i]) && (npcs[i + 1]))
|
50
|
|
- result[i] = fight(npcs[i], npcs[i + 1]);
|
51
|
|
- }
|
52
|
|
-
|
53
|
|
- for( let i = 0; i < size ; i++ ){
|
54
|
|
- ;
|
55
|
|
- }
|
56
|
|
- }
|
57
|
|
-
|
58
|
|
- function swissContest( size ){
|
59
|
|
- let result = [];
|
60
|
|
- let npcs = generateNPCs( size );
|
61
|
|
-
|
62
|
|
- for(let i = 0; i < npcs.length; i++){
|
63
|
|
- result[i] = [];
|
64
|
|
-
|
65
|
|
- for(let j = 0; j < npcs.length; j++){
|
66
|
|
- result[i][j] = ( fight( npcs[i], npcs[j] ) );
|
67
|
|
- npcs[i].fullHeal();
|
68
|
|
- npcs[j].fullHeal();
|
69
|
|
- }
|
70
|
|
- }
|
71
|
|
- return result;
|
72
|
|
- }
|
73
|
|
-
|
74
|
|
- function winRateSwissContest( array, stat){
|
75
|
|
- let result = [];
|
76
|
|
-
|
77
|
|
- for(let i = 0; i < array.length; i++){
|
78
|
|
- let winrate = 0;
|
79
|
|
- let total = 0;
|
80
|
|
- for(let j = 0; j < array[i].length; j++){
|
81
|
|
- winrate += ( array[i][j].winner_side == "attacker" )? 1: 0;
|
82
|
|
- total++;
|
83
|
|
- }
|
84
|
|
-
|
85
|
|
- result[i] = winrate/total;
|
86
|
|
- }
|
87
|
|
- return result;
|
88
|
|
- }
|
89
|
|
-
|
90
|
|
- function hasClass( elem, className){
|
91
|
|
-
|
92
|
|
- for( let i = 0 ; i < elem.classList.length ; i++ )
|
93
|
|
- if( elem.classList[ i ] === className )
|
94
|
|
- return elem;
|
95
|
|
-
|
96
|
|
- return 0;
|
97
|
|
- };
|
98
|
|
-
|
99
|
|
- function getClassFromList( list, className ){
|
100
|
|
- let result = [];
|
101
|
|
-
|
102
|
|
- for( let i = 0 ; i < list.childNodes.length ; i++ )
|
103
|
|
- if( hasClass( list.childNodes[ i ], className ))
|
104
|
|
- result.push( list.childNodes[ i ] );
|
105
|
|
-
|
106
|
|
- return result;
|
107
|
|
- }
|
108
|
|
-
|
109
|
|
- function inputFromElementList( list, input_type ){
|
110
|
|
- let result = [];
|
111
|
|
-
|
112
|
|
- for( let i = 0 ; i ; i++ )
|
113
|
|
- if( list[ i ].getAttributeNames().includes( input_type ))
|
114
|
|
- result.push( list[i] );
|
115
|
|
-
|
116
|
|
- return result;
|
117
|
|
- }
|
118
|
|
-
|
119
|
|
- function display_data( data, anchor ){
|
120
|
|
- let html_display = document.getElementById( anchor );
|
121
|
|
- let headers = [ "name", "initiative", "TN", "attack", "damage", "wounds" ];
|
122
|
|
- let hs = document.createElement("tr");
|
123
|
|
-
|
124
|
|
-
|
125
|
|
- for(let i = 0; i < headers.length ; i++){
|
126
|
|
- let h = document.createElement("th");
|
127
|
|
- h.innerText = headers[ i ];
|
128
|
|
- hs.appendChild( h );
|
129
|
|
- }
|
130
|
|
-
|
131
|
|
- html_display.appendChild( hs ) ;
|
132
|
|
-
|
133
|
|
- for(let i = 0; i < data.length ; i++){
|
134
|
|
- let line = document.createElement( "tr" );
|
135
|
|
- line.setAttribute("id", i + "-" + anchor );
|
136
|
|
- let name = document.createElement("td");
|
137
|
|
- name.innerText = data[i]["get"+capitalize( headers[0] )]();
|
138
|
|
- line.appendChild( name );
|
139
|
|
-
|
140
|
|
- for(let j = 1; j < headers.length ; j++){
|
141
|
|
- let cell = document.createElement("td");
|
142
|
|
- let button = document.createElement("button");
|
143
|
|
- button.setAttribute("class", headers[j]);
|
144
|
|
- let id = i + "-"+j+"-" + anchor;
|
145
|
|
-
|
146
|
|
- button.innerText = headers[j];
|
147
|
|
-
|
148
|
|
- button.addEventListener('click', function(event) {
|
149
|
|
- document.getElementById( id ).value = data[i]["get"+capitalize( headers[j] )]();
|
150
|
|
- });
|
151
|
|
- cell.appendChild( button );
|
152
|
|
-
|
153
|
|
- let result = document.createElement("input");
|
154
|
|
- result.setAttribute("id", id);
|
155
|
|
- result.setAttribute("type", "text");
|
156
|
|
- result.setAttribute("class", "result");
|
157
|
|
- cell.appendChild( result );
|
158
|
|
- line.appendChild( cell );
|
159
|
|
- }
|
160
|
|
- let cell1 = document.createElement("td");
|
161
|
|
- let targeted = document.createElement("input");
|
162
|
|
- targeted.setAttribute("type", "checkbox");
|
163
|
|
- targeted.setAttribute("class", "targeted");
|
164
|
|
- targeted.checked = false;
|
165
|
|
- targeted.addEventListener('click', function(event) {
|
166
|
|
- let targeteds = document.getElementsByClassName( "targeted" );
|
167
|
|
- for(let targeted in targeteds){
|
168
|
|
- if(targeteds[targeted] != this)
|
169
|
|
- targeteds[targeted].checked = false;
|
170
|
|
-
|
171
|
|
- current_target = this.parentNode.parentNode.id.split("-")[0];
|
172
|
|
- }
|
173
|
|
- });
|
174
|
|
- cell1.appendChild( targeted );
|
175
|
|
- line.appendChild( cell1 );
|
176
|
|
-
|
177
|
|
- cell2 = document.createElement("td");
|
178
|
|
- let attacking = document.createElement("input");
|
179
|
|
- attacking.setAttribute("type", "button");
|
180
|
|
- attacking.setAttribute("class", "attacking");
|
181
|
|
- attacking.value = "Attack";
|
182
|
|
- attacking.checked = false;
|
183
|
|
- attacking.addEventListener('click', function(event) {
|
184
|
|
- characters.at( this.parentNode.parentNode.id.split("-")[0] ).attacking( target() );
|
185
|
|
- triggerField( "Wounds" );
|
186
|
|
- triggerField( "TN" );
|
187
|
|
- });
|
188
|
|
- cell2.appendChild( attacking );
|
189
|
|
- line.appendChild( cell2 );
|
190
|
|
-
|
191
|
|
- let cell_switchStance = document.createElement("td");
|
192
|
|
- let switchStance = document.createElement("input");
|
193
|
|
- switchStance.setAttribute("type", "button");
|
194
|
|
- switchStance.value = "Attack Stance";
|
195
|
|
- cell_switchStance.appendChild( switchStance );
|
196
|
|
- cell_switchStance.addEventListener('click', function(event) {
|
197
|
|
- let charac = characters.at( this.parentNode.id.split("-")[0] );
|
198
|
|
- charac.switchStance();
|
199
|
|
- event.target.value = charac.stance;
|
200
|
|
- triggerField( "TN" );
|
201
|
|
- });
|
202
|
|
- line.appendChild( cell_switchStance );
|
203
|
|
-
|
204
|
|
- html_display.appendChild( line );
|
205
|
|
- }
|
206
|
|
- }
|
207
|
|
-
|
208
|
|
- function popAssociativeMaker( associative, anchor ){
|
209
|
|
-
|
210
|
|
- let result = document.createElement( "div" );
|
211
|
|
- result.setAttribute( "class", "popup" );
|
212
|
|
- let exit = document.createElement("input");
|
213
|
|
- exit.setAttribute("type", "button");
|
214
|
|
- exit.setAttribute("class", "exit");
|
215
|
|
- exit.value = "×";
|
216
|
|
- exit.addEventListener('click', function(event) {
|
217
|
|
- anchor.value = JSON.stringify( formToData( result ) );
|
218
|
|
- result.parentNode.removeChild( result );
|
219
|
|
- });
|
220
|
|
-
|
221
|
|
- result.appendChild( exit );
|
222
|
|
-
|
223
|
|
- for( let i in associative ){
|
224
|
|
- switch( typeof varType ){
|
225
|
|
- case "function":
|
226
|
|
- break;
|
227
|
|
- case "object":
|
228
|
|
- result.appendChild( inputField( i, associative[ i ] || "", true, null, function(event) {
|
229
|
|
- this.value = popObjectMaker( associative[ i ], line );
|
230
|
|
- } ));
|
231
|
|
- break;
|
232
|
|
- default:
|
233
|
|
- result.appendChild( inputField( i, associative[ i ] || "") );
|
234
|
|
- }
|
235
|
|
- }
|
236
|
|
-
|
237
|
|
- let add = document.createElement("input");
|
238
|
|
- add.setAttribute("type", "button");
|
239
|
|
- add.setAttribute("class", "add");
|
240
|
|
- add.value = "+";
|
241
|
|
- add.addEventListener('click', function(event) {
|
242
|
|
- result.appendChild( inputField( "", "", true) );
|
243
|
|
- });
|
244
|
|
- result.appendChild( add );
|
245
|
|
-
|
246
|
|
- document.getElementsByTagName('body')[0].appendChild( result );
|
247
|
|
-
|
248
|
|
- return result;
|
249
|
|
- }
|
250
|
|
-
|
251
|
|
- function inputField( field, value, modifiable, label_onclick, input_onclick ){
|
252
|
|
- field = (( typeof field === "unsigned" ) || !field )? "" : field;
|
253
|
|
- value = (( typeof value === "unsigned" ) || !value )? "" : value;
|
254
|
|
- modifiable = (( typeof modifiable === "unsigned" ) || !modifiable )? false : true ;
|
255
|
|
-
|
256
|
|
- let line= document.createElement("div");
|
257
|
|
- let input = document.createElement("input");
|
258
|
|
- let label ;
|
259
|
|
-
|
260
|
|
- if( modifiable ){
|
261
|
|
- label = document.createElement("input");
|
262
|
|
- label.setAttribute("type", "text");
|
263
|
|
- }else{
|
264
|
|
- label = document.createElement("label");
|
265
|
|
- }
|
266
|
|
-
|
267
|
|
- line.setAttribute("class", "line");
|
268
|
|
- label.setAttribute("class", "label");
|
269
|
|
- label.innerText = field;
|
270
|
|
-
|
271
|
|
- if( label_onclick instanceof Function )
|
272
|
|
- label.addEventListener('click', label_onclick );
|
273
|
|
-
|
274
|
|
- line.appendChild( label );
|
275
|
|
-
|
276
|
|
- input.setAttribute("type", "text");
|
277
|
|
- input.setAttribute("class", "maker");
|
278
|
|
- input.value = value;
|
279
|
|
-
|
280
|
|
- if( input_onclick instanceof Function )
|
281
|
|
- input.addEventListener('click', label_onclick );
|
282
|
|
-
|
283
|
|
- input.checked = false;
|
284
|
|
- line.appendChild( input );
|
285
|
|
-
|
286
|
|
- return line;
|
287
|
|
- }
|
288
|
|
-
|
289
|
|
- function popObjectMaker( object, anchor, dictionnary ){
|
290
|
|
- let prototype = new object;
|
291
|
|
- let result = document.createElement( "div" );
|
292
|
|
- result.setAttribute( "class", "popup" );
|
293
|
|
-
|
294
|
|
- let exit = document.createElement("input");
|
295
|
|
- exit.setAttribute("type", "button");
|
296
|
|
- exit.setAttribute("class", "exit");
|
297
|
|
- exit.value = "×";
|
298
|
|
-
|
299
|
|
- if( typeof dictionnary === "object" )
|
300
|
|
- exit.addEventListener('click', function(event) {
|
301
|
|
- formToDictonnary( result, dictionnary);});
|
302
|
|
- else
|
303
|
|
- exit.addEventListener('click', function(event) {
|
304
|
|
- saveAndExitForm( result);});
|
305
|
|
- result.appendChild( exit );
|
306
|
|
-
|
307
|
|
- for( let i in prototype ){
|
308
|
|
- let varType = prototype[i];
|
309
|
|
- let line= document.createElement("div");
|
310
|
|
- let input = document.createElement("input");
|
311
|
|
- let label = document.createElement("label");
|
312
|
|
-
|
313
|
|
- switch( typeof varType ){
|
314
|
|
- case "function":
|
315
|
|
- break;
|
316
|
|
- case "object":
|
317
|
|
- line= document.createElement("div");
|
318
|
|
- line.setAttribute("class", "line");
|
319
|
|
- label.setAttribute("type", "button");
|
320
|
|
- label.classList.add("label");
|
321
|
|
- label.innerText = i;
|
322
|
|
- line.appendChild( label );
|
323
|
|
-
|
324
|
|
- input.setAttribute("type", "text");
|
325
|
|
- input.classList.add("json");
|
326
|
|
- input.classList.add("maker");
|
327
|
|
- input.value = prototype[ i ] || "";
|
328
|
|
- input.checked = false;
|
329
|
|
- input.addEventListener('click', function(event) {
|
330
|
|
- this.value = popAssociativeMaker( prototype[ i ], input );
|
331
|
|
- });
|
332
|
|
- line.appendChild( input );
|
333
|
|
-
|
334
|
|
- result.appendChild( line );
|
335
|
|
- break;
|
336
|
|
- default:
|
337
|
|
- line.setAttribute("class", "line");
|
338
|
|
- label.setAttribute("type", "button");
|
339
|
|
- label.classList.add("label");
|
340
|
|
- label.innerText = i;
|
341
|
|
- line.appendChild( label );
|
342
|
|
-
|
343
|
|
- input.setAttribute("type", "text");
|
344
|
|
- input.classList.add("maker");
|
345
|
|
- input.value = prototype[ i ] || "";
|
346
|
|
- input.checked = false;
|
347
|
|
- line.appendChild( input );
|
348
|
|
-
|
349
|
|
- result.appendChild( line );
|
350
|
|
- }
|
351
|
|
- }
|
352
|
|
-
|
353
|
|
- if( anchor instanceof Element )
|
354
|
|
- anchor.appendChild( result );
|
355
|
|
- else
|
356
|
|
- document.getElementsByTagName('body')[0].appendChild( result );
|
357
|
|
-
|
358
|
|
- return result;
|
359
|
|
- }
|
360
|
|
-
|
361
|
|
- function formToData( form ){
|
362
|
|
- let lines = form.getElementsByClassName( "line" ) ;
|
363
|
|
- let data = {} ;
|
364
|
|
-
|
365
|
|
- for ( let i = 0 ; i < lines.length ; i++ ){
|
366
|
|
- let labels = getClassFromList( lines[ i ], "label");
|
367
|
|
- let makers = getClassFromList( lines[ i ], "maker");
|
368
|
|
-
|
369
|
|
- if(( lines[ i ] instanceof Element ) && ( labels[0] || makers[0] )){
|
370
|
|
- let index = labels[0].value || labels[0].innerText;
|
371
|
|
- let value = makers[0].value || makers[0].innerText ;
|
372
|
|
- value = (hasClass( makers[0], "json" ))? JSON.parse( value ) : value ;
|
373
|
|
-
|
374
|
|
- data[ index ] = value ;
|
375
|
|
- }
|
376
|
|
- }
|
377
|
|
- return data ;
|
378
|
|
- }
|
379
|
|
-
|
380
|
|
- function saveAndExitForm( form ){
|
381
|
|
- form.value = JSON.stringify( formToData( form ) );
|
382
|
|
- form.parentNode.removeChild( form );
|
383
|
|
- }
|
384
|
|
-
|
385
|
|
- function formToDictonnary( form, dictionnary){
|
386
|
|
- return dictionnary.create( formToData( form ) );
|
387
|
|
- }
|
388
|
|
-
|
389
|
|
- function triggerField( field ){
|
390
|
|
- let fields = document.getElementsByClassName( field ) ;
|
391
|
|
-
|
392
|
|
- for (let i = 0 ; i < fields.length ; i++ ){
|
393
|
|
- fields[i].click();
|
394
|
|
- }
|
395
|
|
- }
|
396
|
|
-
|
397
|
|
- function main(){
|
398
|
|
- display_data( characters.pool, "players_summary");
|
399
|
|
- triggerField( "wounds" );
|
400
|
|
- triggerField( "TN" );
|
401
|
|
- }
|
402
|
|
- </script>
|
403
|
|
- <style>
|
404
|
|
- .result{
|
405
|
|
- width : 3em;
|
406
|
|
- }
|
407
|
|
- </style>
|
408
|
|
- </head>
|
409
|
|
- <body onload="main()">
|
410
|
|
- <button onclick="popObjectMaker( Character )">Créer un Personnage</button>
|
411
|
|
- <table id="players_summary"></div>
|
412
|
|
- <div id="npc_summary"></div>
|
413
|
|
- </table>
|
414
|
|
- <button onclick="generateNPC()">Générer NPC</button><input id="npc-level" type="number" value="1"/><select id="npc-role"></select>
|
415
|
|
- <button onclick="popObjectMaker( Character, null, characters )">Générer Personnage</button>
|
416
|
|
- </body>
|
417
|
|
-</html>
|