Skip to content

Commit

Permalink
fix: clearing cheats fully in parsed view (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
thenick775 authored Feb 1, 2025
1 parent 0fad226 commit 392547b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gbajs3/src/components/modals/cheats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export const CheatsModal = () => {
label="Name"
error={!!errors?.cheats?.[index]?.desc}
size="small"
autoComplete="Name"
autoComplete="Cheat Name"
style={isLargerThanPhone ? { maxWidth: 100 } : undefined}
helperText={errors?.cheats?.[index]?.desc?.message}
{...register(`cheats.${index}.desc`, {
Expand Down
28 changes: 14 additions & 14 deletions gbajs3/src/emulator/mgba/mgba-emulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ export const mGBAEmulator = (mGBA: mGBAEmulatorTypeDef): GBAEmulator => {
return Object.values(assembledCheats) as ParsedCheats[];
};

const parsedCheatsToFile = (cheatsList: ParsedCheats[]) => {
const libretroCheats = cheatsList.map((cheat, idx) => {
return `cheat${idx}_desc = "${cheat.desc}"\ncheat${idx}_enable = ${cheat.enable}\ncheat${idx}_code = "${cheat.code}"\n`;
});
const header = `cheats = ${libretroCheats?.length}\n\n`;
const parsedCheatsToFile = (cheatsList: ParsedCheats[]): File | null => {
const cheatsFileName = filepathToFileName(mGBA.gameName, '.cheats');

if (libretroCheats?.length && cheatsFileName) {
const libretroCheatsFile = header + libretroCheats.join('\n');
const blob = new Blob([libretroCheatsFile], { type: 'text/plain' });

return new File([blob], cheatsFileName);
}

return null;
if (!cheatsFileName) return null;

const content = cheatsList.length
? `cheats = ${cheatsList.length}\n\n` +
cheatsList
.map(
({ desc, enable, code }, idx) =>
`cheat${idx}_desc = "${desc}"\ncheat${idx}_enable = ${enable}\ncheat${idx}_code = "${code}"`
)
.join('\n')
: '';

return new File([new Blob([content])], cheatsFileName);
};

// emscriptens SDL_Keycode differs a bit from browser keycode/key mappings
Expand Down

0 comments on commit 392547b

Please sign in to comment.