-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdev.js
362 lines (298 loc) · 8.51 KB
/
dev.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
//
// 方便开发使用的过程
//
export default {
roomBrowse,
runAllScript,
enemyBrowse,
smallMapBrowse,
dataDirBrowse,
bgm,
};
import File from './file.js'
import Shader from './shader.js'
import Node from '../boot/node.js'
import BGM from './bgm.js'
import Tool, {DrawArray} from './tool.js'
const matrix = Node.load('boot/gl-matrix.js');
//
// 房间浏览器
//
function roomBrowse(Room, window, cam) {
let roomIdx = -1;
let cameraFront = cam.lookWhere();
let cameraCenter = cam.pos();
console.log("Total room", Room.count);
// Room.switchRoom(roomIdx++);
Room.showPic('common/data/Tit_bg.adt');
// Room.showPic('common/file/map00d.adt'); // 小地图
// Room.showPic('pl0/emd0/EM03A.TIM');
// Room.showPic('pl0/emd0/EM03A.tim');
window.input().pressOnce(gl.GLFW_KEY_J, function() {
_sw(1);
});
window.input().pressOnce(gl.GLFW_KEY_K, function() {
_sw(-1);
});
window.onKey(gl.GLFW_KEY_Z, gl.GLFW_PRESS, 0, function() {
matrix.vec3.rotateY(cameraFront, cameraFront, cameraCenter, 0.01);
});
console.log("Press J/K switch picture");
function _sw(x) {
roomIdx += x;
if (roomIdx >= Room.count) roomIdx = 0;
else if (roomIdx < 0) roomIdx = Room.count-1;
while (!Room.switchRoom(roomIdx)) {
console.warn("Blank room index", roomIdx.toString(16));
roomIdx += x;
if (roomIdx >= Room.count) roomIdx = 0;
else if (roomIdx < 0) roomIdx = Room.count-1;
}
console.log('room', roomIdx.toString(16));
}
}
function adtBrowse(dir, Room, window) {
let mapIdx = 0;
const maps = [];
const p = dir.split('/')[0];
let tmp = File.read_dir(dir);
tmp.forEach(function(f) {
if (f.endsWith('.adt') || f.endsWith('.tim')) {
let x = f.indexOf(p);
maps.push(f.substr(x));
}
});
console.log("Total map", maps.length);
Room.showPic(maps[0]); // 小地图
window.input().pressOnce(gl.GLFW_KEY_J, function() {
_sw(1);
});
window.input().pressOnce(gl.GLFW_KEY_K, function() {
_sw(-1);
});
console.log("Press J/K switch picture");
function _sw(x) {
mapIdx += x;
if (mapIdx < 0) mapIdx = maps.length-1;
else if (mapIdx >= maps.length) mapIdx = 0;
console.line(mapIdx, maps[mapIdx]);
try {
Room.showPic(maps[mapIdx]);
} catch(e) {
console.error(e.stack);
}
}
}
function smallMapBrowse(Room, window) {
adtBrowse('common/file', Room, window);
}
function dataDirBrowse(Room, window) {
adtBrowse('common/data', Room, window);
}
function enemyBrowse(Liv, window, Room, camera) {
camera.setPos(3000, -1000, 0);
let mods = [];
// 46: 枪店老板, 58:警察僵尸
// 动画不正常: 51:里昂, 94:机械臂, 91:食人花, 70:舔舐者, 71:鳄鱼
// 模型不正常: 39:艾达, 20:暴君
let mindex = 51;
_dir('Pl0/emd0');
_dir('pl1/emd1');
let mod;
let anim_idx = 0;
let anim_frame = 0;
// let q = 0;
let one_step = 5;
let weaponid = 0;
let player;
let curr_weapon;
let speed = 1;
let anim_move_info;
let tmat = matrix.mat4.create(1);
matrix.mat4.translate(tmat, tmat, [0, 0, 0]);
// matrix.mat4.rotateZ(tmat, tmat, Math.PI);
Shader.setModelTrans(tmat);
Shader.setEnvLight({r:255, g:255, b:255});
switchMod(0);
mod.setAnim(0, 0);
// mod.setDir(1);
mod.setSpeed(speed);
const d = 100000;
const color3 = new Float32Array([0.01, 0.01, 0.01]);
const range3 = Tool.xywd2range({x:0, y:-d, d:d<<1, w:10});
Tool.showRange(range3, window, color3);
const color2 = new Float32Array([0.9, 0.9, 0.9]);
const range1 = Tool.xywd2range({x:-d, y:0, d:10, w:d<<1});
Tool.showRange(range1, window, color3);
const range = Tool.xywd2range({x:-d, y:-d, d:d<<1, w:d<<1});
Tool.showRange(range, window, color2);
window.onKey(gl.GLFW_KEY_D, gl.GLFW_PRESS, 0, function() {
matrix.mat4.rotateY(tmat, tmat, 0.01);
Shader.setModelTrans(tmat);
});
window.onKey(gl.GLFW_KEY_A, gl.GLFW_PRESS, 0, function() {
matrix.mat4.rotateY(tmat, tmat, -0.01);
Shader.setModelTrans(tmat);
});
window.onKey(gl.GLFW_KEY_S, gl.GLFW_PRESS, 0, function() {
matrix.mat4.translate(tmat, tmat, [one_step, 0, 0]);
Shader.setModelTrans(tmat);
});
window.onKey(gl.GLFW_KEY_W, gl.GLFW_PRESS, 0, function() {
matrix.mat4.translate(tmat, tmat, [-one_step ,0, 0]);
Shader.setModelTrans(tmat);
});
window.input().pressOnce(gl.GLFW_KEY_U, function() {
switchMod(1);
});
window.input().pressOnce(gl.GLFW_KEY_I, function() {
switchMod(-1);
});
window.input().pressOnce(gl.GLFW_KEY_4, function() {
if (++anim_frame > mod.getPoseFrameLength())
anim_frame = 0;
mod.setAnim(anim_idx, anim_frame);
console.log("Frame", anim_frame);
});
window.input().pressOnce(gl.GLFW_KEY_Q, function() {
if (!mod) return;
if (!mod.setAnim(++anim_idx, 0)) {
mod.setAnim(0, 0);
anim_idx = 0;
}
console.log("POSE", anim_idx);
mod.show_pose_data_info();
});
window.input().pressOnce(gl.GLFW_KEY_Z, function() {
if (!mod) return;
if (!mod.setAnim(--anim_idx, 0)) {
mod.setAnim(0, 0);
anim_idx = 0;
}
console.log("POSE", anim_idx);
mod.show_pose_data_info();
});
window.input().pressOnce(gl.GLFW_KEY_E, function() {
if (!mod) return;
console.log("weapon", weaponid);
switchWeapon(weaponid++);
if (weaponid > 18) weaponid = 0;
});
window.input().pressOnce(gl.GLFW_KEY_1, function() {
if (mod) mod.setDir(-1);
});
window.input().pressOnce(gl.GLFW_KEY_2, function() {
if (mod) mod.setDir(0);
});
window.input().pressOnce(gl.GLFW_KEY_3, function() {
if (mod) mod.setDir(1);
});
window.input().pressOnce(gl.GLFW_KEY_MINUS, function() {
console.log("speed", speed *= 1.2);
if (mod) mod.setSpeed(speed);
});
window.input().pressOnce(gl.GLFW_KEY_EQUAL, function() {
console.log("speed", speed /= 1.2);
if (mod) mod.setSpeed(speed);
});
console.log("Press U/I next model");
console.log("Press A/D rotate");
console.log("Press W/S far/near");
console.log("Press Q next pose, Z previous pose");
console.log("Press 1/2/3 play anim");
console.log("Press =/- play anim speed");
window.add({
draw() {
one_step = anim_move_info[0];
mod.show_info();
},
});
function switchMod(x) {
if (mod) {
window.remove(mod);
mod.free();
}
mindex += x;
if (mindex < 0) mindex = mods.length-1;
else if (mindex >= mods.length) mindex = 0;
let info = mods[mindex];
player = info.player;
mod = Liv.loadEmd(player, info.id);
// mod = Liv.fromPld(info.player, x);
window.add(mod);
camera.lookAtSprite(mod);
// 切换模型的同时, 用模型纹理做背景
// Room.showPic(mod.texfile);
camera.lookAt(tmat[12], tmat[13]-1000, tmat[14]);
mod.setSpeed(speed);
mod.moveImmediately();
anim_move_info = mod.getMoveInfo();
console.log("Mod index:", mindex, player, info.id);
}
function switchWeapon(i) {
let weapon = Liv.fromPlw(player, i);
let comp = new DrawArray();
Liv.createSprites(weapon.mesh, weapon.tex, comp.array);
mod.getMD().setPoseFromMD(weapon, 10);
mod.getMD().combinationDraw(11/*right hand*/, comp);
if (curr_weapon) {
curr_weapon.free();
}
curr_weapon = comp;
}
function _dir(d) {
let dirfiles = File.read_dir(d);
let reg = /em(.)(..)\.emd/;
dirfiles.forEach(function(f) {
let test = f.toLowerCase();
if (! test.endsWith('.emd')) {
return;
}
let match = reg.exec(test);
if (! match) {
console.log("Skip match", test);
return;
}
mods.push({
player : parseInt(match[1]),
id : match[2],
});
});
}
}
//
// 尝试运行 bio 脚本, 并打印过程
//
function runAllScript(mapObj, runtime_data) {
_all(mapObj.init_script);
_all(mapObj.room_script);
// console.log("Map:", JSON.stringify(map0, 0, 2));
function _all(script) {
for (var i=0; i<script.count; ++i) {
console.debug("------------ Run script", i);
script.run(runtime_data);
}
}
}
function bgm() {
Tool.debug(audio.F_WaveShaperFilter);
let sub0 = 'COMMON/Sound/BGM/SUB_01.BGM';
let main0 = 'COMMON/Sound/BGM/MAIN0C.BGM';
let main1 = 'COMMON/Sound/BGM/MAIN05.BGM';
// let seq = BGM.main(main0);
let seq = BGM.sub(sub0)[0];
// for (;;) {
seq.play();
// console.log("LOOP");
// }
// allnote(seq);
function allnote(seq) {
let ch = seq.getChannel(0);
ch.setProgram(2);
for (let i=48; i<127; ++i) {
console.log("Note", i);
ch.play(i, 120);
thread.wait(1200);
}
}
}