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 = () => {
|
||||
|
Reference in New Issue
Block a user