From 9d17345e6d5dc4d4c714f1ff52bc26d995c79157 Mon Sep 17 00:00:00 2001 From: Alexey Nurgaliev Date: Fri, 11 Aug 2023 19:20:11 +0300 Subject: [PATCH] slow motion --- data/GameManager.js | 16 ++++++++++++++-- data/emulator.js | 34 ++++++++++++++++++++++++++++++---- data/emulator.min.js | 2 +- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/data/GameManager.js b/data/GameManager.js index 2bc3575..0c34137 100644 --- a/data/GameManager.js +++ b/data/GameManager.js @@ -27,7 +27,9 @@ class EJS_GameManager { toggleFastForward: this.Module.cwrap('toggle_fastforward', 'null', ['number']), setFastForwardRatio: this.Module.cwrap('set_ff_ratio', 'null', ['number']), toggleRewind: this.Module.cwrap('toggle_rewind', 'null', ['number']), - setRewindGranularity: this.Module.cwrap('set_rewind_granularity', 'null', ['number']) + setRewindGranularity: this.Module.cwrap('set_rewind_granularity', 'null', ['number']), + toggleSlowMotion: this.Module.cwrap('toggle_slow_motion', 'null', ['number']), + setSlowMotionRatio: this.Module.cwrap('set_sm_ratio', 'null', ['number']) } this.mkdir("/home"); this.mkdir("/home/web_user"); @@ -67,6 +69,7 @@ class EJS_GameManager { "video_vsync = true\n" + "video_smooth = false\n" + "fastforward_ratio = 3.0\n" + + "slowmotion_ratio = 3.0\n" + (this.EJS.rewindEnabled ? "rewind_enable = true\n" : "") + (this.EJS.rewindEnabled ? "rewind_granularity = 6\n" : "") + "savefile_directory = \"/data/saves\"\n"; @@ -146,7 +149,7 @@ class EJS_GameManager { this.EJS.netplay.simulateInput(player, index, value); return; } - if ([24, 25, 26, 27, 28].includes(index)) { + if ([24, 25, 26, 27, 28, 29].includes(index)) { if (index === 24 && value === 1) { const slot = this.EJS.settings['save-state-slot'] ? this.EJS.settings['save-state-slot'] : "1"; this.quickSave(slot); @@ -171,6 +174,9 @@ class EJS_GameManager { if (index === 27) { this.functions.toggleFastForward(this.EJS.isFastForward ? !value : value); } + if (index === 29) { + this.functions.toggleSlowMotion(this.EJS.isSlowMotion ? !value : value); + } if (index === 28) { if (this.EJS.rewindEnabled) { this.functions.toggleRewind(value); @@ -312,6 +318,12 @@ class EJS_GameManager { toggleFastForward(active) { this.functions.toggleFastForward(active); } + setSlowMotionRatio(ratio) { + this.functions.setSlowMotionRatio(ratio); + } + toggleSlowMotion(active) { + this.functions.toggleSlowMotion(active); + } setRewindGranularity(value) { this.functions.setRewindGranularity(value); } diff --git a/data/emulator.js b/data/emulator.js index 7171126..cdaaa8d 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -237,6 +237,7 @@ class EmulatorJS { this.config = config; this.currentPopup = null; this.isFastForward = false; + this.isSlowMotion = false; this.rewindEnabled = this.loadRewindEnabled(); this.touch = false; this.cheats = []; @@ -2038,6 +2039,7 @@ class EmulatorJS { {id: 25, label: this.localization('QUICK LOAD STATE')}, {id: 26, label: this.localization('CHANGE STATE SLOT')}, {id: 27, label: this.localization('FAST FORWARD')}, + {id: 29, label: this.localization('SLOW MOTION')}, {id: 28, label: this.localization('REWIND')} ); //if (_this.statesSupported === false) { @@ -2318,6 +2320,7 @@ class EmulatorJS { 26: {}, 27: {}, 28: {}, + 29: {}, }, 1: {}, 2: {}, @@ -2343,7 +2346,7 @@ class EmulatorJS { e.preventDefault(); const special = [16, 17, 18, 19, 20, 21, 22, 23]; for (let i=0; i<4; i++) { - for (let j=0; j<29; j++) { + for (let j=0; j<30; j++) { if (this.controls[i][j] && this.controls[i][j].value === e.key.toLowerCase()) { this.gameManager.simulateInput(i, j, (e.type === 'keyup' ? 0 : (special.includes(j) ? 0x7fff : 1))); } @@ -2375,7 +2378,7 @@ class EmulatorJS { if (this.settingsMenu.style.display !== "none" || this.isPopupOpen()) return; const special = [16, 17, 18, 19, 20, 21, 22, 23]; for (let i=0; i<4; i++) { - for (let j=0; j<29; j++) { + for (let j=0; j<30; j++) { if (['buttonup', 'buttondown'].includes(e.type) && (this.controls[i][j] && this.controls[i][j].value2 === e.index)) { this.gameManager.simulateInput(i, j, (e.type === 'buttonup' ? 0 : (special.includes(j) ? 0x7fff : 1))); } else if (e.type === "axischanged") { @@ -3133,6 +3136,20 @@ class EmulatorJS { this.isFastForward = false; this.gameManager.toggleFastForward(0); } + } else if (option === 'sm-ratio') { + if (this.isSlowMotion) this.gameManager.toggleSlowMotion(0); + this.gameManager.setSlowMotionRatio(parseFloat(value)); + setTimeout(() => { + if (this.isSlowMotion) this.gameManager.toggleSlowMotion(1); + }, 10); + } else if (option === 'slowMotion') { + if (value === "enabled") { + this.isSlowMotion = true; + this.gameManager.toggleSlowMotion(1); + } else if (value === "disabled") { + this.isSlowMotion = false; + this.gameManager.toggleSlowMotion(0); + } } else if (option === "rewind-granularity") { if (this.rewindEnabled) { this.gameManager.setRewindGranularity(parseInt(value)); @@ -3332,9 +3349,18 @@ class EmulatorJS { "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "6.5", "7.0", "7.5", "8.0", "8.5", "9.0", "9.5", "10.0", "unlimited" ], "3.0"); + addToMenu(this.localization('Slow Motion Ratio'), 'sm-ratio', [ + "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "6.5", "7.0", "7.5", "8.0", "8.5", "9.0", "9.5", "10.0" + ], "3.0"); + addToMenu(this.localization('Fast Forward'), 'fastForward', { - 'enabled': this.localization("Enabled"), - 'disabled': this.localization("Disabled") + 'enabled': this.localization("Enabled"), + 'disabled': this.localization("Disabled") + }, "disabled"); + + addToMenu(this.localization('Slow Motion'), 'slowMotion', { + 'enabled': this.localization("Enabled"), + 'disabled': this.localization("Disabled") }, "disabled"); addToMenu(this.localization('Rewind Enabled (requires restart)'), 'rewindEnabled', { diff --git a/data/emulator.min.js b/data/emulator.min.js index dbc3f3d..0d28ab2 100644 --- a/data/emulator.min.js +++ b/data/emulator.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("nipplejs",[],t):"object"==typeof exports?exports.nipplejs=t():e.nipplejs=t()}(window,function(){return n=[function(e,t,n){"use strict";n.r(t);function _(e,t){var n=t.x-e.x,t=t.y-e.y;return Math.sqrt(n*n+t*t)}function b(e){return e*(Math.PI/180)}function o(e){f.has(e)&&clearTimeout(f.get(e)),f.set(e,setTimeout(e,100))}function s(e,t,n){for(var i,o=t.split(/[ ,]+/g),s=0;sthis.options.threshold){var r,l={};for(r in this.direction)this.direction.hasOwnProperty(r)&&(l[r]=this.direction[r]);var c={};for(r in this.direction={x:n,y:i,angle:t},e.direction=this.direction,l)l[r]===this.direction[r]&&(c[r]=!0);if(c.x&&c.y&&c.angle)return e;c.x&&c.y||this.trigger("plain",e),c.x||this.trigger("plain:"+n,e),c.y||this.trigger("plain:"+i,e),c.angle||this.trigger("dir dir:"+t,e)}else this.resetDirection();return e};var x=w;function E(e,t){this.nipples=[],this.idles=[],this.actives=[],this.ids=[],this.pressureIntervals={},this.manager=e,this.id=E.id,E.id+=1,this.defaults={zone:document.body,multitouch:!1,maxNumberOfNipples:10,mode:"dynamic",position:{top:0,left:0},catchDistance:200,size:100,threshold:.1,color:"white",fadeTime:250,dataOnly:!1,restJoystick:!0,restOpacity:.5,lockX:!1,lockY:!1,shape:"circle",dynamicPage:!1,follow:!1},this.config(t),"static"!==this.options.mode&&"semi"!==this.options.mode||(this.options.multitouch=!1),this.options.multitouch||(this.options.maxNumberOfNipples=1);e=getComputedStyle(this.options.zone.parentElement);return e&&"flex"===e.display&&(this.parentIsFlex=!0),this.updateBox(),this.prepareNipples(),this.bindings(),this.begin(),this.nipples}E.prototype=new m,(E.constructor=E).id=0,E.prototype.prepareNipples=function(){var i=this.nipples;i.on=this.on.bind(this),i.off=this.off.bind(this),i.options=this.options,i.destroy=this.destroy.bind(this),i.ids=this.ids,i.id=this.id,i.processOnMove=this.processOnMove.bind(this),i.processOnEnd=this.processOnEnd.bind(this),i.get=function(e){if(void 0===e)return i[0];for(var t=0,n=i.length;t