-
Notifications
You must be signed in to change notification settings - Fork 77
/
weltmeister.html
5217 lines (4243 loc) · 122 KB
/
weltmeister.html
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
window.wm = {};
wm.config = {
project: {
// Where to load available entity files from
entityFiles: 'src/entities/',
// The default path for the level file selection box
levelPath: 'assets/levels/',
// Whether to pretty print the JSON data in level files. If you have
// any issues with your levels, it's usually a good idea to turn this
// on and look at the saved level files with a text editor.
prettyPrint: true,
defaultEntityColor: 'rgba(128, 255, 128, 0.9)'
},
// Default settings when creating new layers in Weltmeister. Change these
// as you like
layerDefaults: {
width: 30,
height: 20,
tilesize: 8
},
// Whether to ask before closing Weltmeister when there are unsaved changes
askBeforeClose: true,
// Whether to attempt to load the last opened level on startup
loadLastLevel: true,
// Size of the "snap" grid when moving entities
entityGrid: 4,
// Number of undo levels. You may want to increase this if you use 'undo'
// frequently.
undoLevels: 500,
// Mouse and Key bindings in Weltmeister. Some function are bound to
// several keys. See the documentation of ig.Input for a list of available
// key names.
binds: {
MOUSE1: 'draw',
MOUSE2: 'drag',
SHIFT: 'select',
CTRL: 'drag',
SPACE: 'menu',
DELETE: 'delete',
BACKSPACE: 'delete',
G: 'grid',
C: 'clone',
Z: 'undo',
Y: 'redo',
S: 'save',
MWHEEL_UP: 'zoomin',
PLUS: 'zoomin',
MWHEEL_DOWN: 'zoomout',
MINUS: 'zoomout'
},
// Whether to enable unidirectional scrolling for touchpads; this
// automatically unbinds the MWHEEL_UP and MWHEEL_DOWN actions.
touchScroll: false,
// View settings. You can change the default Zoom level and whether
// to show the grid on startup here.
view: {
zoom: 1,
zoomMax: 4,
zoomMin: 0.125,
grid: false
},
// Font face and size for entity labels and the grid coordinates
labels: {
draw: true,
step: 32,
font: '10px Bitstream Vera Sans Mono, Monaco, monospace, sans-serif'
},
// Colors to use for the background, selection boxes, text and the grid
colors: {
clear: '#000000', // Background Color
highlight: '#ceff36', // Currently selected tile or entity
primary: '#ffffff', // Labels and layer bounds
labelbg: 'rgba(0,0,0,0.5)', // Label background
secondary: '#555555', // Grid and tile selection bounds
selection: '#ff9933', // Selection cursor box on tile maps
// Colors for collision tileset
collision: {
primary: '#bf80ff',
secondary: '#7f00ff',
indicator: '#ffffff'
}
}
};
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Following is the somewhat condensed source code of the original
// editor from 2010 - a time when JS had no classes.
// There's a lot of things that are easier to do with modern JS, CSS
// and the DOM and a lot of things I would just do differently today.
// So beware, there's not much to learn here and no up-to-date best
// practices to be found.
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Weltmeister</title>
<style>
* {
box-sizing: border-box;
}
html {
margin: 0;
padding: 0;
}
body {
background-color: #555;
color: #fff;
font-family: sans-serif;
font-size: 14px;
margin: 0px;
overflow: hidden;
text-shadow: 0px 1px 1px rgba(0,0,0,0.5);
user-select: none;
}
h2 {
margin: 0 0 4px 0;
padding: 4px 0 4px 6px;
background-color: #000;
font-size: 100%;
color: #555;
}
h3 {
margin: 0;
font-size: 100%;
display: block;
}
dt {
margin: 0;
padding: 4px 0 0 6px;
display:inline;
float:left;
margin-right:5px;
}
dd {
margin: 0;
padding: 2px 0 8px 6px;
}
dl {
margin:0;
}
div.clear {
clear: both;
}
a {
color: #fff;
text-decoration: underline;
}
/* --- Input ------------------------------------------------------------------ */
input {
background-color: rgba(32,32,32,0.5);
border: 1px solid rgb(50,50,50);
color: #fff;
margin: 0;
font-family: sans-serif;
font-size: 10pt;
outline: none;
}
input:focus{
border: 1px solid rgb(200,200,200);
}
input.text {
padding: 4px 4px;
margin: 0px 4;
width: 100%;
}
input.number {
padding: 4px 4px;
margin: 0px 4;
width: 40px;
text-align: right;
}
input.button, button {
font-size: 90%;
padding-left: 13px;
padding-right: 13px;
padding-top: 5px;
padding-bottom: 5px;
color: #bbb;
font-weight: bold;
background-color: #222;
border:none;
cursor: pointer;
}
input.button:hover, button:hover {
background-color: #fafafa;
color: #555;
}
input.button:active, button:active {
background-color: #fff;
}
input.text#layerName {
width:140px;
}
input.text#layerTileset {
width:138px;
}
input#levelSaveAs { margin-right: 10px; }
input#levelLoad { margin-right: 10px; }
input:disabled {
background-color: #555;
color: #888;
}
/* --- Layout ------------------------------------------------------------------ */
#editor {
margin: 0px;
position: relative;
}
#canvas {
image-rendering: optimizeSpeed;
-webkit-interpolation-mode: nearest-neighbor;
}
#menu {
width: 200px;
float: right;
position:absolute;
top:0px;
right:0px;
}
/* --- Layers ------------------------------------------------------------------ */
#layerContainer {
background-color: rgba(0,0,0,0.95);
padding-right:2px;
}
#layers {
max-height: 200px;
overflow: auto;
}
#layerButtons div.button#buttonAddLayer {
position:absolute;
right: 0px;
top:-5px;
cursor: pointer;
padding: 10px;
color:rgba(255,255,255,0.5);
font-weight: bold;
font-size:110%;
margin-left:1px;
z-index:10;
}
#layerButtons div.button#buttonAddLayer:hover { color:rgba(255,255,255,1);}
#layerButtons div.button#buttonAddLayer:active { color:rgba(255,255,255,1);}
.layer {
padding: 6px 4px;
cursor: pointer;
border-top: 1px solid rgba(255,255,255,0);
border-bottom: 1px solid rgba(255,255,255,0);
position: relative;
}
.layer:hover {
background-color: rgba(255,255,255,0.1);
border-top: 1px solid rgba(255,255,255,0.1);
border-bottom: 1px solid rgba(255,255,255,0.1);
}
.layerActive, .layer.layerActive:hover {
background-color: rgba(255,255,255,0.2);
border-top: 1px solid rgba(255,255,255,0.2);
border-bottom: 1px solid rgba(255,255,255,0.2) !important;
}
#layerEntities { border-bottom: 1px solid #000; }
.layer .visible {
background-color: rgba(255,255,255,0.2);
text-indent: -99999px;
display: inline-block;
width: 10px;
height: 10px;
margin-right: 7px;
margin-left: 4px;
}
.layer .visible.specialVis{
margin-right: 2px;
}
.layer .checkedVis{ background-color: rgba(255,255,255,1); }
.layer span.size { font-size: 75%; color: rgba(255,255,255,0.7); }
#layerSettings {
background-color: rgba(0,0,0,0.95);
padding-top: 5px;
margin-top: 1px;
display: none;
}
.layerMove {
position: absolute;
top: 3px;
right: 0;
bottom: 3px;
width: 18px;
cursor: move;
background-image: radial-gradient(#777 1px, transparent 0);
background-size: 8px 8px;
}
.layerMove:hover {
background-image: radial-gradient(#ccc 1px, transparent 0);
}
/* --- Entities ------------------------------------------------------------------ */
h3#entityClass {
border-bottom: 1px solid rgba(255,255,255,0.2);
padding: 5px;
padding-left: 10px;
}
#entitySettings {
background-color: rgba(0,0,0,0.95);
margin-top: 1px;
display: none;
}
#entityDefinitions {
max-height: 220px;
overflow: auto;
}
div.entityDefinition {
color: #aaa;
padding: 2px 0;
border-bottom: 1px solid rgba(255,255,255,0.2);
cursor: pointer;
}
div.entityDefinition:hover {
background-color: rgba(255,255,255,0.1);
}
div.entityDefinition .key {
width: 50%;
display: block;
float: left;
margin: 0 0px 0 0;
padding: 0 0 0 8px;
text-align: left;
color: #fff;
overflow: hidden;
}
div.entityDefinition .value {
padding: 0 0 0 2px;
color: #fff;
}
dl#entityDefinitionInput {
padding: 8px 4px;
}
dl#entityDefinitionInput dd {
display: block;
margin: 0;
padding: 2px 0;
}
dl#entityDefinitionInput input {
width: 100%;
}
div.row {
display: flex;
padding: 4px;
align-items: center;
gap: 4px;
}
div.group {
margin-top: 8px;
}
#entityKey, #entityValue {
}
#entityMenu {
background-color: rgba(0,0,0,0.9);
display: none;
position: absolute;
min-width: 100px;
max-height:300px;
overflow-y: scroll;
z-index: 1000;
}
#entityMenu div {
padding: 3px;
padding-left: 8px;
color: #fff;
cursor: pointer;
border-top: 1px solid rgba(255,255,255,0);
border-bottom: 1px solid rgba(255,255,255,0);
}
#entityMenu div:hover {
background-color: rgba(255,255,255,0.2);
border-top: 1px solid rgba(255,255,255,0.2);
border-bottom: 1px solid rgba(255,255,255,0.2);
}
/* --- Dialogs ------------------------------------------------------------------ */
.selectFileDialogWrap {
position: relative;
}
.selectFileDialog {
background-color: rgba(0,0,0,0.9);
border: 1px solid white;
border-top: 1px solid rgba(255,255,255,0.4);
display: none;
position: absolute;
overflow: hidden;
max-height: 300px;
overflow-y: scroll;
}
.selectFileDialog span {
padding: 4px;
color: #fff;
display: block;
text-decoration: none;
border-top: 1px solid rgba(255,255,255,0);
border-bottom: 1px solid rgba(255,255,255,0);
}
.selectFileDialog span:hover {
background-color: rgba(255,255,255,0.2);
border-top: 1px solid rgba(255,255,255,0.2);
border-bottom: 1px solid rgba(255,255,255,0.2);
}
div.modalDialogBackground {
background-color: rgba(0,0,0,0.7);
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
display: none;
z-index: 100;
}
div.modalDialogBox {
width: 300px;
margin-left: -170px;
background-color: rgba(0,0,0,0.9);
border: 1px solid rgb(100,100,100);
position: absolute;
top: 20%;
left: 50%;
padding: 20px;
}
div.modalDialogText {
font-size: 180%;
font-weight: bold;
}
div.modalDialogButtons {
margin-top: 20px;
text-align: right;
}
div.modalDialogButtons input.button {
min-width: 100px;
text-align: center;
margin-left: 10px;
}
input.modalDialogPath {
margin-top: 20px;
width: 100%;
outline: none;
}
input.modalDialogPath:focus {
outline: none;
border: 1px solid rgb(100,100,100);
}
#headerMenu {
position:relative;
z-index:10;
height:40px;
width:100%;
background: #111;
padding: 8px;
}
#headerMenu span.headerTitle {
display:inline-block;
font-weight:normal;
font-size:140%;
padding-left:20px;
color: #bbb;
}
#headerMenu span.unsavedTitle {
display:inline-block;
font-weight:normal;
font-size:140%;
padding-left:0px;
color:#cc0000;
}
#headerMenu span.headerFloat {
float: right;
}
#headerMenu span.headerFloat button {
margin-left: 8px;
}
.fullscreenOverlay {
background-color: rgba(0, 0, 0, 0.7);
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 50;
}
.fullscreenBox {
position: absolute;
top: 10vh;
left: 0;
right: 0;
margin: auto;
width: 60vw;
max-width: 500px;
background: #111;
color: #eee;
padding: 16px;
font-size: 16px;
}
.fullscreenOverlay button {
width: 100%;
color: #fff;
background-color: #555;
padding: 12px;
}
.fullscreenOverlay button:hover {
background-color: #fff;
color: #000;
}
.fullscreenOverlay code {
font-weight: bold;
}
#helpScreenOverlay {
display: none;
}
div#zoomIndicator {
font-weight: bold;
font-size: 300%;
position: absolute;
left: 50px;
top: 30px;
color: #fff;
display: none;
}
button#toggleSidebar {
width: 186px;
opacity: 0.5;
}
button#toggleSidebar.active{
opacity: 1;
}
input[type="checkbox"] {
position: relative;
margin: 0 4px 0 0;
border: 0;
width: 14px;
height: 14px;
display: inline-block;
appearance: none;
}
input[type="checkbox"] {
background-color:rgba(255,255,255,0.2);
}
input[type="checkbox"]:checked {
background-color: rgba(255,255,255,1);
}
input[type="checkbox"]:hover {
cursor: pointer;
}
input[type="checkbox"]:disabled {
background-color: rgba(255,255,255,0.1);
}
</style>
</head>
<body>
<div id="headerMenu">
<span class="headerTitle"></span>
<span class="unsavedTitle"></span>
<span class="headerFloat">
<button id="help">Help</button>
<button id="openProject">Switch Project</button>
<button id="levelSave" title="ctrl+s">Save</button>
<button id="levelSaveAs" title="ctrl+shift+s">Save As</button>
<button id="levelNew">New</button>
<button id="levelLoad">Load</button>
<button id="toggleSidebar" class="active">Layers ☰</button>
</span>
</div>
<div id="editor">
<div id="entityMenu"></div>
<canvas id="canvas"></canvas>
<div id="menu">
<div id="layerContainer">
<h2> </h2>
<div id="layerButtons">
<div class="button" id="buttonAddLayer" title="Add Layer">+</div>
</div>
<div id="layers">
<div id="layerEntities" class="layer">
<span class="visible specialVis checkedVis" title="Toggle Visibility (Shift+0)"></span>
<span class="name">entities</span>
<span class="layerMove" title="Move layer"></span>
</div>
</div>
</div>
<div id="layerSettings">
<h2>Layer Settings</h2>
<div class="row">
<label>Name:</label>
<input type="text" class="text" id="layerName"/>
</div>
<div class="row">
<label>Tileset:</label>
<div><input type="text" class="text" id="layerTileset"/></div>
</div>
<div class="row">
<label>Tilesize:</label>
<input type="text" class="number" id="layerTilesize"/>
</div>
<div class="row">
<label>Dimensions:</label>
<div>
<input type="text" class="number" id="layerWidth"/> × <input type="text" class="number" id="layerHeight"/>
</div>
</div>
<div class="row">
<label>Distance:</label>
<input type="text" class="number" id="layerDistance"/>
</div>
<div class="group">
<div class="row">
<input type="checkbox" id="layerIsCollision"/>
<label for="layerIsCollision">Is Collision Layer</label>
</div>
<div class="row">
<input type="checkbox" id="layerRepeat"/>
<label for="layerRepeat">Repeat</label>
</div>
<div class="row">
<input type="checkbox" id="layerLinkWithCollision"/>
<label for="layerLinkWithCollision">Link with Collision</label>
</div>
</div>
<div class="group">
<div class="row">
<button id="buttonSaveLayerSettings">Apply Changes</button>
<button id="buttonRemoveLayer">Delete</button>
</div>
</div>
</div>
<div id="entitySettings">
<h2>Entity Settings</h2>
<h3 id="entityClass">EntityClassName</h3>
<div id="entityDefinitions">
<div class="entityDefinition"><span class="key">x</span><span class="value">188</span></div>
<div class="entityDefinition"><span class="key">y</span><span class="value">269</span></div>
</div>
<dl id="entityDefinitionInput">
<dd><input type="text" class="text" id="entityKey" placeholder="key" /></dd>
<dd><input type="text" class="text" id="entityValue" placeholder="value"/></dd>
</dl>
<dd>
<button id="buttonEntityDefinition">Set</button>
</dd>
</div>
</div>
<div id="zoomIndicator">1x</div>
<div class="fullscreenOverlay" id="welcomeScreenOverlay">
<div class="fullscreenBox">
<h1>Weltmeister</h1>
<p>
Begin by picking your project directory – The directory containing
the Makefile.
</p>
<p>
This enables Weltmeister to look through
<code>src/entities/*.c</code> in this directory to find available
entity types and load and save levels.
</p>
<button id="openInitialProject">Pick Project Directory</button>
</div>
</div>
<div class="fullscreenOverlay" id="helpScreenOverlay">
<div class="fullscreenBox">
<h1>Quick Reference</h1>
<p>
<div><code>space</code>: open tileset selection or entity selection menu</div>
<div><code>left mouse button</code>: draw selected tiles or select entity</div>
<div><code>shift</code>: hold to select an area of tiles on the map (also works in the tile-selection menu)</div>
<div><code>right mouse button</code>: drag view</div>
<div><code>backspace</code>: delete selected entity</div>
<div><code>mouse wheel</code>: zoom in/out</div>
<div><code>+</code>: zoom in</div>
<div><code>-</code>: zoom out</div>
<div><code>s</code>: quick save</div>
<div><code>g</code>: toggle grid</div>
<div><code>c</code>: clone selected entity</div>
<div><code>z</code>: undo</div>
<div><code>y</code>: redo</div>
</p>
<p>
These key bindings can be changed in the first few lines of weltmeister.html.
</p>
<p>
Entities can be connected by giving one entity a <code>name</code> and
another entity a <code>target.1</code> with this name.
</p>
<p>
Some more documentation is available on
<a href="https://impactjs.com/documentation/weltmeister" target="_blank">impactjs.com</a> –
this is for the original JavaScript game engine, but many things are the same here.
</p>
<button id="closeHelp">Close</button>
</div>
</div>
</div>
<script type="text/javascript">
(function(window){ "use strict";
// -----------------------------------------------------------------------------
// ig Namespace
window.ig = {
game: null,
debug: null,
version: '1.24',
global: window,
ready: false,
baked: false,
nocache: '',
ua: {},
prefix: (window.ImpactPrefix || ''),
lib: 'lib/',
_current: null,
_loadQueue: [],
_waitForOnload: 0,
clamp: function(v, min, max) {
return Math.min(max, Math.max(min, v));
},
arrayRemove: function(a, v) {
for (var i = a.length; i--;) {
if (a[i] === v) {
a.splice(i, 1);
}
}
return a;
},
copy: function( object ) {
if(
!object || typeof(object) != 'object' ||
object instanceof HTMLElement ||
object instanceof ig.Class
) {
return object;
}
else if( object instanceof Array ) {
var c = [];
for( var i = 0, l = object.length; i < l; i++) {
c[i] = ig.copy(object[i]);
}
return c;
}
else {
var c = {};
for( var i in object ) {
c[i] = ig.copy(object[i]);
}
return c;
}
},
merge: function( original, extended ) {
for( var key in extended ) {
var ext = extended[key];
if(
typeof(ext) != 'object' ||
ext instanceof HTMLElement ||
ext instanceof ig.Class ||
ext === null
) {
original[key] = ext;
}
else {
if( !original[key] || typeof(original[key]) != 'object' ) {
original[key] = (ext instanceof Array) ? [] : {};
}
ig.merge( original[key], ext );
}
}
return original;
},
ksort: function( obj ) {
if( !obj || typeof(obj) != 'object' ) {
return [];
}
var keys = [], values = [];
for( var i in obj ) {
keys.push(i);
}
keys.sort();
for( var i = 0; i < keys.length; i++ ) {
values.push( obj[keys[i]] );
}
return values;
},
// Ah, yes. I love vendor prefixes. So much fun!
setVendorAttribute: function( el, attr, val ) {
var uc = attr.charAt(0).toUpperCase() + attr.substr(1);
el[attr] = el['ms'+uc] = el['moz'+uc] = el['webkit'+uc] = el['o'+uc] = val;
},
getVendorAttribute: function( el, attr ) {
var uc = attr.charAt(0).toUpperCase() + attr.substr(1);
return el[attr] || el['ms'+uc] || el['moz'+uc] || el['webkit'+uc] || el['o'+uc];
},
normalizeVendorAttribute: function( el, attr ) {
var prefixedVal = ig.getVendorAttribute( el, attr );
if( !el[attr] && prefixedVal ) {
el[attr] = prefixedVal;
}
},
// Stubs for ig.Debug
log: function() {},
assert: function( condition, msg ) {},
show: function( name, number ) {},
mark: function( msg, color ) {},
_boot: function() {
// Probe user agent string
ig.ua.pixelRatio = window.devicePixelRatio || 1;
ig.ua.viewport = {
width: window.innerWidth,
height: window.innerHeight
};
ig.ua.screen = {
width: window.screen.availWidth * ig.ua.pixelRatio,
height: window.screen.availHeight * ig.ua.pixelRatio
};
ig.ua.iPhone = /iPhone|iPod/i.test(navigator.userAgent);
ig.ua.iPhone4 = (ig.ua.iPhone && ig.ua.pixelRatio == 2);
ig.ua.iPad = /iPad/i.test(navigator.userAgent);
ig.ua.android = /android/i.test(navigator.userAgent);
ig.ua.winPhone = /Windows Phone/i.test(navigator.userAgent);
ig.ua.iOS = ig.ua.iPhone || ig.ua.iPad;
ig.ua.mobile = ig.ua.iOS || ig.ua.android || ig.ua.winPhone || /mobile/i.test(navigator.userAgent);
ig.ua.touchDevice = (('ontouchstart' in window) || (window.navigator.msMaxTouchPoints));
}
};
// Json pretty print
(function(window) {
var p = [],
push = function( m ) { return '\\' + p.push( m ) + '\\'; },
pop = function( m, i ) { return p[i-1] },
tabs = function( count ) { return new Array( count + 1 ).join( '\t' ); };
ig.jsonPrettyPrint = function( json ) {
p = [];
var out = "",
indent = 0;
// Extract backslashes and strings
json = json
.replace( /\\./g, push )
.replace( /(".*?"|'.*?')/g, push )
.replace( /\s+/, '' );
// Indent and insert newlines
for( var i = 0; i < json.length; i++ ) {
var c = json.charAt(i);
switch(c) {
case '{':
case '[':
out += c + "\n" + tabs(++indent);
break;