diff --git a/www.rus/js/plugins/VND_ONSControls.js b/www.rus/js/plugins/VND_ONSControls.js index 576407b..70fdb2e 100644 --- a/www.rus/js/plugins/VND_ONSControls.js +++ b/www.rus/js/plugins/VND_ONSControls.js @@ -335,11 +335,7 @@ ONSControls.clearInteractive = function() { elem.removeAllListeners(); } // Clear status of VirtualGamepad - for (button of VirtualGamepad.gamepad.buttons) { - button.pressed = false; - button.touched = false; - button.value = 0; - } + VirtualGamepad.clearState(); } //============================================================================= // * Setup drag'n drop events for element @@ -492,6 +488,16 @@ VirtualGamepad.disconnect = function () { //VirtualGamepad.originalNavigator.getGamepads.call(); console.log(`ONSControls: Virtual gamepad disconnected with index ${this.gamepad.index}`); } +//============================================================================= +// * Clear state of all buttons +//============================================================================= +VirtualGamepad.clearState = function() { + for (button of VirtualGamepad.gamepad.buttons) { + button.pressed = false; + button.touched = false; + button.value = 0; + } +} @@ -532,32 +538,35 @@ ConfigManager.ONSConfig.showY ||= ONSControls._controlsCanvas.screen.height - (C var _ConfigManager_restoreDefaultConfig = ConfigManager.restoreDefaultConfig; ConfigManager.restoreDefaultConfig = function () { _ConfigManager_restoreDefaultConfig.apply(this, arguments); - const fs = require("fs");j + const fs = require("fs"); const path = require('path'); var base = path.dirname(process.mainModule.filename); base = path.join(base, 'save/'); if (fs.existsSync(base + "config.rpgsave")) { fs.unlinkSync(base + "config.rpgsave"); } - ConfigManager.ONSConfig.buttonsScale = this.options.buttonsScale; - ConfigManager.ONSConfig.buttonsOpacity = this.options.buttonsOpacity; - ConfigManager.ONSConfig.safeArea = ONSControls._controlsCanvas.vh(0.032); - ConfigManager.ONSConfig.buttonsSize = ONSControls._controlsCanvas.vh(0.18) * ConfigManager.ONSConfig.buttonsScale; - ConfigManager.ONSConfig.buttonsX = ONSControls._controlsCanvas.screen.width - (ConfigManager.ONSConfig.buttonsSize + ConfigManager.ONSConfig.safeArea); - ConfigManager.ONSConfig.buttonsY = ONSControls._controlsCanvas.screen.height - (ConfigManager.ONSConfig.buttonsSize + ConfigManager.ONSConfig.safeArea); - ConfigManager.ONSConfig.dPadSize = ONSControls._controlsCanvas.vh(0.36) * ConfigManager.ONSConfig.buttonsScale; - ConfigManager.ONSConfig.dPadX = ConfigManager.ONSConfig.dPadSize / 2 + ConfigManager.ONSConfig.safeArea; - ConfigManager.ONSConfig.dPadY = ONSControls._controlsCanvas.screen.height - (ConfigManager.ONSConfig.dPadSize / 2 + ConfigManager.ONSConfig.safeArea); - ConfigManager.ONSConfig.bumpersOffsetX = 16; - ConfigManager.ONSConfig.bumpersOffsetY = ONSControls._controlsCanvas.vh(0.30); - ConfigManager.ONSConfig.bumpersWidth = ONSControls._controlsCanvas.vh(0.188) * ConfigManager.ONSConfig.buttonsScale; - ConfigManager.ONSConfig.bumpersHeight = ONSControls._controlsCanvas.vh(0.12) * ConfigManager.ONSConfig.buttonsScale; - ConfigManager.ONSConfig.LBX = ConfigManager.ONSConfig.bumpersOffsetX + ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersWidth / 2; - ConfigManager.ONSConfig.LBY = (ConfigManager.ONSConfig.bumpersOffsetY + ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersHeight / 2); - ConfigManager.ONSConfig.RBX = ONSControls._controlsCanvas.screen.width - (ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersOffsetX + ConfigManager.ONSConfig.bumpersWidth / 2); - ConfigManager.ONSConfig.RBY = (ConfigManager.ONSConfig.bumpersOffsetY + ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersHeight / 2);ConfigManager.ONSConfig.additionalOffset = ONSControls._controlsCanvas.vh(0.03); - ConfigManager.ONSConfig.additonalSize = ONSControls._controlsCanvas.vh(0.06) * ConfigManager.ONSConfig.buttonsScale; - ConfigManager.ONSConfig.showX = ONSControls._controlsCanvas.screen.width - (ConfigManager.ONSConfig.additonalSize / 2 + ConfigManager.ONSConfig.safeArea); - ConfigManager.ONSConfig.showY = ONSControls._controlsCanvas.screen.height - (ConfigManager.ONSConfig.additonalSize / 2 + ConfigManager.ONSConfig.safeArea); - ConfigManager.applyData(ConfigManager); + this.ONSConfig.buttonsScale = ONSControls.options.buttonsScale; + this.ONSConfig.buttonsOpacity = ONSControls.options.buttonsOpacity; + this.ONSConfig.safeArea = ONSControls._controlsCanvas.vh(0.032); + this.ONSConfig.buttonsSize = ONSControls._controlsCanvas.vh(0.18) * this.ONSConfig.buttonsScale; + this.ONSConfig.buttonsX = ONSControls._controlsCanvas.screen.width - (this.ONSConfig.buttonsSize + this.ONSConfig.safeArea); + this.ONSConfig.buttonsY = ONSControls._controlsCanvas.screen.height - (this.ONSConfig.buttonsSize + this.ONSConfig.safeArea); + this.ONSConfig.dPadSize = ONSControls._controlsCanvas.vh(0.36) * this.ONSConfig.buttonsScale; + this.ONSConfig.dPadX = this.ONSConfig.dPadSize / 2 + this.ONSConfig.safeArea; + this.ONSConfig.dPadY = ONSControls._controlsCanvas.screen.height - (this.ONSConfig.dPadSize / 2 + this.ONSConfig.safeArea); + this.ONSConfig.bumpersOffsetX = 16; + this.ONSConfig.bumpersOffsetY = ONSControls._controlsCanvas.vh(0.30); + this.ONSConfig.bumpersWidth = ONSControls._controlsCanvas.vh(0.188) * this.ONSConfig.buttonsScale; + this.ONSConfig.bumpersHeight = ONSControls._controlsCanvas.vh(0.12) * this.ONSConfig.buttonsScale; + this.ONSConfig.LBX = this.ONSConfig.bumpersOffsetX + this.ONSConfig.safeArea + this.ONSConfig.bumpersWidth / 2; + this.ONSConfig.LBY = (this.ONSConfig.bumpersOffsetY + this.ONSConfig.safeArea + this.ONSConfig.bumpersHeight / 2); + this.ONSConfig.RBX = ONSControls._controlsCanvas.screen.width - (this.ONSConfig.safeArea + this.ONSConfig.bumpersOffsetX + this.ONSConfig.bumpersWidth / 2); + this.ONSConfig.RBY = (this.ONSConfig.bumpersOffsetY + this.ONSConfig.safeArea + this.ONSConfig.bumpersHeight / 2); + this.ONSConfig.additionalOffset = ONSControls._controlsCanvas.vh(0.03); + this.ONSConfig.additonalSize = ONSControls._controlsCanvas.vh(0.06) * this.ONSConfig.buttonsScale; + this.ONSConfig.showX = ONSControls._controlsCanvas.screen.width - (this.ONSConfig.additonalSize / 2 + this.ONSConfig.safeArea); + this.ONSConfig.showY = ONSControls._controlsCanvas.screen.height - (this.ONSConfig.additonalSize / 2 + this.ONSConfig.safeArea); + this.applyData(ConfigManager); + this.ONSConfig.updateData(); + VirtualGamepad.clearState(); let needsRestore = confirm(LanguageManager.languageData().text.System.plugins.optionsMenu.alertMessages["restoreGeneral"]); if (!!needsRestore) { DataManager._restoreGlobalInfo(); } }