Add experimental vibration touch feedback on mobile
parent
77e70a6540
commit
1e4e0d013e
|
@ -77,6 +77,8 @@ export default class BattleScene extends Phaser.Scene {
|
|||
public gameSpeed: integer = 1;
|
||||
public showLevelUpStats: boolean = true;
|
||||
public windowType: integer = 1;
|
||||
public enableTouchControls: boolean = false;
|
||||
public enableVibration: boolean = false;
|
||||
public quickStart: boolean = quickStart;
|
||||
public finalWave: integer = 200;
|
||||
|
||||
|
@ -910,19 +912,24 @@ export default class BattleScene extends Phaser.Scene {
|
|||
if (this.blockInput)
|
||||
return;
|
||||
let inputSuccess = false;
|
||||
if (this.isButtonPressed(Button.UP))
|
||||
let vibrationLength = 0;
|
||||
if (this.isButtonPressed(Button.UP)) {
|
||||
inputSuccess = this.ui.processInput(Button.UP);
|
||||
else if (this.isButtonPressed(Button.DOWN))
|
||||
vibrationLength = 5;
|
||||
} else if (this.isButtonPressed(Button.DOWN)) {
|
||||
inputSuccess = this.ui.processInput(Button.DOWN);
|
||||
else if (this.isButtonPressed(Button.LEFT))
|
||||
vibrationLength = 5;
|
||||
} else if (this.isButtonPressed(Button.LEFT)) {
|
||||
inputSuccess = this.ui.processInput(Button.LEFT);
|
||||
else if (this.isButtonPressed(Button.RIGHT))
|
||||
vibrationLength = 5;
|
||||
} else if (this.isButtonPressed(Button.RIGHT)) {
|
||||
inputSuccess = this.ui.processInput(Button.RIGHT);
|
||||
else if (this.isButtonPressed(Button.ACTION))
|
||||
vibrationLength = 5;
|
||||
} else if (this.isButtonPressed(Button.ACTION))
|
||||
inputSuccess = this.ui.processInput(Button.ACTION);
|
||||
else if (this.isButtonPressed(Button.CANCEL))
|
||||
else if (this.isButtonPressed(Button.CANCEL)) {
|
||||
inputSuccess = this.ui.processInput(Button.CANCEL);
|
||||
else if (this.isButtonPressed(Button.MENU)) {
|
||||
} else if (this.isButtonPressed(Button.MENU)) {
|
||||
switch (this.ui.getMode()) {
|
||||
case Mode.MESSAGE:
|
||||
if (!(this.ui.getHandler() as MessageUiHandler).pendingPrompt)
|
||||
|
@ -938,12 +945,14 @@ export default class BattleScene extends Phaser.Scene {
|
|||
case Mode.CONFIRM:
|
||||
case Mode.GAME_MODE_SELECT:
|
||||
this.ui.setOverlayMode(Mode.MENU);
|
||||
inputSuccess = true;
|
||||
break;
|
||||
case Mode.MENU:
|
||||
case Mode.SETTINGS:
|
||||
case Mode.ACHIEVEMENTS:
|
||||
this.ui.revertMode();
|
||||
this.playSound('select');
|
||||
inputSuccess = true;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
@ -959,8 +968,7 @@ export default class BattleScene extends Phaser.Scene {
|
|||
inputSuccess = this.ui.processInput(Button.CYCLE_ABILITY);
|
||||
else
|
||||
return;
|
||||
}
|
||||
else if (this.isButtonPressed(Button.SPEED_UP)) {
|
||||
} else if (this.isButtonPressed(Button.SPEED_UP)) {
|
||||
if (this.gameSpeed < 5) {
|
||||
this.gameData.saveSetting(Setting.Game_Speed, settingOptions[Setting.Game_Speed].indexOf(`${this.gameSpeed}x`) + 1);
|
||||
if (this.ui.getMode() === Mode.SETTINGS)
|
||||
|
@ -983,6 +991,8 @@ export default class BattleScene extends Phaser.Scene {
|
|||
return;
|
||||
} else
|
||||
return;
|
||||
if (inputSuccess && this.enableVibration)
|
||||
navigator.vibrate(vibrationLength || 10);
|
||||
this.blockInput = true;
|
||||
this.time.delayedCall(Utils.fixedInt(250), () => this.blockInput = false);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ export enum Setting {
|
|||
SE_Volume = "SE_VOLUME",
|
||||
Show_Stats_on_Level_Up = "SHOW_LEVEL_UP_STATS",
|
||||
Window_Type = "WINDOW_TYPE",
|
||||
Touch_Controls = "TOUCH_CONTROLS"
|
||||
Touch_Controls = "TOUCH_CONTROLS",
|
||||
Vibration = "VIBRATION"
|
||||
}
|
||||
|
||||
export interface SettingOptions {
|
||||
|
@ -26,7 +27,8 @@ export const settingOptions: SettingOptions = {
|
|||
[Setting.SE_Volume]: new Array(11).fill(null).map((_, i) => i ? (i * 10).toString() : 'Mute'),
|
||||
[Setting.Show_Stats_on_Level_Up]: [ 'Off', 'On' ],
|
||||
[Setting.Window_Type]: new Array(4).fill(null).map((_, i) => (i + 1).toString()),
|
||||
[Setting.Touch_Controls]: [ 'Auto', 'Disabled' ]
|
||||
[Setting.Touch_Controls]: [ 'Auto', 'Disabled' ],
|
||||
[Setting.Vibration]: [ 'Auto', 'Disabled' ]
|
||||
};
|
||||
|
||||
export const settingDefaults: SettingDefaults = {
|
||||
|
@ -36,7 +38,8 @@ export const settingDefaults: SettingDefaults = {
|
|||
[Setting.SE_Volume]: 10,
|
||||
[Setting.Show_Stats_on_Level_Up]: 1,
|
||||
[Setting.Window_Type]: 0,
|
||||
[Setting.Touch_Controls]: 0
|
||||
[Setting.Touch_Controls]: 0,
|
||||
[Setting.Vibration]: 0
|
||||
};
|
||||
|
||||
export function setSetting(scene: BattleScene, setting: Setting, value: integer): boolean {
|
||||
|
@ -63,9 +66,13 @@ export function setSetting(scene: BattleScene, setting: Setting, value: integer)
|
|||
updateWindowType(scene, parseInt(settingOptions[setting][value]));
|
||||
break;
|
||||
case Setting.Touch_Controls:
|
||||
scene.enableTouchControls = settingOptions[setting][value] !== 'Disabled' && hasTouchscreen();
|
||||
const touchControls = document.getElementById('touchControls');
|
||||
if (touchControls)
|
||||
touchControls.classList.toggle('visible', settingOptions[setting][value] !== 'Disabled' && hasTouchscreen());
|
||||
touchControls.classList.toggle('visible', scene.enableTouchControls);
|
||||
break;
|
||||
case Setting.Vibration:
|
||||
scene.enableVibration = settingOptions[setting][value] !== 'Disabled' && hasTouchscreen();
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue