Guest User

KDDL ALpha 4 Bootstrap.ts class

a guest
Aug 14th, 2021
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <reference path='../index.d.ts'/>
  2. import {ResourcesQueue} from "../resources/mainGame/ResourcesQueue";
  3. import {C} from "../C";
  4. import {RecamelCore} from "../../src.framework/net/retrocade/camel/core/RecamelCore";
  5. import {TStatePreloader} from "../game/states/TStatePreloader";
  6. import {DROD} from "../game/global/DROD";
  7. import {RecamelLang} from "../../src.framework/net/retrocade/camel/RecamelLang";
  8. import {Core} from "../game/global/Core";
  9. import {TStateInitialize} from "../game/states/TStateInitialize";
  10. import {PlatformOptions} from "../platform/PlatformOptions";
  11. import {Gfx} from "../game/global/Gfx";
  12. import {TStateTitle} from "../game/states/TStateTitle";
  13. import {Achievements} from "../game/achievements/Achievements";
  14. import {RecamelTooltip} from "../../src.framework/net/retrocade/camel/core/RecamelTooltip";
  15. import {Make} from "../game/global/Make";
  16. import {DrodInput} from "../game/global/DrodInput";
  17. import {TWidgetScroll} from "../game/widgets/TWidgetScroll";
  18. import {TWidgetLevelName} from "../game/widgets/TWidgetLevelName";
  19. import {TWidgetClock} from "../game/widgets/TWidgetClock";
  20. import {TWidgetMoveCounter} from "../game/widgets/TWidgetMoveCounter";
  21. import {Helper} from "../game/global/Helper";
  22. import {NutkaLayer} from "../../src.evidently_audio/NutkaLayer";
  23. import {Sfx} from "../game/global/Sfx";
  24. import {Progress} from "../game/global/Progress";
  25. import {RecamelSave} from "../../src.framework/net/retrocade/camel/core/RecamelSave";
  26. import {S} from "../S";
  27. import {TEffectTarSplatter} from "../game/objects/effects/TEffectTarSplatter";
  28. import {TEffectSwordSwing} from "../game/objects/effects/TEffectSwordSwing";
  29. import {TEffectBlood} from "../game/objects/effects/TEffectBlood";
  30. import {TEffectCheckpoint} from "../game/objects/effects/TEffectCheckpoint";
  31. import {TEffectDebris} from "../game/objects/effects/TEffectDebris";
  32. import {TEffectEvilEyeGaze} from "../game/objects/effects/TEffectEvilEyeGaze";
  33. import {TEffectOrbHit} from "../game/objects/effects/TEffectOrbHit";
  34. import {TEffectVermin} from "../game/objects/effects/TEffectVermin";
  35.  
  36. require('../assets/font/toms-new-roman.css');
  37.  
  38. export class Bootstrap {
  39.     public static async bootstrap(init: (musicLayer: NutkaLayer) => void) {
  40.         init(DROD.nutkaLayerMusic);
  41.  
  42.         RecamelLang.initialize();
  43.         RecamelSave.setStorage(S.saveStorageName);
  44.  
  45.         await Promise.all([
  46.             Bootstrap.loadPreloaderBackground(),
  47.             Bootstrap.loadLocale(),
  48.             Bootstrap.waitForFontsToLoad(),
  49.         ]);
  50.         await Bootstrap.initRecamel();
  51.         await Bootstrap.fadeOutPrePreloader();
  52.  
  53.         DROD.resize()
  54.         await Promise.all([
  55.             Bootstrap.startLoadingAllResources(),
  56.             Bootstrap.showPreloader(),
  57.         ]);
  58.         await Bootstrap.initCore();
  59.         await Bootstrap.unpackHold();
  60.         await Progress.loadFromDisk();
  61.         await Bootstrap.initializeGraphics();
  62.         await Bootstrap.initializeGameClasses();
  63.         await Bootstrap.showInitialize();
  64.         Bootstrap.startGame();
  65.     }
  66.  
  67.     private static async loadPreloaderBackground() {
  68.         await ResourcesQueue.loadResource(C.RES_PRELOADER_BG);
  69.     }
  70.  
  71.     private static async loadLocale() {
  72.         await Promise.all([
  73.             ResourcesQueue.loadResource(C.RES_LANG_CREDITS),
  74.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_EN),
  75.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_NL),
  76.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_DE),
  77.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_FI),
  78.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_ES),
  79.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_PT),
  80.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_FR),
  81.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_RU),
  82.             ResourcesQueue.loadResource(C.RES_LANG_COMMON_PL),
  83.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_EN),
  84.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_NL),
  85.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_DE),
  86.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_FI),
  87.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_ES),
  88.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_PT),
  89.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_FR),
  90.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_RU),
  91.             ResourcesQueue.loadResource(C.RES_LANG_HOLD_PL),
  92.         ]);
  93.  
  94.         const credits = ResourcesQueue.getText(C.RES_LANG_CREDITS);
  95.         RecamelLang.loadLanguageFile(credits, 'en');
  96.         RecamelLang.loadLanguageFile(credits, 'nl');
  97.         RecamelLang.loadLanguageFile(credits, 'de');
  98.         RecamelLang.loadLanguageFile(credits, 'fi');
  99.         RecamelLang.loadLanguageFile(credits, 'es');
  100.         RecamelLang.loadLanguageFile(credits, 'pt');
  101.         RecamelLang.loadLanguageFile(credits, 'fr');
  102.         RecamelLang.loadLanguageFile(credits, 'ru');
  103.         RecamelLang.loadLanguageFile(credits, 'pl');
  104.  
  105.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_EN), 'en');
  106.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_NL), 'nl');
  107.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_DE), 'de');
  108.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_FI), 'fi');
  109.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_ES), 'es');
  110.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_PT), 'pt');
  111.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_FR), 'fr');
  112.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_RU), 'ru');
  113.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_COMMON_PL), 'pl');
  114.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_EN), 'en');
  115.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_NL), 'nl');
  116.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_DE), 'de');
  117.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_FI), 'fi');
  118.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_ES), 'es');
  119.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_PT), 'pt');
  120.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_FR), 'fr');
  121.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_RU), 'ru');
  122.         RecamelLang.loadLanguageFile(ResourcesQueue.getText(C.RES_LANG_HOLD_PL), 'pl');
  123.     }
  124.  
  125.     private static async waitForFontsToLoad() {
  126.         if ((document as any).fonts) {
  127.             await (document as any).fonts.ready;
  128.         } else {
  129.             // @todo add some other detection in the future or hope for the best
  130.         }
  131.  
  132.         document.getElementById('tomloader')!.remove();
  133.     }
  134.  
  135.     private static async initRecamel() {
  136.         RecamelCore.init(DROD.app, DROD.app.stage);
  137.     }
  138.  
  139.     private static async startLoadingAllResources() {
  140.         return ResourcesQueue.startLoadingAll();
  141.     }
  142.  
  143.     private static async fadeOutPrePreloader() {
  144.         const prepreloader = document.getElementById('prepreloader')!;
  145.         prepreloader.style.opacity = '0';
  146.         return new Promise<void>(resolve => {
  147.             setTimeout(() => {
  148.                 DROD.app.view.style.opacity = '1';
  149.                 prepreloader.remove();
  150.                 resolve();
  151.             }, 600);
  152.         });
  153.     }
  154.  
  155.     private static async showPreloader() {
  156.         return new Promise<void>(resolve => {
  157.             RecamelCore.setState(new TStatePreloader(resolve));
  158.             if (PlatformOptions.isDebug) {
  159.                 resolve();
  160.             }
  161.         });
  162.     }
  163.  
  164.     private static async initCore() {
  165.         Gfx.initialize();
  166.         Core.init();
  167.     }
  168.  
  169.     private static async unpackHold() {
  170.         Core.unpackHold(ResourcesQueue.getBinary(C.RES_HOLD));
  171.     }
  172.  
  173.     private static async initializeGameClasses() {
  174.         Achievements.init();
  175.         DrodInput.init();
  176.         RecamelTooltip.setBackground(Make.tooltipGrid9());
  177.         RecamelTooltip.setSize(14);
  178.         RecamelTooltip.setPadding(5, 10, 5, 10);
  179.         RecamelTooltip.setShadow(45, 4, 5, 1, 0.5, 0);
  180.         TWidgetScroll.init();
  181.         TWidgetLevelName.init();
  182.         TWidgetClock.init();
  183.         TWidgetMoveCounter.init();
  184.         Helper.init();
  185.         Sfx.initialize();
  186.     }
  187.  
  188.     private static async showInitialize() {
  189.         return new Promise<void>(resolve => {
  190.             RecamelCore.setState(new TStateInitialize(resolve));
  191.         });
  192.     }
  193.  
  194.     private static startGame() {
  195.         TStateTitle.show();
  196.     }
  197.  
  198.     private static async initializeGraphics() {
  199.         TEffectBlood.initialize();
  200.         TEffectCheckpoint.initialize();
  201.         TEffectDebris.initialize();
  202.         TEffectEvilEyeGaze.initialize();
  203.         TEffectOrbHit.initialize();
  204.         TEffectSwordSwing.initialize();
  205.         TEffectTarSplatter.initialize();
  206.         TEffectVermin.initialize();
  207.     }
  208. }
RAW Paste Data