-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathshared_ui.js
More file actions
180 lines (170 loc) · 4.21 KB
/
Copy pathshared_ui.js
File metadata and controls
180 lines (170 loc) · 4.21 KB
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
var actions = null;
var objects = null;
var combine = false;
var first_object = null;
var throw_obj = false;
function panel() {
if (map == null)
return;
var hero = map.hero, level = hero.level;
var html = "<dl><dt id='f'>" + hero.name + " the Fontanero<small>Level: " + hero.level + " (" + hero.levels[level-1] + ")</small></dt><dd>";
html += "<b>HP:</b> " + hero.hp + " (" + hero.max_hp() + ")" +
(hero.poisoned? " <b id='ps'>[POISONED]</b> ":"") +
(hero.blinded? " <b id='bl'>[BLINDED]</b>":"") +
(hero.confused? " <b id='cf'>[CONFUSED]</b>":"") +
"<br><b>Cash:</b> $" + hero.cash + " / " + hero.level_cap() +"<br>" +
"<b>Pipes found:</b> " + map.pipes + "<br><b>Pipes fixed:</b> " + map.fixed;
if (throw_obj) {
html += '<dt>Choose direction:</dt><dd>Press up, down, left or right to throw ' + first_object.name +'</dd>';
$('#panel')['html'](html);
return;
} else if (objects) {
html += '<dt>Choose item:</dt><dd><ol>';
for(var i = 0; i < objects.length; ++i) {
var o = objects[i];
html += "<li>" + o[0].name + "</li>";
}
html += '</ol></dd>';
$('#panel')['html'](html);
return;
} else {
html += '<dt>You are carrying:</dt><dd>' + hero.inv + '</dd>';
}
actions = hero.get_actions(); //MUST BE CALLED FIRST (do auto-pickup and other stuff)
var objs = hero.cell.objects;
var mask = 0;
html += '<dt>You see:</dt><dd>';
if (objs.length) {
for(var i = 0; i < objs.length; ++i) {
var o = objs[i];
mask |= o.type;
html += (i? ', ': '') + o.name;
}
}
else {
html += 'nothing'
}
html += "</dd>";
html += '<dt>Actions:</dt><dd id="a"><ul>';
for(var i = 0; i < actions.length; ++i) {
html += '<li>' + actions[i].name + "</li>";
}
html += '</ul></dd>';
$('#panel')['html'](html);
}
function on_key(e) {
var h = map.hero;
if (map == null || e.metaKey || $("#mg")['is'](":visible") || h.hp <= 0)
return;
var key = e.which || e.keyCode;
var key_char = String.fromCharCode(key).toLowerCase();
key = key_char.charCodeAt(0);
var used = false, call_tick = true;
//log("key " + key + "(" + key_char + ")");
switch(key) {
case 27:
used = true;
combine = false;
throw_obj = false;
first_object = null;
break;
case 37:
case 38:
case 39:
case 40:
var dx = [-1, 0, 1, 0][key - 37], dy = [0, -1, 0, 1][key - 37];
if (h.confused > 0) {
dx = -dx;
dy = -dy;
}
if (throw_obj) {
h.throw_obj(first_object, dx, dy);
call_tick = false;
} else
h.move(dx, dy);
used = true;
throw_obj = false;
first_object = null;
objects = null;
break;
default:
if (objects != null) {
var i = key - 0x61; //ord('a');
if (in_range(i, 0, objects.length)) {
var o = objects[i];
var a = o[1], obj = o[0];
if (combine && first_object == null) {
first_object = obj;
objects = h.get_objects(a, DRINKABLE);
call_tick = false;
used = true;
break;
}
if (a.need_dir) {
first_object = obj;
throw_obj = true;
call_tick = false;
used = true;
break;
}
a.apply(obj, first_object);
}
used = true;
objects = null;
} else if (actions != null) {
for(var i = 0; i < actions.length; ++i) {
var a = actions[i];
if (a.key == key_char) {
objects = h.get_objects(a);
combine = a.combine;
first_object = null;
switch(objects.length) {
case 0:
a.apply(); //auto-action w/o object (like (s)leep)
objects = null;
break;
case 1:
var obj = objects[0][0];
if (combine) { //choose even one object
call_tick = false;
break;
}
if (a.need_dir) {
first_object = obj;
throw_obj = true;
call_tick = false;
break;
}
a.apply(obj);
objects = null;
break;
default:
call_tick = false;
}
actions = null;
used = true;
break;
}
}
}
}
if (used) {
e.preventDefault();
if (call_tick)
map.tick();
panel();
}
}
function intro() {
log("You've entered the <s>dungeon</s> cellar to fix all broken pipes and vents.");
}
/*
window.onbeforeunload = function (evt) {
evt = evt || window.event;
if (evt) {
evt.returnValue = "Are you sure you want to leave?";
}
return message;
}
*/
$(document)['bind']($['browser']['mozilla'] ? 'keypress' : 'keydown', on_key);