pokerogue/src/system/settings.ts

209 lines
7.3 KiB
TypeScript
Raw Normal View History

import i18next from "i18next";
2023-10-26 16:33:59 -04:00
import BattleScene from "../battle-scene";
2024-03-25 16:10:43 -04:00
import { hasTouchscreen } from "../touch-controls";
import { updateWindowType } from "../ui/ui-theme";
2024-02-06 16:15:35 -05:00
import { PlayerGender } from "./game-data";
import { Mode } from "#app/ui/ui";
import SettingsUiHandler from "#app/ui/settings-ui-handler";
2023-10-26 16:33:59 -04:00
export enum Setting {
Game_Speed = "GAME_SPEED",
Master_Volume = "MASTER_VOLUME",
BGM_Volume = "BGM_VOLUME",
2023-11-04 21:53:38 -04:00
SE_Volume = "SE_VOLUME",
Language = "LANGUAGE",
2024-03-01 00:27:46 -05:00
Damage_Numbers = "DAMAGE_NUMBERS",
UI_Theme = "UI_THEME",
2023-12-25 15:03:50 -05:00
Window_Type = "WINDOW_TYPE",
2024-02-13 18:42:11 -05:00
Tutorials = "TUTORIALS",
2024-04-04 15:22:05 -04:00
Enable_Retries = "ENABLE_RETRIES",
2024-02-24 21:16:19 -05:00
Sprite_Set = "SPRITE_SET",
2024-04-09 15:06:47 -04:00
Move_Animations = "MOVE_ANIMATIONS",
2024-04-04 15:22:05 -04:00
Show_Stats_on_Level_Up = "SHOW_LEVEL_UP_STATS",
2024-04-18 00:49:44 -04:00
EXP_Gains_Speed = "EXP_GAINS_SPEED",
HP_Bar_Speed = "HP_BAR_SPEED",
2024-03-05 21:54:26 -05:00
Fusion_Palette_Swaps = "FUSION_PALETTE_SWAPS",
2024-02-06 16:15:35 -05:00
Player_Gender = "PLAYER_GENDER",
2024-04-15 20:13:58 -04:00
Gamepad_Support = "GAMEPAD_SUPPORT",
Touch_Controls = "TOUCH_CONTROLS",
Vibration = "VIBRATION"
2023-10-26 16:33:59 -04:00
}
export interface SettingOptions {
[key: string]: string[]
}
export interface SettingDefaults {
[key: string]: integer
}
export const settingOptions: SettingOptions = {
[Setting.Game_Speed]: [ '1x', '1.25x', '1.5x', '2x', '2.5x', '3x', '4x', '5x' ],
[Setting.Master_Volume]: new Array(11).fill(null).map((_, i) => i ? (i * 10).toString() : 'Mute'),
[Setting.BGM_Volume]: new Array(11).fill(null).map((_, i) => i ? (i * 10).toString() : 'Mute'),
2023-11-04 21:53:38 -04:00
[Setting.SE_Volume]: new Array(11).fill(null).map((_, i) => i ? (i * 10).toString() : 'Mute'),
[Setting.Language]: [ 'English', 'Change' ],
2024-03-01 00:27:46 -05:00
[Setting.Damage_Numbers]: [ 'Off', 'Simple', 'Fancy' ],
[Setting.UI_Theme]: [ 'Default', 'Legacy' ],
[Setting.Window_Type]: new Array(5).fill(null).map((_, i) => (i + 1).toString()),
2024-02-13 18:42:11 -05:00
[Setting.Tutorials]: [ 'Off', 'On' ],
2024-04-04 15:22:05 -04:00
[Setting.Enable_Retries]: [ 'Off', 'On' ],
[Setting.Sprite_Set]: [ 'Consistent', 'Mixed Animated' ],
2024-04-09 15:06:47 -04:00
[Setting.Move_Animations]: [ 'Off', 'On' ],
2024-04-04 15:22:05 -04:00
[Setting.Show_Stats_on_Level_Up]: [ 'Off', 'On' ],
2024-04-18 00:49:44 -04:00
[Setting.EXP_Gains_Speed]: [ 'Normal', 'Fast', 'Faster', 'Skip' ],
[Setting.HP_Bar_Speed]: [ 'Normal', 'Fast', 'Faster', 'Instant' ],
2024-03-05 21:54:26 -05:00
[Setting.Fusion_Palette_Swaps]: [ 'Off', 'On' ],
2024-02-06 16:15:35 -05:00
[Setting.Player_Gender]: [ 'Boy', 'Girl' ],
2024-04-15 20:13:58 -04:00
[Setting.Gamepad_Support]: [ 'Auto', 'Disabled' ],
[Setting.Touch_Controls]: [ 'Auto', 'Disabled' ],
[Setting.Vibration]: [ 'Auto', 'Disabled' ]
2023-10-26 16:33:59 -04:00
};
export const settingDefaults: SettingDefaults = {
[Setting.Game_Speed]: 3,
2023-10-26 16:33:59 -04:00
[Setting.Master_Volume]: 5,
[Setting.BGM_Volume]: 10,
2023-11-04 21:53:38 -04:00
[Setting.SE_Volume]: 10,
[Setting.Language]: 0,
2024-03-01 00:27:46 -05:00
[Setting.Damage_Numbers]: 0,
[Setting.UI_Theme]: 0,
2023-12-25 15:08:51 -05:00
[Setting.Window_Type]: 0,
2024-02-13 18:42:11 -05:00
[Setting.Tutorials]: 1,
2024-04-04 15:22:05 -04:00
[Setting.Enable_Retries]: 0,
2024-02-24 21:16:19 -05:00
[Setting.Sprite_Set]: 0,
2024-04-09 15:06:47 -04:00
[Setting.Move_Animations]: 1,
2024-04-04 15:22:05 -04:00
[Setting.Show_Stats_on_Level_Up]: 1,
2024-04-18 00:49:44 -04:00
[Setting.EXP_Gains_Speed]: 0,
[Setting.HP_Bar_Speed]: 0,
2024-03-05 21:54:26 -05:00
[Setting.Fusion_Palette_Swaps]: 1,
2024-02-06 16:15:35 -05:00
[Setting.Player_Gender]: 0,
2024-04-15 22:40:27 -04:00
[Setting.Gamepad_Support]: 0,
[Setting.Touch_Controls]: 0,
[Setting.Vibration]: 0
2023-10-26 16:33:59 -04:00
};
export const reloadSettings: Setting[] = [ Setting.UI_Theme, Setting.Language, Setting.Sprite_Set ];
2023-10-26 16:33:59 -04:00
export function setSetting(scene: BattleScene, setting: Setting, value: integer): boolean {
switch (setting) {
case Setting.Game_Speed:
scene.gameSpeed = parseFloat(settingOptions[setting][value].replace('x', ''));
break;
case Setting.Master_Volume:
scene.masterVolume = value ? parseInt(settingOptions[setting][value]) * 0.01 : 0;
scene.updateSoundVolume();
break;
case Setting.BGM_Volume:
scene.bgmVolume = value ? parseInt(settingOptions[setting][value]) * 0.01 : 0;
scene.updateSoundVolume();
break;
case Setting.SE_Volume:
scene.seVolume = value ? parseInt(settingOptions[setting][value]) * 0.01 : 0;
scene.updateSoundVolume();
break;
2024-03-01 00:27:46 -05:00
case Setting.Damage_Numbers:
scene.damageNumbersMode = value;
break;
case Setting.UI_Theme:
scene.uiTheme = value;
break;
case Setting.Window_Type:
updateWindowType(scene, parseInt(settingOptions[setting][value]));
break;
2024-02-13 18:42:11 -05:00
case Setting.Tutorials:
scene.enableTutorials = settingOptions[setting][value] === 'On';
break;
2024-04-04 15:22:05 -04:00
case Setting.Enable_Retries:
scene.enableRetries = settingOptions[setting][value] === 'On';
break;
2024-02-24 21:16:19 -05:00
case Setting.Sprite_Set:
scene.experimentalSprites = !!value;
if (value)
scene.initExpSprites();
break;
2024-04-09 15:06:47 -04:00
case Setting.Move_Animations:
scene.moveAnimations = settingOptions[setting][value] === 'On';
break;
2024-04-04 15:22:05 -04:00
case Setting.Show_Stats_on_Level_Up:
scene.showLevelUpStats = settingOptions[setting][value] === 'On';
break;
2024-04-18 00:49:44 -04:00
case Setting.EXP_Gains_Speed:
scene.expGainsSpeed = value;
break;
case Setting.HP_Bar_Speed:
scene.hpBarSpeed = value;
break;
2024-03-05 21:54:26 -05:00
case Setting.Fusion_Palette_Swaps:
scene.fusionPaletteSwaps = !!value;
break;
2024-02-06 16:15:35 -05:00
case Setting.Player_Gender:
if (scene.gameData) {
const female = settingOptions[setting][value] === 'Girl';
scene.gameData.gender = female ? PlayerGender.FEMALE : PlayerGender.MALE;
scene.trainer.setTexture(scene.trainer.texture.key.replace(female ? 'm' : 'f', female ? 'f' : 'm'));
} else
return false;
break;
2024-04-15 20:13:58 -04:00
case Setting.Gamepad_Support:
scene.gamepadSupport = settingOptions[setting][value] !== 'Disabled';
break;
2023-12-25 15:03:50 -05:00
case Setting.Touch_Controls:
scene.enableTouchControls = settingOptions[setting][value] !== 'Disabled' && hasTouchscreen();
2023-12-25 15:03:50 -05:00
const touchControls = document.getElementById('touchControls');
if (touchControls)
touchControls.classList.toggle('visible', scene.enableTouchControls);
break;
case Setting.Vibration:
scene.enableVibration = settingOptions[setting][value] !== 'Disabled' && hasTouchscreen();
2023-12-25 15:03:50 -05:00
break;
case Setting.Language:
if (value) {
if (scene.ui) {
const cancelHandler = () => {
scene.ui.revertMode();
(scene.ui.getHandler() as SettingsUiHandler).setOptionCursor(Object.values(Setting).indexOf(Setting.Language), 0, true);
};
const changeLocaleHandler = (locale: string) => {
i18next.changeLanguage(locale);
localStorage.setItem('prLang', locale);
cancelHandler();
scene.reset(true, false, true);
};
scene.ui.setOverlayMode(Mode.OPTION_SELECT, {
options: [
{
label: 'English',
handler: () => changeLocaleHandler('en')
},
{
label: 'Spanish',
handler: () => changeLocaleHandler('es')
},
{
label: 'Italian',
handler: () => changeLocaleHandler('it')
},
{
label: 'French',
handler: () => changeLocaleHandler('fr')
},
{
label: 'German',
handler: () => changeLocaleHandler('de')
},
{
label: 'Cancel',
handler: () => cancelHandler()
}
]
});
return false;
}
}
break;
2023-10-26 16:33:59 -04:00
}
return true;
}