Prepping save file support
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
display: none !important;
|
||||
}
|
||||
</style>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js" integrity="sha512-a+SUDuwNzXDvz4XrIcXHuCf089/iJAoN4lmrXJg18XnduKK6YlDHNRalv4yd1N40OKI80tFidF+rqTFKGPoWFQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -85,6 +86,29 @@
|
||||
clearInterval(initInterval);
|
||||
}
|
||||
|
||||
const md5File = async path => {
|
||||
const buffer = EJS_emulator.gameManager.FS.readFile(path);
|
||||
const hash = await crypto.subtle.digest('SHA-256', buffer);
|
||||
const hashArray = Array.from(new Uint8Array(hash));
|
||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
return hashHex;
|
||||
}
|
||||
|
||||
const emulatorSave = async () => {
|
||||
// First, we get the currently saved MD5 hash of all files in the save
|
||||
// directory
|
||||
const contents = EJS_emulator.gameManager.FS.readdir('/homeplay/saves').filter(f => !f.startsWith('.'));
|
||||
const hashes = await Promise.all(contents.map(f => md5File(`/homeplay/saves/${f}`)));
|
||||
EJS_emulator.gameManager.saveSaveFiles();
|
||||
const newHashes = await Promise.all(contents.map(f => md5File(`/homeplay/saves/${f}`)));
|
||||
const changedFiles = contents.filter((f, i) => hashes[i] !== newHashes[i]);
|
||||
console.log('Changed files', changedFiles);
|
||||
|
||||
send({
|
||||
message: ''
|
||||
})
|
||||
}
|
||||
|
||||
const send = data => {
|
||||
window.parent.postMessage(data, '*');
|
||||
}
|
||||
@ -107,6 +131,10 @@
|
||||
EJS_emulator.setVolume(data.volume);
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
emulatorSave();
|
||||
break;
|
||||
|
||||
default:
|
||||
console.error('Unknown message', message);
|
||||
}
|
||||
@ -142,11 +170,11 @@
|
||||
}
|
||||
|
||||
EJS_onSaveState = () => {
|
||||
send({ message: 'save' });
|
||||
send({ message: 'save_state' });
|
||||
}
|
||||
|
||||
EJS_onLoadState = () => {
|
||||
send({ message: 'load' });
|
||||
send({ message: 'load_state' });
|
||||
}
|
||||
|
||||
EJS_onGameStart = () => {
|
||||
|
@ -18,15 +18,16 @@ type SendEmulatorMessageVolume = {
|
||||
|
||||
type SendEmulatorMessage = (
|
||||
SendEmulatorMessageInit |
|
||||
SendEmulatorMessageVolume
|
||||
SendEmulatorMessageVolume |
|
||||
{ message: 'save' }
|
||||
);
|
||||
|
||||
type ReceiveEmulatorMessage = (
|
||||
{ message: 'iframe_loaded' } |
|
||||
{ message: 'start' } |
|
||||
{ message: 'ready' } |
|
||||
{ message: 'save' } |
|
||||
{ message: 'load' }
|
||||
{ message: 'save_state' } |
|
||||
{ message: 'load_state' }
|
||||
);
|
||||
|
||||
export type EmulatorProps = {
|
||||
@ -69,8 +70,8 @@ export const Emulator:React.FC<EmulatorProps> = props => {
|
||||
|
||||
case 'start':
|
||||
case 'ready':
|
||||
case 'load':
|
||||
case 'save':
|
||||
case 'load_state':
|
||||
case 'save_state':
|
||||
break;
|
||||
default:
|
||||
console.error('Invalid message received:', msg);
|
||||
|
@ -7,12 +7,6 @@ import Error500, { Error500Props } from '../500';
|
||||
import { extendFragment, includeFragment } from '@/lib/fragment';
|
||||
import { Paginated, paginationQuery } from '@/lib/page';
|
||||
|
||||
type Game = {
|
||||
id: string;
|
||||
name: string;
|
||||
system: string;
|
||||
};
|
||||
|
||||
type PageProps = {
|
||||
games:Paginated<GameLight>|null;
|
||||
} | Error500Props;
|
||||
@ -21,7 +15,9 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async () => {
|
||||
try {
|
||||
const client = await apiClientGet();
|
||||
const res = await client.query<{ games:Paginated<GameLight> }>({
|
||||
variables: { },
|
||||
variables: {
|
||||
after: null,
|
||||
},
|
||||
query: gql`
|
||||
${includeFragment(GameLightFragment)}
|
||||
query getGames {
|
||||
|
Reference in New Issue
Block a user