MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / loadFromSlot

Function loadFromSlot

src/engine/persistence.ts:291–454  ·  view source on GitHub ↗
(engine: VisualNovelEngine, slot: string)

Source from the content-addressed store, hash-verified

289 * @param slot - The key with which the slot was saved on the storage
290 */
291export function loadFromSlot (engine: VisualNovelEngine, slot: string): Promise<void> {
292 document.body.style.cursor = 'wait';
293 engine.global ('playing', true);
294
295 engine.trigger ('willLoadGame');
296
297 return resetGame (engine).then (() => {
298 engine.hideScreens ();
299
300 return engine.Storage.get (slot).then ((rawData) => {
301 const data = rawData as LegacySaveData;
302 // @Compatibility [<= v1.4.1]
303 // Check if an older save format was used so we can transform
304 // that information into the new format.
305 if (typeof data.Engine !== 'undefined') {
306
307 // Set the game state
308 engine.state ({
309 step: data.Engine.Step,
310 label: data.Engine.Label,
311 scene: `show scene ${data.Engine.Scene}`,
312 });
313
314 // Retrieve if a song was playing so we can set it to the state
315 if (data.Engine.Song !== '' && typeof data.Engine.Song !== 'undefined') {
316 engine.state ({
317 music: [{ statement: data.Engine.Song, paused: false }],
318 });
319 }
320
321 // Retrieve if a sound was playing so we can set it to the state
322 if (data.Engine.Sound !== '' && typeof data.Engine.Sound !== 'undefined') {
323 engine.state ({
324 sound: [{ statement: data.Engine.Sound, paused: false }],
325 });
326 }
327
328 // Retrieve if particles were shown so we can set it to the state
329 if (data.Engine.Particles !== '' && typeof data.Engine.Particles !== 'undefined') {
330 engine.state ({
331 particles: `show particles ${data.Engine.Particles}`
332 });
333 }
334
335 // Check if there are images to be shown
336 if (data.Show !== '' && typeof data.Show !== 'undefined') {
337 const show = data.Show.split (',');
338
339 // For every image saved, add their element to the game
340 for (const element of show) {
341 if (element.trim () !== '') {
342 const div = document.createElement ('div');
343 div.innerHTML = element.replace ('img/', 'assets/');
344 if (div.firstChild) {
345 const item = $_(div.firstChild as HTMLElement);
346 const firstElement = item.get(0);
347 if (firstElement) {
348 if (element.indexOf ('data-character') > -1) {

Callers

nothing calls this directly

Calls 14

resetGameFunction · 0.85
migrateFunction · 0.85
globalMethod · 0.80
triggerMethod · 0.80
hideScreensMethod · 0.80
stateMethod · 0.80
replaceMethod · 0.80
historyMethod · 0.80
storageMethod · 0.80
labelMethod · 0.80
showScreenMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected