-
Notifications
You must be signed in to change notification settings - Fork 0
/
diydudley.js
3835 lines (3366 loc) · 108 KB
/
diydudley.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
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
function parse_text_tags(txt)
{
var matches = txt.split(/\\nocode\\/);
if (matches.length == 3) {
return parse_text_tags(matches[0]) + matches[1] + parse_text_tags(matches[2]);
}
do {
var p_t_t_d = 0;
txt = txt.replace(/\\i{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<i>'+grp+'</i>'; });
txt = txt.replace(/\\u{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<u>'+grp+'</u>'; });
txt = txt.replace(/\\b{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<b>'+grp+'</b>'; });
txt = txt.replace(/\\tt{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<tt>'+grp+'</tt>'; });
txt = txt.replace(/\\sup{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<sup>'+grp+'</sup>'; });
txt = txt.replace(/\\sub{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<sub>'+grp+'</sub>'; });
txt = txt.replace(/\\small{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<small>'+grp+'</small>'; });
txt = txt.replace(/\\sc{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<span class="smallcaps">'+grp+'</span>'; });
txt = txt.replace(/\\left{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<div class="left_text">'+grp+'</div>'; });
txt = txt.replace(/\\right{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<div class="right_text">'+grp+'</div>'; });
txt = txt.replace(/\\dead{([^}]+)}/, function (str, grp) { p_t_t_d = 1; return '<span class="f_gray">'+grp+'</span>'; });
txt = txt.replace(/\\br/, function (str) { p_t_t_d = 1; return '<br>'; });
txt = txt.replace(/\\mdash/, function (str) { p_t_t_d = 1; return '—'; });
txt = txt.replace(/\\gt/, function (str) { p_t_t_d = 1; return '>'; });
txt = txt.replace(/\\lt/, function (str) { p_t_t_d = 1; return '<'; });
txt = txt.replace(/\\amp/, function (str) { p_t_t_d = 1; return '&'; });
txt = txt.replace(/\\ent\((entity=)?"([^"]+)"\)/, function (str, grp2, grp3) { p_t_t_d = 1; return '&' + grp3 + ';'; });
txt = txt.replace(/\\comic\("?([^"]+)"?\){([^}]+)}/, function (str, grp2, grp3) { p_t_t_d = 1; return '<a href="index.php?f=' + grp2 + '">' + grp3 + '</a>'; });
txt = txt.replace(/\\link\("?([^"]+)"?\) *{([^}]+)}/, function (str, grp2, grp3) { p_t_t_d = 1; return '<a href="http://' + grp2 + '">' + grp3 + '</a>'; });
txt = txt.replace(/\\mail\("?([^"]+)"?\) *{([^}]+)}/, function (str, grp2, grp3) { p_t_t_d = 1; return '<a href="mailto:' + grp2 + '">' + grp3 + '</a>'; });
txt = txt.replace(/\\mail\("?([^"]+)"?\)/, function (str, grp2) { p_t_t_d = 1; return '<a href="mailto:' + grp2 + '">' + grp2 + '</a>'; });
txt = txt.replace(/\\color\("?([^"]+)"?\) *{([^}]+)}/, function (str, grp2, grp3) { p_t_t_d = 1; return '<span style="color:' + grp2 + '">' + grp3 + '</span>'; });
} while (p_t_t_d);
return txt;
}
function popup_save_position(elem, x, y)
{
var vis = ((elem.style.display != "none" && elem.style.visibility != "hidden") ? 1 : 0);
createCookie(elem.id, x+","+y+","+vis, 30);
}
function popup_isvisible(id)
{
var elem = $(id + "_widget");
if (!elem) return false;
if (elem.style.display == "none" || elem.style.visibility == "hidden") return false;
return true;
}
function popup_create(id, title, contents, hidden)
{
var elem = $(id + "_widget");
if (!elem) {
var txt = "";
txt += "<dt class='widget_title widget_draggable_handle'>" + title + "<span class='widget_close' onclick='popup_hide(\""+id+"\");'>X</span></dt>";
txt += "<div class='widget_contents' id='" + id + "_widget_contents'>";
txt += contents;
txt += "</div>";
var nod = document.createElement('dl');
nod.setAttribute('id', id + '_widget');
nod.setAttribute('class', 'widget');
nod.innerHTML = txt;
document.body.appendChild(nod);
if (hidden == undefined) hidden = 0;
if (hidden == 1) nod.style.visibility = 'hidden';
nod.style.display = "block";
var lft;
var top;
var oldpos = readCookie(id + '_widget');
if (oldpos != undefined && oldpos.match(/^\d+,\d+,[01]$/)) {
var tmp = oldpos.split(",");
lft = parseInt(tmp[0]);
top = parseInt(tmp[1]);
if (parseInt(tmp[2]) == 0) { hidden = 1; } else { hidden = 0; }
} else {
lft = (dudley_mouse_pos_x - Math.floor(nod.offsetWidth / 2));
top = (dudley_mouse_pos_y - Math.floor(nod.offsetHeight / 2));
}
if (lft < 0) lft = 0;
if (top < 0) top = 0;
nod.style.left = lft + 'px';
nod.style.top = top + 'px';
if (hidden == 1) {
nod.style.display = 'none';
} else {
nod.style.visibility = 'visible';
}
var drg = DragHandler.attach(nod);
drg.dragEnd = popup_save_position;
} else {
popup_set_contents(id, contents);
}
}
function popup_show(id, toggle)
{
var elem = $(id + "_widget");
if (!elem) return;
if (toggle != undefined) {
elem.style.display = (toggle == 0) ? "block" : "none";
} else {
elem.style.display = (elem.style.display == "block") ? "none" : "block";
}
elem.style.visibility = 'visible';
popup_save_position(elem, parseInt(elem.style.left), parseInt(elem.style.top));
}
function popup_hide(id)
{
var elem = $(id + "_widget");
if (!elem) return;
elem.style.display = "none";
popup_save_position(elem, parseInt(elem.style.left), parseInt(elem.style.top));
}
function popup_set_contents(id, contents)
{
var elem = $(id + "_widget_contents");
if (!elem) return;
elem.innerHTML = contents;
}
var widget_popups = new Array(
{'title':'Game Symbols', 'id':'gamesyms', 'getcontents':get_nethacksym_selection_contents},
{'title':'Pen Selection', 'id':'penchars', 'getcontents':get_pen_selection_popup_contents},
{'title':'Extended Chars', 'id':'extchars', 'getcontents':get_extended_char_popup_contents},
{'title':'Boxes', 'id':'boxchars', 'getcontents':get_box_char_popup_contents}
);
function create_widgets()
{
var i;
for (i = 0; i < widget_popups.length; i++) {
var wp = widget_popups[i];
popup_create(wp.id, wp.title, wp.getcontents(), 1);
}
}
function show_widget(num, close)
{
if (close == 1) {
popup_show(widget_popups[num].id, 1);
} else {
popup_show(widget_popups[num].id);
}
}
function isvisible_widget(num)
{
return popup_isvisible(widget_popups[num].id);
}
function widget_set_contents(num, txt)
{
popup_set_contents(widget_popups[num].id, txt);
}
function pen_clone(pen)
{
return {'chr':pen.chr, 'fg':pen.fg, 'bold':pen.bold, 'rev':pen.rev, 'ul':pen.ul, 'ita':pen.ita};
}
function pen_clone_nornd(pen)
{
return {'chr':pen.chr, 'fg':pen_getcolor(pen.fg), 'bold':pen.bold, 'rev':pen.rev, 'ul':pen.ul, 'ita':pen.ita};
}
function pen_toggle_color_brightness(pen)
{
if (pen.fg == undefined) {
pen.fg = 'gray';
} else pen.fg = pen_getcolor(pen.fg);
for (var i = 0; i < colors.length; i++)
if (colors[i] == pen.fg) {
pen.fg = colors[(i + 8) % 16];
return pen;
}
return pen;
}
function pen_equal(pen1, pen2)
{
return ((pen1.chr == pen2.chr) && (pen1.fg == pen2.fg) && (pen1.bold == pen2.bold) && (pen1.rev == pen2.rev) && (pen1.ul == pen2.ul) && (pen1.ita == pen2.ita));
}
function pen_htmlchr(pen)
{
var chr = pen.chr;
if (!chr) chr = '.';
else if (chr == '<') chr = '<';
else if (chr == '>') chr = '>';
else if (chr == '&') chr = '&';
else if (chr == '~') chr = '˜';
else if (chr < ' ' || chr > '~') return chr;
return chr;
}
function pen_insert()
{
var fg = pen_getcolor(pen.fg);
if ((fg == undefined || fg == "white" || fg == "black" || pen.chr == ' ') && (pen.rev != 1)) {
str = pen.chr;
} else {
str = '<span class="'+datspanclass(pen)+'">'+pen.chr+'</span>';
}
insertAtCursor('editpanel_text', str);
set_panel_text();
}
function pen_has_changed()
{
show_current_pen();
color_selection();
char_selection();
update_pen_selection_popup();
update_extended_char_popup();
pens_save();
}
function pen_swap_ctrl()
{
var tmp = pen;
pen = ctrl_pen;
ctrl_pen = tmp;
pen_has_changed();
}
function pens_save()
{
createCookie("current_pen", pen_to_string(pen), 30);
createCookie("current_ctrl_pen", pen_to_string(ctrl_pen), 30);
}
function pens_load()
{
var str = readCookie('current_pen');
if (!(str == undefined || str == null)) {
var tmpen = string_to_pen(str);
if (tmpen != undefined) { pen = tmpen; }
}
str = readCookie('current_ctrl_pen');
if (!(str == undefined || str == null)) {
var tmpen = string_to_pen(str);
if (tmpen != undefined) { ctrl_pen = tmpen; }
}
}
function getkeyb_handler_string(elem)
{
if (typeof(elem) == 'undefined') {
return " onfocus='document.onkeyup=null' onblur='document.onkeyup=handle_keyb' ";
} else {
elem.onFocus='document.onkeyup=null';
elem.onBlur='document.onkeyup=handle_keyb';
}
}
function bindable_key_get()
{
if (keybinding_keys.length > 0) {
var chr = keybinding_keys.substr(0,1);
keybinding_keys = keybinding_keys.substr(1);
return chr;
} else return undefined;
}
function bindable_key_remove(key)
{
var idx = keybinding_keys.indexOf(key);
if (idx >= 0) {
keybinding_keys = keybinding_keys.substr(0, idx) + keybinding_keys.substr(idx+1);
}
}
function bindable_key_release(key)
{
var x = key.charCodeAt(0);
var i;
for (i = 0; i < keybinding_keys.length; i++) {
var ch = keybinding_keys.substr(i,0);
if (ch.charCodeAt(0) < x) {
keybinding_keys = keybinding_keys.substr(0, i) + key + keybinding_keys.substr(i);
}
}
}
function bindable_key_isfree(key)
{
var idx = keybinding_keys.indexOf(key);
if (idx >= 0) return true;
return false;
}
function panel_write_character(ch, spen)
{
var sym = {};
if (spen != undefined) sym = pen_clone(spen);
sym.chr = ch;
editpaneldata.set_data(cursor_x, cursor_y, sym);
cursor_x++;
if (cursor_x >= editpaneldata.WID) {
cursor_x = 0;
cursor_y++;
if (cursor_y >= editpaneldata.HEI) {
cursor_y = 0;
}
}
}
function panel_write_string(str,tmppen)
{
for (i = 0; i < str.length; i++) panel_write_character(str.substr(i,1), tmppen);
}
function panel_draw_gravestone()
{
var grass = "/\\()|";
var stone = [" ------------ ",
" / REST IN \\ ",
" / PEACE \\ ",
"/ \\",
"| Dudley |",
"| |",
"| |",
"| |"];
var engraving_ypos = 5;
var engraving_linelen = 14;
var engraving_maxlines = 3;
var oldx = cursor_x;
var oldy = cursor_y;
var txt = "";
var deathreasons = new Array(
"choked on a very rich meal",
"committed suicide",
"died of exhaustion",
"died of starvation",
"dissolved in molten lava",
"dragged downstairs by an iron ball",
"drowned in a moat",
"drowned in a pool of water",
"escaped (in celestial disgrace)",
"fell into a chasm",
"fell into a pit",
"fell into a pit of iron spikes",
"fell onto a sink",
"killed by a blast of acid",
"killed by a blast of disintegration",
"killed by a blast of fire",
"killed by a blast of frost",
"killed by a blast of lightning",
"killed by a blast of missiles",
"killed by a boiling potion",
"killed by a bolt of cold",
"killed by a bolt of fire",
"killed by a bolt of lightning",
"killed by a boomerang",
"killed by a boulder",
"killed by a burning book",
"killed by a burning potion of oil",
"killed by a burning scroll",
"killed by a cadaver",
"killed by a cursed throne",
"killed by a dagger",
"killed by a dart",
"killed by a death ray",
"killed by a falling object",
"killed by a falling rock",
"killed by a knight called Perseus",
"killed by a land mine",
"killed by a magic missile",
"killed by a magical explosion",
"killed by a mildly contaminated potion",
"killed by a poison dart",
"killed by a poisoned blast",
"killed by a poisoned needle",
"killed by a poisonous corpse",
"killed by a potion of acid",
"killed by a potion of holy water",
"killed by a potion of unholy water",
"killed by a riding accident",
"killed by a scroll of earth",
"killed by a scroll of fire",
"killed by a scroll of genocide",
"killed by a shattered potion",
"killed by a system shock",
"killed by a touch of death",
"killed by a tower of flame",
"killed by a wand",
"killed by a war hammer named Mjollnir",
"killed by an alchemic blast",
"killed by an exploding chest",
"killed by an exploding crystal ball",
"killed by an exploding large box",
"killed by an exploding ring",
"killed by an exploding rune",
"killed by an exploding wand",
"killed by an explosion",
"killed by an unrefrigerated sip of juice",
"killed by an unsuccessful polymorph",
"killed by axing a hard object",
"killed by boiling potions",
"killed by boiling water",
"killed by brainlessness",
"killed by bumping into a boulder",
"killed by bumping into a door",
"killed by bumping into a tree",
"killed by bumping into a wall",
"killed by burning scrolls",
"killed by colliding with the ceiling",
"killed by contaminated tap water",
"killed by contaminated water",
"killed by crashing into iron bars",
"killed by dangerous winds",
"killed by elementary chemistry",
"killed by exhaustion",
"killed by falling downstairs",
"killed by his own axe",
"killed by his own battle-axe",
"killed by his own dwarvish mattock",
"killed by his own pick-axe",
"killed by kicking the stairs",
"killed by sipping boiling water",
"killed by sitting in lava",
"killed by sitting on an iron spike",
"killed by sitting on lava",
"killed by strangulation",
"killed by wedging into a narrow crevice",
"killed himself by breaking a wand",
"killed himself with his bullwhip",
"killed while stuck in creature form",
"molten lava",
"petrified by a chickatrice",
"petrified by a chickatrice corpse",
"petrified by a cockatrice",
"petrified by a cockatrice corpse",
"petrified by a cockatrice egg",
"petrified by elementary physics",
"petrified by genocidal confusion",
"petrified by tasting chickatrice meat",
"petrified by tasting cockatrice meat",
"poisoned by a fall onto poison spikes",
"poisoned by a poison dart",
"poisoned by a poisoned blast",
"poisoned by a poisoned needle",
"slipped while mounting a saddled horse",
"squished under a boulder",
"turned into green slime",
"went to heaven prematurely"
);
editpaneldata.save_undopoint();
editpaneldata.fill({'chr':' ', 'fg':"gray"});
editpaneldata.set_cursor(-1, -1);
cursor_x = 0;
cursor_y = 0;
for (z = 0; z < stone.length; z++) {
var s = stone[stone.length - z - 1];
if (s.length < editpaneldata.WID)
cursor_x = Math.floor((editpaneldata.WID/2 - s.length/2));
else
cursor_x = 0;
cursor_y = (editpaneldata.HEI - z) - 2;
if (s != undefined)
panel_write_string(s);
}
var engraving_ok = 1;
var engrarr = undefined;
var cnt = 0;
var wrappedengr;
do {
var engravetxt = deathreasons[Math.floor(Math.random() * deathreasons.length)];
wrappedengr = wordwrap(engravetxt, engraving_linelen);
engrarr = wrappedengr.split("\n");
if (engrarr.length > engraving_maxlines) {
engraving_ok = 0;
} else {
for (var i = 0; i < engrarr.length; i++)
if (engrarr[i].length > engraving_linelen) {
engraving_ok = 0;
break;
}
}
cnt++;
} while ((engraving_ok == 0) && (cnt < 10));
for (i = 0; i < engrarr.length; i++) {
var txt = engrarr[i].trim();
cursor_y = editpaneldata.HEI - stone.length + engraving_ypos + i - 1;
cursor_x = Math.floor((editpaneldata.WID/2 - txt.length/2));
panel_write_string(txt);
}
var tmp = "";
for (i = 0; i < editpaneldata.WID; i++)
tmp += grass.substr(Math.floor(Math.random() * grass.length), 1);
cursor_x = 0;
cursor_y = editpaneldata.HEI - 1;
panel_write_string(tmp, {'fg':'green'});
cursor_x = oldx;
cursor_y = oldy;
editpaneldata.check_undopoint();
}
function random_trap_sym()
{
var fg = colors[Math.floor(Math.random() * (colors.length-1)) + 1];
return {'chr':'^', 'fg':fg};
}
function random_obj_sym()
{
var fg = colors[Math.floor(Math.random() * (colors.length-1)) + 1];
var chr = nh_object_chars.substr(Math.floor(Math.random() * nh_object_chars.length), 1);
if (chr == '?') fg = "white";
if (chr == '$') fg = "yellow";
if (chr == '"') fg = "cyan";
if ((chr == ')') && (Math.random() < .9)) fg = (Math.random() < 0.5) ? "cyan" : "brown";
if ((chr == '[') && (Math.random() < .9)) fg = (Math.random() < 0.5) ? "cyan" : "brown";
return {'chr':chr, 'fg':fg};
}
function random_terrain_sym()
{
var tmp = Math.floor(Math.random() * 4);
var sym;
switch (tmp) {
default:
case 0: sym = {'chr':"}",'fg':'blue'}; break; /* water */
case 1: sym = {'chr':"}",'fg':'red'}; break; /* lava */
case 2: sym = {'chr':"#",'fg':'green'}; break; /* tree */
}
return sym;
}
function random_nethack_monster_sym()
{
do {
i = Math.floor(Math.random() * game_symbols_orig.length);
var s = game_symbols_orig[i];
} while (s.sort != 1);
var tmp = $("nethacksymselboxid");
if (tmp) {
tmp.selectedIndex = game_symbols_orig[i].nhsymselectbox_idx;
}
return {'chr':s.chr, 'fg':s.fg};
}
function random_monster_sym()
{
var fg = colors[Math.floor(Math.random() * (colors.length-1)) + 1];
var chr = nh_monster_chars.substr(Math.floor(Math.random() * nh_monster_chars.length), 1);
return {'chr':chr, 'fg':fg};
}
function get_random_shop_sym(shoptype)
{
var rnd = Math.random();
switch (shoptype) {
case '?': if (rnd < 0.1) return {'chr':'+', 'fg':pen_getcolor('random')};
return {'chr':'?', 'fg':'white'};
case '+': if (rnd < 0.9) return {'chr':'+', 'fg':pen_getcolor('random')};
return {'chr':'?', 'fg':'white'};
case '=': if (rnd < 0.85) return {'chr':'=', 'fg':pen_getcolor('random')};
if (rnd < 0.95) return {'chr':'*', 'fg':pen_getcolor('random')};
return {'chr':'"', 'fg':'cyan'};
case '%':
var foodcolors = new Array('brown','brown','brown','brown','cyan','brightgreen','orange','red','white','yellow','yellow','green','green');
if (rnd < 0.83) return {'chr':'%', 'fg':foodcolors[Math.floor(Math.random() * foodcolors.length)]};
if (rnd < 0.88) return {'chr':'!', 'fg':'red'};
if (rnd < 0.93) return {'chr':'!', 'fg':'cyan'};
if (rnd < 0.97) return {'chr':'!', 'fg':'pink'};
return {'chr':'(', 'fg':'white'};
case '(':
var toolcolors = new Array('darkgray', 'red', 'red', 'white', 'white', 'white', 'white', 'white', 'white', 'white',
'cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan',
'brightcyan', 'brightcyan', 'brown', 'brown', 'brown', 'brown', 'brown', 'brown', 'brown', 'brown',
'yellow', 'yellow', 'yellow', 'yellow', 'gray', 'gray', 'gray');
return {'chr':'(', 'fg':toolcolors[Math.floor(Math.random() * toolcolors.length)]};
case '!':
return {'chr':'!', 'fg':pen_getcolor('random')};
case '/': if (rnd < 0.9) return {'chr':'/', 'fg':pen_getcolor('random')};
return {'chr':'[', 'fg':'brown'};
case '[':
if (rnd < 0.9) {
if (rnd < 0.40) return {'chr':'[', 'fg':'cyan'};
if (rnd < 0.80) return {'chr':'[', 'fg':'brown'};
return {'chr':'[', 'fg':pen_getcolor('random')};
} else {
return {'chr':')', 'fg':((Math.random() < 0.5) ? 'cyan' : 'brown')};
}
case ')':
if (rnd < 0.1) {
if (rnd < 0.04) return {'chr':'[', 'fg':'cyan'};
if (rnd < 0.08) return {'chr':'[', 'fg':'brown'};
return {'chr':'[', 'fg':pen_getcolor('random')};
} else {
return {'chr':')', 'fg':((Math.random() < 0.5) ? 'cyan' : 'brown')};
}
default:
var sym;
do {
sym = random_obj_sym();
} while (sym.chr == '$');
return sym;
}
}
function generate_random_shop(shoptype)
{
var x, y;
editpaneldata.draw_random(10); /* HACK: makes a fake scroll shop */
if (typeof(shoptype) == "number") shoptype = nethack_shop_types[shoptype].chr;
for (x = 0; x < editpaneldata.WID; x++)
for (y = 0; y < editpaneldata.HEI; y++) {
var dat = editpaneldata.get_data(x,y);
if (dat.chr == '?' && dat.fg == 'white') editpaneldata.set_data(x,y, get_random_shop_sym(shoptype));
}
}
function panel_redraw()
{
show_edit_panel();
show_editpanel_textarea();
panel_showcode();
strip_preview_panels();
update_editpanel_textarea();
set_undobtn_state();
}
function ruler_display(typ)
{
var t = (typ) ? 'block' : 'none';
$('mapcoords_n').style.display = t;
$('mapcoords_s').style.display = t;
$('mapcoords_w').style.display = t;
$('mapcoords_e').style.display = t;
$('mapruler_h').style.display = t;
$('mapruler_v').style.display = t;
}
function show_ruler(x,y, maxx, maxy, pose, mape)
{
var px = get_documentOffsetLeft($(pose));
var py = get_documentOffsetTop($(pose));
var mox = get_documentOffsetLeft($(mape));
var moy = get_documentOffsetTop($(mape));
ruler_display(1);
$('mapcoords_n').innerHTML = ''+y;
$('mapcoords_s').innerHTML = ''+(maxy-1 - y);
$('mapcoords_w').innerHTML = ''+x;
$('mapcoords_e').innerHTML = ''+(maxx-1 - x);
$('mapcoords_n').style.top = (moy - $('mapcoords_n').offsetHeight)+'px';
$('mapcoords_n').style.left = px+'px';
$('mapcoords_s').style.top = (moy + $(mape).offsetHeight)+'px';
$('mapcoords_s').style.left = px+'px';
$('mapcoords_w').style.top = py+'px';
$('mapcoords_w').style.left = (mox - $('mapcoords_w').offsetWidth)+'px';
$('mapcoords_e').style.top = py+'px';
$('mapcoords_e').style.left = (mox + $(mape).offsetWidth)+'px';
$('mapruler_h').style.top = py+'px';
$('mapruler_h').style.left = mox+'px';
$('mapruler_h').style.width = $(mape).offsetWidth+'px';
$('mapruler_v').style.top = moy+'px';
$('mapruler_v').style.left = px+'px';
$('mapruler_v').style.height = $(mape).offsetHeight+'px';
}
function panel_mouse_hover(x,y, onoff)
{
var tmp;
if (onoff) {
current_pos_x = x;
current_pos_y = y;
hovering_on_editpanel = 1;
show_ruler(x,y, editpaneldata.WID, editpaneldata.HEI, 'editpanelpos'+x+'x'+y, 'editpanel_container');
} else {
hovering_on_editpanel = 0;
ruler_display(0);
}
function mousehover_mark_on(x1,y1)
{
tmp = $("editpanelpos"+x1+"x"+y1);
if (tmp) tmp.style.background = "red";
}
function mousehover_mark_off(x1,y1)
{
tmp = $("editpanelpos"+x1+"x"+y1);
if (tmp) tmp.style.background = "black";
}
switch (editmode) {
default:
case 0: /* pen drawing */
case 1: /* color picker */
case 2: /* writer mode */
tmp = $("editpanelpos"+x+"x"+y);
if (tmp) {
tmp.style.background = (onoff) ? "red" : "black";
}
break;
case 3: /* floodfill */
if (onoff) {
tmp = $("editpanelpos"+x+"x"+y);
if (tmp && tmp.style.background == "red") break;
editpaneldata.draw_floodfill(x,y, mousehover_mark_on);
} else {
tmp = $("editpanelpos"+x+"x"+y);
if (tmp && tmp.style.background == "black") break;
editpaneldata.draw_floodfill(x,y, mousehover_mark_off);
}
break;
case 4: /* line draw */
if (onoff) {
editpaneldata.draw_line(cursor_x, cursor_y, x,y, mousehover_mark_on);
} else {
editpaneldata.draw_line(cursor_x, cursor_y, x,y, mousehover_mark_off);
}
break;
case 5: /* rect draw */
if (onoff) {
editpaneldata.draw_rect(cursor_x, cursor_y, x, y, mousehover_mark_on);
} else {
editpaneldata.draw_rect(cursor_x, cursor_y, x, y, mousehover_mark_off);
}
break;
case 6: /* filled rect draw */
if (onoff) {
editpaneldata.draw_rect_filled(cursor_x, cursor_y, x, y, mousehover_mark_on);
} else {
editpaneldata.draw_rect_filled(cursor_x, cursor_y, x, y, mousehover_mark_off);
}
break;
case 7: /* room rect */
if (onoff) {
editpaneldata.draw_rect(cursor_x, cursor_y, x, y, mousehover_mark_on);
} else {
editpaneldata.draw_rect(cursor_x, cursor_y, x, y, mousehover_mark_off);
}
break;
}
}
function panel_update(event, x,y)
{
var p;
if (event.ctrlKey) {
p = pen_clone_nornd(ctrl_pen);
} else {
p = pen_clone_nornd(pen);
}
if (p.chr == ' ') p.fg = "gray";
switch (editmode) {
default:
case 2: /* writer */
case 0: /* pen drawing */
editpaneldata.save_undopoint();
editpaneldata.set_data(x,y,p);
editpaneldata.check_undopoint();
break;
case 1: /* color picker */
var tmp = editpaneldata.get_data(x,y);
pen_set_sym(tmp);
change_editmode(0);
break;
case 3: /* flood fill */
editpaneldata.save_undopoint();
editpaneldata.draw_floodfill(x,y, p);
editpaneldata.check_undopoint();
break;
case 4: /* line draw */
editpaneldata.save_undopoint();
editpaneldata.draw_line(cursor_x, cursor_y, x,y, p);
editpaneldata.check_undopoint();
break;
case 5: /* rect draw */
editpaneldata.save_undopoint();
editpaneldata.draw_rect(cursor_x, cursor_y, x,y, p);
editpaneldata.check_undopoint();
break;
case 6: /* fill rect draw */
editpaneldata.save_undopoint();
editpaneldata.draw_rect_filled(cursor_x, cursor_y, x,y, p);
editpaneldata.check_undopoint();
break;
case 7: /* room rect */
editpaneldata.save_undopoint();
editpaneldata.draw_line(cursor_x, cursor_y, cursor_x, y, {'chr':'|'});
editpaneldata.draw_line( x, cursor_y, x, y, {'chr':'|'});
editpaneldata.draw_line(cursor_x, cursor_y, x, cursor_y, {'chr':'-'});
editpaneldata.draw_line(cursor_x, y, x, y, {'chr':'-'});
editpaneldata.check_undopoint();
break;
}
cursor_x = x;
cursor_y = y;
panel_redraw();
}
function panel_getdiv()
{
var x, y;
var txt = "";
var dat;
var tmpen;
var p_cursor_x = -1;
var p_cursor_y = -1;
if (editpaneldata.cursor != undefined) {
p_cursor_x = editpaneldata.cursor.x;
p_cursor_y = editpaneldata.cursor.y;
}
txt += '<div id="mapcoords_n"></div>';
txt += '<div id="mapcoords_s"></div>';
txt += '<div id="mapcoords_w"></div>';
txt += '<div id="mapcoords_e"></div>';
txt += '<div id="mapruler_h"></div>';
txt += '<div id="mapruler_v"></div>';
txt += "<div class='panelborder' id='editpanel_container'>";
txt += "<pre class='panel'>";
for (y = 0; y < editpaneldata.HEI; y++) {
for (x = 0; x < editpaneldata.WID; x++) {
dat = editpaneldata.get_data(x,y);
txt += "<span class='hovered";
if (editmode == 2 && x == cursor_x && y == cursor_y) txt += " cursor_hilite";
txt += "'";
txt += " id='editpanelpos"+x+"x"+y+"'";
txt += " onmouseover='panel_mouse_hover("+x+","+y+",1);'";
txt += " onmouseout='panel_mouse_hover("+x+","+y+",0);'";
txt += " onClick='panel_update(event, "+x+","+y+");'>";
tmpen = pen_clone(dat);
if (p_cursor_x == x && p_cursor_y == y) { tmpen.cur = 1; } else { tmpen.cur = 0; }
txt += get_data_span(tmpen);
txt += "</span>";
}
txt += "<br>";
}
txt += "</pre>";
txt += "</div>";
return txt;
}
function panel_get_colornotes(panelnum)
{
var y,x, i, r;
var txt = "";
var notes = new Array();
var dat;
var ch;
var tmppanel = panels[panelnum].panel.clone();
var fg;
for (y = 0; y < tmppanel.HEI; y++) {
for (x = 0; x < tmppanel.WID; x++) {
dat = tmppanel.get_data(x,y);
if (dat.chr != undefined) { ch = dat.chr; } else { continue; }
if (dat.chr == ' ') continue;
fg = dat.fg;
if (fg == undefined) { fg = "gray"; }
if (notes[ch] == undefined) {
notes[ch] = {'colors':new Array(), 'numcolors':0};
for (r in colors) {
notes[ch].colors[colors[r]] = 0;
}
}
if (notes[ch].colors[fg] == 0) { notes[ch].numcolors++; }
notes[ch].colors[fg]++;
}
}
for (i = ' '.charCodeAt(0); i <= '~'.charCodeAt(0); i++) {
ch = String.fromCharCode(i);
if ((notes[ch] == undefined) || (notes[ch].numcolors != 1)) continue;
for (r in colors) {
if (colors[r] == "gray") continue;
if ((notes[ch].colors[colors[r]] > 1) && (notes[ch].numcolors == 1)) {
txt += "SETCOLORS: All '" + ch + "' are \"" + colors[r] + "\"\n";
notes[ch].colors[colors[r]] = 0;
break;
}
}
}
for (y = 0; y < tmppanel.HEI; y++) {
for (x = 0; x < tmppanel.WID; x++) {
dat = tmppanel.get_data(x,y);
if (dat.chr != undefined) { ch = dat.chr; } else { continue; }
if (dat.chr == ' ') continue;
if (dat.fg && (dat.fg != "gray") && (notes[ch].colors[dat.fg] > 0)) {
if (ch >= ' ' && ch <= '~' && ch.length == 1) {
txt += "SETCOLOR: (" + x + "," + y + "), '"+ch+"' is \"" + dat.fg + "\"\n";
} else {
txt += "SETCOLOR: (" + x + "," + y + "), \"" + dat.fg + "\"\n";
}
}
}
}
return txt;
}
var update_temp_stripcode = 0;
function save_temp_stripcode(turnoff)
{
if (update_temp_stripcode != 1) return;
if (turnoff == 1) update_temp_stripcode = 0;
var txt = escape(panel_getcode(1));
setStorageData('tmp_strip', txt);
}
function load_temp_stripcode(turnoff)
{
if (update_temp_stripcode != 1) return;
var txt = getStorageData('tmp_strip');
txt = unescape(txt);
txt = txt.replace(/</g, "<");
txt = txt.replace(/>/g, ">");
txt = txt.replace(/&/g, "&");
if (turnoff == 1) update_temp_stripcode = 0;
if (txt) { parse_code(txt); return 1; }
return 0;
}
function erase_temp_stripcode()
{
eraseStorageData('tmp_strip');
}
function panel_getcode(html)
{
var x,y, i;
var txt = "";
//txt += "TITLE:"+stripdata.title+"\n";
if (html)
txt += "AUTHOR:"+htmlentities(stripdata.author)+"\n";
else {
var htxt = stripdata.author;
htxt = htxt.replace("&", "&");
txt += "AUTHOR:"+htxt+"\n";
}
txt += "PANELS: (" + STRIP_WID + "," + STRIP_HEI + ")\n";
for (i = 0; i < (STRIP_HEI*STRIP_WID); i++) {
if (panels[i] == undefined) continue;