Go で書き直した Ikemen
修订版 | d11337cb87de5510c73e5c5fd8e68749cf87a38a (tree) |
---|---|
时间 | 2018-12-16 19:53:53 |
作者 | neatunsou <sisiy4excite@gmai...> |
Commiter | neatunsou |
ゲームパッドに暫定対応
@@ -87,32 +87,32 @@ function options.f_keyDefault() | ||
87 | 87 | config.KeyConfig[2].Buttons[11] = 'RSHIFT' |
88 | 88 | config.KeyConfig[2].Buttons[12] = 'LEFTBRACKET' |
89 | 89 | config.KeyConfig[2].Buttons[13] = 'RIGHTBRACKET' |
90 | - config._comment.KeyConfig[1].Buttons[1] = '-7' | |
91 | - config._comment.KeyConfig[1].Buttons[2] = '-8' | |
92 | - config._comment.KeyConfig[1].Buttons[3] = '-5' | |
93 | - config._comment.KeyConfig[1].Buttons[4] = '-6' | |
94 | - config._comment.KeyConfig[1].Buttons[5] = '0' | |
95 | - config._comment.KeyConfig[1].Buttons[6] = '1' | |
96 | - config._comment.KeyConfig[1].Buttons[7] = '4' | |
97 | - config._comment.KeyConfig[1].Buttons[8] = '2' | |
98 | - config._comment.KeyConfig[1].Buttons[9] = '3' | |
99 | - config._comment.KeyConfig[1].Buttons[10] = '5' | |
100 | - config._comment.KeyConfig[1].Buttons[11] = '7' | |
101 | - config._comment.KeyConfig[1].Buttons[12] = '6' | |
102 | - config._comment.KeyConfig[1].Buttons[13] = '8' | |
103 | - config._comment.KeyConfig[2].Buttons[1] = '-7' | |
104 | - config._comment.KeyConfig[2].Buttons[2] = '-8' | |
105 | - config._comment.KeyConfig[2].Buttons[3] = '-5' | |
106 | - config._comment.KeyConfig[2].Buttons[4] = '-6' | |
107 | - config._comment.KeyConfig[2].Buttons[5] = '0' | |
108 | - config._comment.KeyConfig[2].Buttons[6] = '1' | |
109 | - config._comment.KeyConfig[2].Buttons[7] = '4' | |
110 | - config._comment.KeyConfig[2].Buttons[8] = '2' | |
111 | - config._comment.KeyConfig[2].Buttons[9] = '3' | |
112 | - config._comment.KeyConfig[2].Buttons[10] = '5' | |
113 | - config._comment.KeyConfig[2].Buttons[11] = '7' | |
114 | - config._comment.KeyConfig[2].Buttons[12] = '6' | |
115 | - config._comment.KeyConfig[2].Buttons[13] = '8' | |
90 | + config.JoystickConfig[1].Buttons[1] = '-7' | |
91 | + config.JoystickConfig[1].Buttons[2] = '-8' | |
92 | + config.JoystickConfig[1].Buttons[3] = '-5' | |
93 | + config.JoystickConfig[1].Buttons[4] = '-6' | |
94 | + config.JoystickConfig[1].Buttons[5] = '0' | |
95 | + config.JoystickConfig[1].Buttons[6] = '1' | |
96 | + config.JoystickConfig[1].Buttons[7] = '4' | |
97 | + config.JoystickConfig[1].Buttons[8] = '2' | |
98 | + config.JoystickConfig[1].Buttons[9] = '3' | |
99 | + config.JoystickConfig[1].Buttons[10] = '5' | |
100 | + config.JoystickConfig[1].Buttons[11] = '7' | |
101 | + config.JoystickConfig[1].Buttons[12] = '6' | |
102 | + config.JoystickConfig[1].Buttons[13] = '8' | |
103 | + config.JoystickConfig[2].Buttons[1] = '-7' | |
104 | + config.JoystickConfig[2].Buttons[2] = '-8' | |
105 | + config.JoystickConfig[2].Buttons[3] = '-5' | |
106 | + config.JoystickConfig[2].Buttons[4] = '-6' | |
107 | + config.JoystickConfig[2].Buttons[5] = '0' | |
108 | + config.JoystickConfig[2].Buttons[6] = '1' | |
109 | + config.JoystickConfig[2].Buttons[7] = '4' | |
110 | + config.JoystickConfig[2].Buttons[8] = '2' | |
111 | + config.JoystickConfig[2].Buttons[9] = '3' | |
112 | + config.JoystickConfig[2].Buttons[10] = '5' | |
113 | + config.JoystickConfig[2].Buttons[11] = '7' | |
114 | + config.JoystickConfig[2].Buttons[12] = '6' | |
115 | + config.JoystickConfig[2].Buttons[13] = '8' | |
116 | 116 | end |
117 | 117 | |
118 | 118 | function options.f_menuCommon1(cursorPosY, moveTxt, item, t) |
@@ -1049,7 +1049,7 @@ function options.f_keyCfg(playerNo, controller) | ||
1049 | 1049 | if controller == -1 then |
1050 | 1050 | t_keyCfg[i].vardisplay = config.KeyConfig[playerNo].Buttons[i] |
1051 | 1051 | else |
1052 | - t_keyCfg[i].vardisplay = config._comment.KeyConfig[playerNo].Buttons[i] | |
1052 | + t_keyCfg[i].vardisplay = config.JoystickConfig[playerNo].Buttons[i] | |
1053 | 1053 | end |
1054 | 1054 | end |
1055 | 1055 | while true do |
@@ -1072,7 +1072,7 @@ function options.f_keyCfg(playerNo, controller) | ||
1072 | 1072 | if controller == -1 then |
1073 | 1073 | config.KeyConfig[playerNo].Buttons[item] = key |
1074 | 1074 | else |
1075 | - config._comment.KeyConfig[playerNo].Buttons[item] = key | |
1075 | + config.JoystickConfig[playerNo].Buttons[item] = key | |
1076 | 1076 | end |
1077 | 1077 | else |
1078 | 1078 | sndPlay(motif.files.snd_data, motif.option_info.cancel_snd[1], motif.option_info.cancel_snd[2]) |
@@ -2,11 +2,12 @@ package main | ||
2 | 2 | |
3 | 3 | import ( |
4 | 4 | "encoding/binary" |
5 | - "github.com/go-gl/glfw/v3.2/glfw" | |
6 | 5 | "net" |
7 | 6 | "os" |
8 | 7 | "strings" |
9 | 8 | "time" |
9 | + | |
10 | + "github.com/go-gl/glfw/v3.2/glfw" | |
10 | 11 | ) |
11 | 12 | |
12 | 13 | type CommandKey byte |
@@ -51,6 +52,8 @@ const ( | ||
51 | 52 | CK_y |
52 | 53 | CK_z |
53 | 54 | CK_s |
55 | + CK_v | |
56 | + CK_w | |
54 | 57 | CK_na |
55 | 58 | CK_nb |
56 | 59 | CK_nc |
@@ -58,7 +61,9 @@ const ( | ||
58 | 61 | CK_ny |
59 | 62 | CK_nz |
60 | 63 | CK_ns |
61 | - CK_Last = CK_ns | |
64 | + CK_nv | |
65 | + CK_nw | |
66 | + CK_Last = CK_nw | |
62 | 67 | ) |
63 | 68 | |
64 | 69 | type NetState int |
@@ -311,6 +316,246 @@ func StringToKey(s string) glfw.Key { | ||
311 | 316 | return glfw.KeyUnknown |
312 | 317 | } |
313 | 318 | |
319 | +func KeyToString(k glfw.Key) string { | |
320 | + switch k { | |
321 | + case glfw.KeyEnter: | |
322 | + return "RETURN" | |
323 | + case glfw.KeyEscape: | |
324 | + return "ESCAPE" | |
325 | + case glfw.KeyBackspace: | |
326 | + return "BACKSPACE" | |
327 | + case glfw.KeyTab: | |
328 | + return "TAB" | |
329 | + case glfw.KeySpace: | |
330 | + return "SPACE" | |
331 | + case glfw.KeyApostrophe: | |
332 | + return "QUOTE" | |
333 | + case glfw.KeyComma: | |
334 | + return "COMMA" | |
335 | + case glfw.KeyMinus: | |
336 | + return "MINUS" | |
337 | + case glfw.KeyPeriod: | |
338 | + return "PERIOD" | |
339 | + case glfw.KeySlash: | |
340 | + return "SLASH" | |
341 | + case glfw.Key0: | |
342 | + return "0" | |
343 | + case glfw.Key1: | |
344 | + return "1" | |
345 | + case glfw.Key2: | |
346 | + return "2" | |
347 | + case glfw.Key3: | |
348 | + return "3" | |
349 | + case glfw.Key4: | |
350 | + return "4" | |
351 | + case glfw.Key5: | |
352 | + return "5" | |
353 | + case glfw.Key6: | |
354 | + return "6" | |
355 | + case glfw.Key7: | |
356 | + return "7" | |
357 | + case glfw.Key8: | |
358 | + return "8" | |
359 | + case glfw.Key9: | |
360 | + return "9" | |
361 | + case glfw.KeySemicolon: | |
362 | + return "SEMICOLON" | |
363 | + case glfw.KeyEqual: | |
364 | + return "EQUALS" | |
365 | + case glfw.KeyLeftBracket: | |
366 | + return "LEFTBRACKET" | |
367 | + case glfw.KeyBackslash: | |
368 | + return "BACKSLASH" | |
369 | + case glfw.KeyRightBracket: | |
370 | + return "RIGHTBRACKET" | |
371 | + case glfw.KeyGraveAccent: | |
372 | + return "BACKQUOTE" | |
373 | + case glfw.KeyA: | |
374 | + return "a" | |
375 | + case glfw.KeyB: | |
376 | + return "b" | |
377 | + case glfw.KeyC: | |
378 | + return "c" | |
379 | + case glfw.KeyD: | |
380 | + return "d" | |
381 | + case glfw.KeyE: | |
382 | + return "e" | |
383 | + case glfw.KeyF: | |
384 | + return "f" | |
385 | + case glfw.KeyG: | |
386 | + return "g" | |
387 | + case glfw.KeyH: | |
388 | + return "h" | |
389 | + case glfw.KeyI: | |
390 | + return "i" | |
391 | + case glfw.KeyJ: | |
392 | + return "j" | |
393 | + case glfw.KeyK: | |
394 | + return "k" | |
395 | + case glfw.KeyL: | |
396 | + return "l" | |
397 | + case glfw.KeyM: | |
398 | + return "m" | |
399 | + case glfw.KeyN: | |
400 | + return "n" | |
401 | + case glfw.KeyO: | |
402 | + return "o" | |
403 | + case glfw.KeyP: | |
404 | + return "p" | |
405 | + case glfw.KeyQ: | |
406 | + return "q" | |
407 | + case glfw.KeyR: | |
408 | + return "r" | |
409 | + case glfw.KeyS: | |
410 | + return "s" | |
411 | + case glfw.KeyT: | |
412 | + return "t" | |
413 | + case glfw.KeyU: | |
414 | + return "u" | |
415 | + case glfw.KeyV: | |
416 | + return "v" | |
417 | + case glfw.KeyW: | |
418 | + return "w" | |
419 | + case glfw.KeyX: | |
420 | + return "x" | |
421 | + case glfw.KeyY: | |
422 | + return "y" | |
423 | + case glfw.KeyZ: | |
424 | + return "z" | |
425 | + case glfw.KeyCapsLock: | |
426 | + return "CAPSLOCK" | |
427 | + case glfw.KeyF1: | |
428 | + return "F1" | |
429 | + case glfw.KeyF2: | |
430 | + return "F2" | |
431 | + case glfw.KeyF3: | |
432 | + return "F3" | |
433 | + case glfw.KeyF4: | |
434 | + return "F4" | |
435 | + case glfw.KeyF5: | |
436 | + return "F5" | |
437 | + case glfw.KeyF6: | |
438 | + return "F6" | |
439 | + case glfw.KeyF7: | |
440 | + return "F7" | |
441 | + case glfw.KeyF8: | |
442 | + return "F8" | |
443 | + case glfw.KeyF9: | |
444 | + return "F9" | |
445 | + case glfw.KeyF10: | |
446 | + return "F10" | |
447 | + case glfw.KeyF11: | |
448 | + return "F11" | |
449 | + case glfw.KeyF12: | |
450 | + return "F12" | |
451 | + case glfw.KeyPrintScreen: | |
452 | + return "PRINTSCREEN" | |
453 | + case glfw.KeyScrollLock: | |
454 | + return "SCROLLLOCK" | |
455 | + case glfw.KeyPause: | |
456 | + return "PAUSE" | |
457 | + case glfw.KeyInsert: | |
458 | + return "INSERT" | |
459 | + case glfw.KeyHome: | |
460 | + return "HOME" | |
461 | + case glfw.KeyPageUp: | |
462 | + return "PAGEUP" | |
463 | + case glfw.KeyDelete: | |
464 | + return "DELETE" | |
465 | + case glfw.KeyEnd: | |
466 | + return "END" | |
467 | + case glfw.KeyPageDown: | |
468 | + return "PAGEDOWN" | |
469 | + case glfw.KeyRight: | |
470 | + return "RIGHT" | |
471 | + case glfw.KeyLeft: | |
472 | + return "LEFT" | |
473 | + case glfw.KeyDown: | |
474 | + return "DOWN" | |
475 | + case glfw.KeyUp: | |
476 | + return "UP" | |
477 | + case glfw.KeyNumLock: | |
478 | + return "NUMLOCKCLEAR" | |
479 | + case glfw.KeyKPDivide: | |
480 | + return "KP_DIVIDE" | |
481 | + case glfw.KeyKPMultiply: | |
482 | + return "KP_MULTIPLY" | |
483 | + case glfw.KeyKPSubtract: | |
484 | + return "KP_MINUS" | |
485 | + case glfw.KeyKPAdd: | |
486 | + return "KP_PLUS" | |
487 | + case glfw.KeyKPEnter: | |
488 | + return "KP_ENTER" | |
489 | + case glfw.KeyKP1: | |
490 | + return "KP_1" | |
491 | + case glfw.KeyKP2: | |
492 | + return "KP_2" | |
493 | + case glfw.KeyKP3: | |
494 | + return "KP_3" | |
495 | + case glfw.KeyKP4: | |
496 | + return "KP_4" | |
497 | + case glfw.KeyKP5: | |
498 | + return "KP_5" | |
499 | + case glfw.KeyKP6: | |
500 | + return "KP_6" | |
501 | + case glfw.KeyKP7: | |
502 | + return "KP_7" | |
503 | + case glfw.KeyKP8: | |
504 | + return "KP_8" | |
505 | + case glfw.KeyKP9: | |
506 | + return "KP_9" | |
507 | + case glfw.KeyKP0: | |
508 | + return "KP_0" | |
509 | + case glfw.KeyKPDecimal: | |
510 | + return "KP_PERIOD" | |
511 | + case glfw.KeyKPEqual: | |
512 | + return "KP_EQUALS" | |
513 | + case glfw.KeyF13: | |
514 | + return "F13" | |
515 | + case glfw.KeyF14: | |
516 | + return "F14" | |
517 | + case glfw.KeyF15: | |
518 | + return "F15" | |
519 | + case glfw.KeyF16: | |
520 | + return "F16" | |
521 | + case glfw.KeyF17: | |
522 | + return "F17" | |
523 | + case glfw.KeyF18: | |
524 | + return "F18" | |
525 | + case glfw.KeyF19: | |
526 | + return "F19" | |
527 | + case glfw.KeyF20: | |
528 | + return "F20" | |
529 | + case glfw.KeyF21: | |
530 | + return "F21" | |
531 | + case glfw.KeyF22: | |
532 | + return "F22" | |
533 | + case glfw.KeyF23: | |
534 | + return "F23" | |
535 | + case glfw.KeyF24: | |
536 | + return "F24" | |
537 | + case glfw.KeyMenu: | |
538 | + return "MENU" | |
539 | + case glfw.KeyLeftControl: | |
540 | + return "LCTRL" | |
541 | + case glfw.KeyLeftShift: | |
542 | + return "LSHIFT" | |
543 | + case glfw.KeyLeftAlt: | |
544 | + return "LALT" | |
545 | + case glfw.KeyLeftSuper: | |
546 | + return "LGUI" | |
547 | + case glfw.KeyRightControl: | |
548 | + return "RCTRL" | |
549 | + case glfw.KeyRightShift: | |
550 | + return "RSHIFT" | |
551 | + case glfw.KeyRightAlt: | |
552 | + return "RALT" | |
553 | + case glfw.KeyRightSuper: | |
554 | + return "RGUI" | |
555 | + } | |
556 | + return "" | |
557 | +} | |
558 | + | |
314 | 559 | type ShortcutScript struct { |
315 | 560 | Activate bool |
316 | 561 | Script string |
@@ -344,8 +589,11 @@ func keyCallback(_ *glfw.Window, key glfw.Key, _ int, | ||
344 | 589 | switch action { |
345 | 590 | case glfw.Release: |
346 | 591 | sys.keySatate[key] = false |
592 | + sys.keyInput = glfw.KeyUnknown | |
593 | + sys.keyString = "" | |
347 | 594 | case glfw.Press: |
348 | 595 | sys.keySatate[key] = true |
596 | + sys.keyInput = key | |
349 | 597 | sys.esc = sys.esc || |
350 | 598 | key == glfw.KeyEscape && mk&(glfw.ModControl|glfw.ModAlt) == 0 |
351 | 599 | for k, v := range sys.shortcutScripts { |
@@ -353,6 +601,9 @@ func keyCallback(_ *glfw.Window, key glfw.Key, _ int, | ||
353 | 601 | } |
354 | 602 | } |
355 | 603 | } |
604 | +func charCallback(_ *glfw.Window, char rune, mk glfw.ModifierKey) { | |
605 | + sys.keyString = string(char) | |
606 | +} | |
356 | 607 | |
357 | 608 | var joystick = [...]glfw.Joystick{glfw.Joystick1, glfw.Joystick2, |
358 | 609 | glfw.Joystick3, glfw.Joystick4, glfw.Joystick5, glfw.Joystick6, |
@@ -367,27 +618,30 @@ func JoystickState(joy, button int) bool { | ||
367 | 618 | if joy >= len(joystick) { |
368 | 619 | return false |
369 | 620 | } |
621 | + btns := glfw.GetJoystickButtons(joystick[joy]) | |
370 | 622 | if button < 0 { |
371 | 623 | button = -button - 1 |
372 | 624 | axes := glfw.GetJoystickAxes(joystick[joy]) |
373 | 625 | if len(axes)*2 <= button { |
374 | 626 | return false |
375 | 627 | } |
628 | + if (button == 8 || button == 10) && len(axes) == 6 && len(btns) == 14 { //XboxコントローラーのLRトリガー判定(glfwがバージョンアップすればもっとちゃんと判別できるようになるはず) | |
629 | + return axes[button/2] > 0 | |
630 | + } | |
376 | 631 | switch button & 1 { |
377 | 632 | case 0: |
378 | - return axes[button/2] < -0.1 | |
633 | + return axes[button/2] < -0.2 | |
379 | 634 | case 1: |
380 | - return axes[button/2] > 0.1 | |
635 | + return axes[button/2] > 0.2 | |
381 | 636 | } |
382 | 637 | } |
383 | - btns := glfw.GetJoystickButtons(joystick[joy]) | |
384 | 638 | if len(btns) <= button { |
385 | 639 | return false |
386 | 640 | } |
387 | 641 | return btns[button] != 0 |
388 | 642 | } |
389 | 643 | |
390 | -type KeyConfig struct{ Joy, u, d, l, r, a, b, c, x, y, z, s int } | |
644 | +type KeyConfig struct{ Joy, u, d, l, r, a, b, c, x, y, z, s, v, w int } | |
391 | 645 | |
392 | 646 | func (kc KeyConfig) U() bool { return JoystickState(kc.Joy, kc.u) } |
393 | 647 | func (kc KeyConfig) D() bool { return JoystickState(kc.Joy, kc.d) } |
@@ -400,6 +654,8 @@ func (kc KeyConfig) X() bool { return JoystickState(kc.Joy, kc.x) } | ||
400 | 654 | func (kc KeyConfig) Y() bool { return JoystickState(kc.Joy, kc.y) } |
401 | 655 | func (kc KeyConfig) Z() bool { return JoystickState(kc.Joy, kc.z) } |
402 | 656 | func (kc KeyConfig) S() bool { return JoystickState(kc.Joy, kc.s) } |
657 | +func (kc KeyConfig) V() bool { return JoystickState(kc.Joy, kc.v) } | |
658 | +func (kc KeyConfig) W() bool { return JoystickState(kc.Joy, kc.w) } | |
403 | 659 | |
404 | 660 | type InputBits int32 |
405 | 661 |
@@ -415,7 +671,9 @@ const ( | ||
415 | 671 | IB_Y |
416 | 672 | IB_Z |
417 | 673 | IB_S |
418 | - IB_anybutton = IB_A | IB_B | IB_C | IB_X | IB_Y | IB_Z | |
674 | + IB_V | |
675 | + IB_W | |
676 | + IB_anybutton = IB_A | IB_B | IB_C | IB_X | IB_Y | IB_Z | IB_V | IB_W | |
419 | 677 | ) |
420 | 678 | |
421 | 679 | func (ib *InputBits) SetInput(in int) { |
@@ -425,7 +683,8 @@ func (ib *InputBits) SetInput(in int) { | ||
425 | 683 | Btoi(sys.keyConfig[in].R())<<3 | Btoi(sys.keyConfig[in].A())<<4 | |
426 | 684 | Btoi(sys.keyConfig[in].B())<<5 | Btoi(sys.keyConfig[in].C())<<6 | |
427 | 685 | Btoi(sys.keyConfig[in].X())<<7 | Btoi(sys.keyConfig[in].Y())<<8 | |
428 | - Btoi(sys.keyConfig[in].Z())<<9 | Btoi(sys.keyConfig[in].S())<<10) | |
686 | + Btoi(sys.keyConfig[in].Z())<<9 | Btoi(sys.keyConfig[in].S())<<10 | | |
687 | + Btoi(sys.keyConfig[in].V())<<11 | Btoi(sys.keyConfig[in].W())<<12) | |
429 | 688 | } |
430 | 689 | } |
431 | 690 | func (ib InputBits) GetInput(cb *CommandBuffer, facing int32) { |
@@ -436,23 +695,23 @@ func (ib InputBits) GetInput(cb *CommandBuffer, facing int32) { | ||
436 | 695 | b, f = ib&IB_L != 0, ib&IB_R != 0 |
437 | 696 | } |
438 | 697 | cb.Input(b, ib&IB_D != 0, f, ib&IB_U != 0, ib&IB_A != 0, ib&IB_B != 0, |
439 | - ib&IB_C != 0, ib&IB_X != 0, ib&IB_Y != 0, ib&IB_Z != 0, ib&IB_S != 0) | |
698 | + ib&IB_C != 0, ib&IB_X != 0, ib&IB_Y != 0, ib&IB_Z != 0, ib&IB_S != 0, ib&IB_V != 0, ib&IB_W != 0) | |
440 | 699 | } |
441 | 700 | |
442 | 701 | type CommandKeyRemap struct { |
443 | - a, b, c, x, y, z, s, na, nb, nc, nx, ny, nz, ns CommandKey | |
702 | + a, b, c, x, y, z, s, v, w, na, nb, nc, nx, ny, nz, ns, nv, nw CommandKey | |
444 | 703 | } |
445 | 704 | |
446 | 705 | func NewCommandKeyRemap() *CommandKeyRemap { |
447 | - return &CommandKeyRemap{CK_a, CK_b, CK_c, CK_x, CK_y, CK_z, CK_s, | |
448 | - CK_na, CK_nb, CK_nc, CK_nx, CK_ny, CK_nz, CK_ns} | |
706 | + return &CommandKeyRemap{CK_a, CK_b, CK_c, CK_x, CK_y, CK_z, CK_s, CK_v, CK_w, | |
707 | + CK_na, CK_nb, CK_nc, CK_nx, CK_ny, CK_nz, CK_ns, CK_nv, CK_nw} | |
449 | 708 | } |
450 | 709 | |
451 | 710 | type CommandBuffer struct { |
452 | - Bb, Db, Fb, Ub int32 | |
453 | - ab, bb, cb, xb, yb, zb, sb int32 | |
454 | - B, D, F, U int8 | |
455 | - a, b, c, x, y, z, s int8 | |
711 | + Bb, Db, Fb, Ub int32 | |
712 | + ab, bb, cb, xb, yb, zb, sb, vb, wb int32 | |
713 | + B, D, F, U int8 | |
714 | + a, b, c, x, y, z, s, v, w int8 | |
456 | 715 | } |
457 | 716 | |
458 | 717 | func NewCommandBuffer() (c *CommandBuffer) { |
@@ -462,9 +721,9 @@ func NewCommandBuffer() (c *CommandBuffer) { | ||
462 | 721 | } |
463 | 722 | func (__ *CommandBuffer) Reset() { |
464 | 723 | *__ = CommandBuffer{B: -1, D: -1, F: -1, U: -1, |
465 | - a: -1, b: -1, c: -1, x: -1, y: -1, z: -1, s: -1} | |
724 | + a: -1, b: -1, c: -1, x: -1, y: -1, z: -1, s: -1, v: -1, w: -1} | |
466 | 725 | } |
467 | -func (__ *CommandBuffer) Input(B, D, F, U, a, b, c, x, y, z, s bool) { | |
726 | +func (__ *CommandBuffer) Input(B, D, F, U, a, b, c, x, y, z, s, v, w bool) { | |
468 | 727 | if (B && !F) != (__.B > 0) { |
469 | 728 | __.Bb = 0 |
470 | 729 | __.B *= -1 |
@@ -520,6 +779,16 @@ func (__ *CommandBuffer) Input(B, D, F, U, a, b, c, x, y, z, s bool) { | ||
520 | 779 | __.s *= -1 |
521 | 780 | } |
522 | 781 | __.sb += int32(__.s) |
782 | + if v != (__.v > 0) { | |
783 | + __.vb = 0 | |
784 | + __.v *= -1 | |
785 | + } | |
786 | + __.vb += int32(__.v) | |
787 | + if w != (__.w > 0) { | |
788 | + __.wb = 0 | |
789 | + __.w *= -1 | |
790 | + } | |
791 | + __.wb += int32(__.w) | |
523 | 792 | } |
524 | 793 | func (__ *CommandBuffer) InputBits(ib InputBits, f int32) { |
525 | 794 | var B, F bool |
@@ -529,7 +798,7 @@ func (__ *CommandBuffer) InputBits(ib InputBits, f int32) { | ||
529 | 798 | B, F = ib&IB_L != 0, ib&IB_R != 0 |
530 | 799 | } |
531 | 800 | __.Input(B, ib&IB_D != 0, F, ib&IB_U != 0, ib&IB_A != 0, ib&IB_B != 0, |
532 | - ib&IB_C != 0, ib&IB_X != 0, ib&IB_Y != 0, ib&IB_Z != 0, ib&IB_S != 0) | |
801 | + ib&IB_C != 0, ib&IB_X != 0, ib&IB_Y != 0, ib&IB_Z != 0, ib&IB_S != 0, ib&IB_V != 0, ib&IB_W != 0) | |
533 | 802 | } |
534 | 803 | func (__ *CommandBuffer) State(ck CommandKey) int32 { |
535 | 804 | switch ck { |
@@ -579,6 +848,10 @@ func (__ *CommandBuffer) State(ck CommandKey) int32 { | ||
579 | 848 | return __.zb |
580 | 849 | case CK_s: |
581 | 850 | return __.sb |
851 | + case CK_v: | |
852 | + return __.vb | |
853 | + case CK_w: | |
854 | + return __.wb | |
582 | 855 | case CK_nB: |
583 | 856 | return -Min(-Max(__.Db, __.Ub), __.Bb) |
584 | 857 | case CK_nD: |
@@ -625,6 +898,10 @@ func (__ *CommandBuffer) State(ck CommandKey) int32 { | ||
625 | 898 | return -__.zb |
626 | 899 | case CK_ns: |
627 | 900 | return -__.sb |
901 | + case CK_nv: | |
902 | + return -__.vb | |
903 | + case CK_nw: | |
904 | + return -__.wb | |
628 | 905 | } |
629 | 906 | return 0 |
630 | 907 | } |
@@ -705,7 +982,7 @@ func (__ *CommandBuffer) LastDirectionTime() int32 { | ||
705 | 982 | } |
706 | 983 | func (__ *CommandBuffer) LastChangeTime() int32 { |
707 | 984 | return Min(__.LastDirectionTime(), Abs(__.ab), Abs(__.bb), Abs(__.cb), |
708 | - Abs(__.xb), Abs(__.yb), Abs(__.zb), Abs(__.sb)) | |
985 | + Abs(__.xb), Abs(__.yb), Abs(__.zb), Abs(__.sb), Abs(__.vb), Abs(__.wb)) | |
709 | 986 | } |
710 | 987 | |
711 | 988 | type NetBuffer struct { |
@@ -1052,13 +1329,14 @@ func (fi *FileInput) Update() bool { | ||
1052 | 1329 | } |
1053 | 1330 | |
1054 | 1331 | type AiInput struct { |
1055 | - dir, dt, at, bt, ct, xt, yt, zt, st int32 | |
1332 | + dir, dt, at, bt, ct, xt, yt, zt, st, vt, wt int32 | |
1056 | 1333 | } |
1057 | 1334 | |
1058 | 1335 | func (__ *AiInput) Update() { |
1059 | 1336 | if sys.intro != 0 { |
1060 | 1337 | __.dt, __.at, __.bt, __.ct = 0, 0, 0, 0 |
1061 | 1338 | __.xt, __.yt, __.zt, __.st = 0, 0, 0, 0 |
1339 | + __.vt, __.wt = 0, 0 | |
1062 | 1340 | return |
1063 | 1341 | } |
1064 | 1342 | var osu, hanasu int32 = 15, 60 |
@@ -1083,6 +1361,8 @@ func (__ *AiInput) Update() { | ||
1083 | 1361 | dec(&__.xt) |
1084 | 1362 | dec(&__.yt) |
1085 | 1363 | dec(&__.zt) |
1364 | + dec(&__.vt) | |
1365 | + dec(&__.wt) | |
1086 | 1366 | osu = 3600 |
1087 | 1367 | dec(&__.st) |
1088 | 1368 | } |
@@ -1119,6 +1399,12 @@ func (__ *AiInput) Z() bool { | ||
1119 | 1399 | func (__ *AiInput) S() bool { |
1120 | 1400 | return __.st != 0 |
1121 | 1401 | } |
1402 | +func (__ *AiInput) V() bool { | |
1403 | + return __.vt != 0 | |
1404 | +} | |
1405 | +func (__ *AiInput) W() bool { | |
1406 | + return __.wt != 0 | |
1407 | +} | |
1122 | 1408 | |
1123 | 1409 | type cmdElem struct { |
1124 | 1410 | key []CommandKey |
@@ -1305,7 +1591,7 @@ func ReadCommand(name, cmdstr string, kr *CommandKeyRemap) (*Command, error) { | ||
1305 | 1591 | tilde = false |
1306 | 1592 | case 'x': |
1307 | 1593 | if tilde { |
1308 | - ce.key = append(ce.key, kr.x) | |
1594 | + ce.key = append(ce.key, kr.nx) | |
1309 | 1595 | } else { |
1310 | 1596 | ce.key = append(ce.key, kr.x) |
1311 | 1597 | } |
@@ -1331,6 +1617,20 @@ func ReadCommand(name, cmdstr string, kr *CommandKeyRemap) (*Command, error) { | ||
1331 | 1617 | ce.key = append(ce.key, kr.s) |
1332 | 1618 | } |
1333 | 1619 | tilde = false |
1620 | + case 'v': | |
1621 | + if tilde { | |
1622 | + ce.key = append(ce.key, kr.nv) | |
1623 | + } else { | |
1624 | + ce.key = append(ce.key, kr.v) | |
1625 | + } | |
1626 | + tilde = false | |
1627 | + case 'w': | |
1628 | + if tilde { | |
1629 | + ce.key = append(ce.key, kr.nw) | |
1630 | + } else { | |
1631 | + ce.key = append(ce.key, kr.w) | |
1632 | + } | |
1633 | + tilde = false | |
1334 | 1634 | case '$': |
1335 | 1635 | switch nextChar() { |
1336 | 1636 | case 'B': |
@@ -1616,7 +1916,7 @@ func (cl *CommandList) Input(i int, facing int32) bool { | ||
1616 | 1916 | _else = true |
1617 | 1917 | } |
1618 | 1918 | if _else { |
1619 | - var l, r, u, d, a, b, c, x, y, z, s bool | |
1919 | + var l, r, u, d, a, b, c, x, y, z, s, v, w bool | |
1620 | 1920 | if i < 0 { |
1621 | 1921 | i = ^i |
1622 | 1922 | if i < len(sys.aiInput) { |
@@ -1631,12 +1931,14 @@ func (cl *CommandList) Input(i int, facing int32) bool { | ||
1631 | 1931 | y = sys.aiInput[i].Y() |
1632 | 1932 | z = sys.aiInput[i].Z() |
1633 | 1933 | s = sys.aiInput[i].S() |
1934 | + v = sys.aiInput[i].V() | |
1935 | + w = sys.aiInput[i].W() | |
1634 | 1936 | } |
1635 | 1937 | } else if i < len(sys.inputRemap) { |
1636 | 1938 | in := sys.inputRemap[i] |
1637 | 1939 | if in < len(sys.keyConfig) { |
1638 | 1940 | joy := sys.keyConfig[in].Joy |
1639 | - if joy >= -1 { | |
1941 | + if joy == -1 { | |
1640 | 1942 | l = sys.keyConfig[in].L() |
1641 | 1943 | r = sys.keyConfig[in].R() |
1642 | 1944 | u = sys.keyConfig[in].U() |
@@ -1648,6 +1950,52 @@ func (cl *CommandList) Input(i int, facing int32) bool { | ||
1648 | 1950 | y = sys.keyConfig[in].Y() |
1649 | 1951 | z = sys.keyConfig[in].Z() |
1650 | 1952 | s = sys.keyConfig[in].S() |
1953 | + v = sys.keyConfig[in].V() | |
1954 | + w = sys.keyConfig[in].W() | |
1955 | + } | |
1956 | + } | |
1957 | + if in < len(sys.JoystickConfig) { | |
1958 | + joyS := sys.JoystickConfig[in].Joy | |
1959 | + if joyS >= 0 { | |
1960 | + if l == false { | |
1961 | + l = sys.JoystickConfig[in].L() | |
1962 | + } | |
1963 | + if r == false { | |
1964 | + r = sys.JoystickConfig[in].R() | |
1965 | + } | |
1966 | + if u == false { | |
1967 | + u = sys.JoystickConfig[in].U() | |
1968 | + } | |
1969 | + if d == false { | |
1970 | + d = sys.JoystickConfig[in].D() | |
1971 | + } | |
1972 | + if a == false { | |
1973 | + a = sys.JoystickConfig[in].A() | |
1974 | + } | |
1975 | + if b == false { | |
1976 | + b = sys.JoystickConfig[in].B() | |
1977 | + } | |
1978 | + if c == false { | |
1979 | + c = sys.JoystickConfig[in].C() | |
1980 | + } | |
1981 | + if x == false { | |
1982 | + x = sys.JoystickConfig[in].X() | |
1983 | + } | |
1984 | + if y == false { | |
1985 | + y = sys.JoystickConfig[in].Y() | |
1986 | + } | |
1987 | + if z == false { | |
1988 | + z = sys.JoystickConfig[in].Z() | |
1989 | + } | |
1990 | + if s == false { | |
1991 | + s = sys.JoystickConfig[in].S() | |
1992 | + } | |
1993 | + if v == false { | |
1994 | + v = sys.JoystickConfig[in].V() | |
1995 | + } | |
1996 | + if w == false { | |
1997 | + w = sys.JoystickConfig[in].W() | |
1998 | + } | |
1651 | 1999 | } |
1652 | 2000 | } |
1653 | 2001 | } |
@@ -1657,7 +2005,7 @@ func (cl *CommandList) Input(i int, facing int32) bool { | ||
1657 | 2005 | } else { |
1658 | 2006 | B, F = l, r |
1659 | 2007 | } |
1660 | - cl.Buffer.Input(B, d, F, u, a, b, c, x, y, z, s) | |
2008 | + cl.Buffer.Input(B, d, F, u, a, b, c, x, y, z, s, v, w) | |
1661 | 2009 | } |
1662 | 2010 | return step |
1663 | 2011 | } |
@@ -7,6 +7,7 @@ import ( | ||
7 | 7 | "os" |
8 | 8 | "regexp" |
9 | 9 | "runtime" |
10 | + "strconv" | |
10 | 11 | "strings" |
11 | 12 | "syscall" |
12 | 13 |
@@ -103,16 +104,13 @@ func main() { | ||
103 | 104 | "Joystick":-1, |
104 | 105 | "Buttons":["t","g","f","h","j","k","l","u","i","o","RSHIFT","LEFTBRACKET","RIGHTBRACKET"] |
105 | 106 | }], |
106 | - "_comment":{ | |
107 | - "_comment":"ジョイスティック (0番) の場合の KeyConfig", | |
108 | - "KeyConfig":[{ | |
109 | - "Joystick":0, | |
110 | - "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"] | |
111 | - },{ | |
112 | - "Joystick":1, | |
113 | - "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"] | |
114 | - }] | |
115 | - }, | |
107 | + "JoystickConfig":[{ | |
108 | + "Joystick":0, | |
109 | + "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"] | |
110 | + },{ | |
111 | + "Joystick":1, | |
112 | + "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"] | |
113 | + }], | |
116 | 114 | "Motif":"data/system.def", |
117 | 115 | "CommonAir":"data/common.air", |
118 | 116 | "CommonCmd":"data/common.cmd", |
@@ -159,6 +157,10 @@ func main() { | ||
159 | 157 | Joystick int |
160 | 158 | Buttons []interface{} |
161 | 159 | } |
160 | + JoystickConfig []struct { | |
161 | + Joystick int | |
162 | + Buttons []interface{} | |
163 | + } | |
162 | 164 | NumTag int |
163 | 165 | TeamLifeShare bool |
164 | 166 | AIRandomColor bool |
@@ -192,17 +194,15 @@ func main() { | ||
192 | 194 | stoki := func(key string) int { |
193 | 195 | return int(StringToKey(key)) |
194 | 196 | } |
197 | + Atoi := func(key string) int { | |
198 | + var i int | |
199 | + i, _ = strconv.Atoi(key) | |
200 | + return i | |
201 | + } | |
195 | 202 | for a := 0; a < tmp.NumTag; a++ { |
196 | 203 | for _, kc := range tmp.KeyConfig { |
197 | 204 | b := kc.Buttons |
198 | - if kc.Joystick >= 0 { | |
199 | - sys.keyConfig = append(sys.keyConfig, KeyConfig{kc.Joystick, | |
200 | - int(b[0].(float64)), int(b[1].(float64)), | |
201 | - int(b[2].(float64)), int(b[3].(float64)), | |
202 | - int(b[4].(float64)), int(b[5].(float64)), int(b[6].(float64)), | |
203 | - int(b[7].(float64)), int(b[8].(float64)), int(b[9].(float64)), | |
204 | - int(b[10].(float64)), int(b[11].(float64)), int(b[12].(float64))}) | |
205 | - } else { | |
205 | + if kc.Joystick < 0 { | |
206 | 206 | sys.keyConfig = append(sys.keyConfig, KeyConfig{kc.Joystick, |
207 | 207 | stoki(b[0].(string)), stoki(b[1].(string)), |
208 | 208 | stoki(b[2].(string)), stoki(b[3].(string)), |
@@ -211,6 +211,17 @@ func main() { | ||
211 | 211 | stoki(b[10].(string)), stoki(b[11].(string)), stoki(b[12].(string))}) |
212 | 212 | } |
213 | 213 | } |
214 | + for _, jc := range tmp.JoystickConfig { | |
215 | + b := jc.Buttons | |
216 | + if jc.Joystick >= 0 { | |
217 | + sys.JoystickConfig = append(sys.JoystickConfig, KeyConfig{jc.Joystick, | |
218 | + Atoi(b[0].(string)), Atoi(b[1].(string)), | |
219 | + Atoi(b[2].(string)), Atoi(b[3].(string)), | |
220 | + Atoi(b[4].(string)), Atoi(b[5].(string)), Atoi(b[6].(string)), | |
221 | + Atoi(b[7].(string)), Atoi(b[8].(string)), Atoi(b[9].(string)), | |
222 | + Atoi(b[10].(string)), Atoi(b[11].(string)), Atoi(b[12].(string))}) | |
223 | + } | |
224 | + } | |
214 | 225 | } |
215 | 226 | sys.teamLifeShare = tmp.TeamLifeShare |
216 | 227 | sys.fullscreen = tmp.Fullscreen |
@@ -2,11 +2,11 @@ package main | ||
2 | 2 | |
3 | 3 | import ( |
4 | 4 | "fmt" |
5 | + "math/rand" | |
5 | 6 | "runtime" |
7 | + "strconv" | |
6 | 8 | "strings" |
7 | 9 | |
8 | - "math/rand" | |
9 | - | |
10 | 10 | "github.com/go-gl/glfw/v3.2/glfw" |
11 | 11 | "github.com/yuin/gopher-lua" |
12 | 12 | ) |
@@ -1085,6 +1085,32 @@ func systemScriptInit(l *lua.LState) { | ||
1085 | 1085 | if sys.keyInput != glfw.KeyUnknown { |
1086 | 1086 | s = KeyToString(sys.keyInput) |
1087 | 1087 | } |
1088 | + | |
1089 | + for j := 0; j < 2; j++ { | |
1090 | + if glfw.JoystickPresent(joystick[j]) { | |
1091 | + axes := glfw.GetJoystickAxes(joystick[j]) | |
1092 | + btns := glfw.GetJoystickButtons(joystick[j]) | |
1093 | + for i := range axes { | |
1094 | + if i > 3 && len(axes) == 6 && len(btns) == 14 { //Xboxコントローラー判定(glfwがバージョンアップすればもっとちゃんと判別できるようになるはず) | |
1095 | + if axes[i] > 0 { | |
1096 | + s = strconv.Itoa(-i*2 - 1) | |
1097 | + } | |
1098 | + } else { | |
1099 | + if axes[i] < -0.2 { | |
1100 | + s = strconv.Itoa(-i*2 - 1) | |
1101 | + } else if axes[i] > 0.2 { | |
1102 | + s = strconv.Itoa(-i*2 - 2) | |
1103 | + } | |
1104 | + } | |
1105 | + } | |
1106 | + for i := range btns { | |
1107 | + if btns[i] > 0 { | |
1108 | + s = strconv.Itoa(i) | |
1109 | + } | |
1110 | + } | |
1111 | + } | |
1112 | + } | |
1113 | + | |
1088 | 1114 | l.Push(lua.LString(s)) |
1089 | 1115 | return 1 |
1090 | 1116 | }) |
@@ -98,6 +98,7 @@ type System struct { | ||
98 | 98 | fileInput *FileInput |
99 | 99 | aiInput [MaxSimul * 2]AiInput |
100 | 100 | keyConfig []KeyConfig |
101 | + JoystickConfig []KeyConfig | |
101 | 102 | com [MaxSimul * 2]int32 |
102 | 103 | autolevel bool |
103 | 104 | home int |
@@ -445,6 +446,11 @@ func (s *System) anyHardButton() bool { | ||
445 | 446 | return true |
446 | 447 | } |
447 | 448 | } |
449 | + for _, kc := range s.JoystickConfig { | |
450 | + if kc.A() || kc.B() || kc.C() || kc.X() || kc.Y() || kc.Z() { | |
451 | + return true | |
452 | + } | |
453 | + } | |
448 | 454 | return false |
449 | 455 | } |
450 | 456 | func (s *System) anyButton() bool { |