Bonk Camera Controls

Adds camera movement and speed adjustment to replays

目前为 2022-05-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bonk Camera Controls
  3. // @version 1.1.2
  4. // @author Shaunxx & AA1134
  5. // @description Adds camera movement and speed adjustment to replays
  6. // @match https://bonk.io/gameframe-release.html
  7. // @run-at document-start
  8. // @grant none
  9. // @license GPL-3.0
  10. // @namespace https://greasyfork.org/en/users/911845
  11. // ==/UserScript==
  12.  
  13. const injectorName = `Camera`;
  14. const errorMsg = `Whoops! ${injectorName} was unable to load.
  15. This may be due to an update to Bonk.io. If so, please report this error!
  16. This could also be because you have an extension that is incompatible with \
  17. ${injectorName}`;
  18.  
  19. function injector(src){
  20. let newSrc = src;
  21.  
  22. // replay speed slider
  23. const slider = document.getElementById("bgreplay_timescrub")
  24. slider.style.visibility = "inherit"
  25. slider.max = 2
  26. slider.step = 0.1
  27. // replaces screen shake with camera pan
  28. let screenshake = `if(L1Q.shk && (L1Q.shk.x != 0 || L1Q.shk.y != 0)){this.shakeTweenGroup.removeAll();var p1Q=new TWEEN.Tween(this.shakeTweenObject,this.shakeTweenGroup);var Y1Q=50;var C1Q=800;p1Q.to({x:L1Q.shk.x,y:L1Q.shk.y},Y1Q);p1Q.easing(TWEEN.Easing.Cubic.Out);p1Q.onComplete(()=>{var m1Q=new TWEEN.Tween(this.shakeTweenObject,this.shakeTweenGroup);m1Q.to({x:0,y:0},C1Q);m1Q.easing(TWEEN.Easing.Elastic.Out);G9b.g9b();m1Q.start();});p1Q.start();}`
  29. newSrc = newSrc.replace(screenshake, `
  30. var render = this
  31. window.moveCamera = function() {
  32. if (render.isReplay == "replay") {
  33. render.shakeTweenGroup.removeAll();
  34. var p1Q = new TWEEN.Tween(render.shakeTweenObject, render.shakeTweenGroup);
  35. p1Q.to({
  36. x: cameraX,
  37. y: cameraY
  38. }, 0);
  39. p1Q.easing(TWEEN.Easing.Cubic.Out);
  40. p1Q.start();
  41. }
  42. }
  43. `)
  44.  
  45. // function spam xd
  46. newSrc = newSrc.replace("I8yy[443628]=(function(){", `I8yy[443628] = (function() {
  47. var keys = {}
  48. n = 20
  49. function handleKeyPress(evt) {
  50. let { keyCode, type } = evt || Event;
  51. let isKeyDown = (type == 'keydown');
  52. keys[keyCode] = isKeyDown;
  53. if (isKeyDown && keys[104]) { // NUMPAD_UP
  54. if (keys[100]) { moveTwo(n, n); } // NUMPAD_LEFT
  55. else if (keys[102]) { moveTwo(-n, n); } // MUMPAD_RIGHT
  56. else { cameraY += n; }
  57. }else if (isKeyDown && keys[98]) { // NUMPAD_DOWN
  58. if (keys[100]) { moveTwo(n, -n); } // NUMPAD_LEFT
  59. else if (keys[102]) { moveTwo(-n, -n); } // NUMPAD_RIGHT
  60. else { cameraY -= n; }
  61. }else if (isKeyDown && keys[100]) { cameraX += n; } // NUMPAD_LEFT
  62. else if (isKeyDown && keys[102]) { cameraX -= n; } // NUMPAD_RIGHT
  63. else if (isKeyDown && keys[101]) { resetCamera() } // NUMPAD_CENTER
  64. else if (isKeyDown && keys[103]) { changeZoom(-1) } // NUMPAD_HOME
  65. else if (isKeyDown && keys[105]) { changeZoom(1) } // NUMPAD_PGUP
  66. else { return; }
  67. window.moveCamera();
  68. };
  69.  
  70. function moveTwo(x, y) {
  71. cameraX += x
  72. cameraY += y
  73. }
  74. function changeZoom(n) {
  75. if (1/(n*0)===1/0) {
  76. zoom1 -= 50
  77. zoom2 -= 50
  78. }
  79. else {
  80. zoom1 += 50
  81. zoom2 += 50
  82. }
  83. }
  84. function resetCamera() {
  85. cameraX = 0;
  86. cameraY = 0;
  87. }
  88. window.addEventListener("keyup", handleKeyPress);
  89. window.addEventListener("keydown", handleKeyPress);
  90. cameraX = 0
  91. cameraY = 0
  92. `)
  93.  
  94. if(src === newSrc) throw "Injection failed!";
  95. console.log(injectorName+" injector run");
  96. return newSrc;
  97. }
  98.  
  99. // Compatibility with Excigma's code injector userscript
  100. if(!window.bonkCodeInjectors) window.bonkCodeInjectors = [];
  101. window.bonkCodeInjectors.push(bonkCode => {
  102. try {
  103. return injector(bonkCode);
  104. } catch (error) {
  105. alert(errorMsg);
  106. throw error;
  107. }
  108. });