@@ -32,6 +32,7 @@ import { UndoManager } from "./manager/undo";
32
32
import { formatTilesetName } from "./util/format" ;
33
33
34
34
import "./styles/global.css" ;
35
+ import { AssetManager } from "./manager/asset" ;
35
36
36
37
const STANDARD_THEME = "standard" ;
37
38
const LIGHT_THEME = "light" ;
@@ -83,6 +84,7 @@ document.addEventListener("DOMContentLoaded", async () => {
83
84
let animationManager = new AnimationManager ( ) ;
84
85
let undoManager = new UndoManager ( ) ;
85
86
let gameStorage = new BrowserGameStorage ( ) ;
87
+ let assetManager = new AssetManager ( document . querySelector ( ".loader-wrapper" ) as HTMLElement ) ;
86
88
// Store unlockable statuses so that their unlock messages don't display again if player achieved the same conditions again
87
89
let unlockedClassic = false ;
88
90
let unlockedInitialCommit = false ;
@@ -438,7 +440,9 @@ document.addEventListener("DOMContentLoaded", async () => {
438
440
}
439
441
const welcomeText = document . querySelector ( ".classic-welcome-text" ) as HTMLElement ;
440
442
const scoreLabel = document . querySelector ( ".score-box > .score-label" ) as HTMLElement ;
441
- const highscoreLabel = document . querySelector ( ".highscore-box > .score-label" ) as HTMLElement ;
443
+ const highscoreLabel = document . querySelector (
444
+ ".highscore-box > .score-label"
445
+ ) as HTMLElement ;
442
446
if ( selectedTheme === CLASSIC_THEME ) {
443
447
welcomeText . style . display = "block" ;
444
448
classicTimeout = setTimeout ( ( ) => {
@@ -886,8 +890,6 @@ document.addEventListener("DOMContentLoaded", async () => {
886
890
( document . querySelector ( "link[rel='canonical']" ) as HTMLLinkElement ) . href =
887
891
import . meta. env . VITE_WEBSITE_URL || "https://coteh.github.io/2048-clone/" ;
888
892
889
- ( document . querySelector ( ".loader-wrapper" ) as HTMLElement ) . style . display = "none" ;
890
-
891
893
Sentry . onLoad ( ( ) => {
892
894
Sentry . init ( {
893
895
release : `2048-clone@${ GAME_VERSION } ` ,
@@ -924,13 +926,21 @@ document.addEventListener("DOMContentLoaded", async () => {
924
926
posthog . capture ( "game open" , { version : GAME_VERSION } ) ;
925
927
926
928
try {
929
+ await assetManager . loadAssets ( [
930
+ "/images/CheckerboardTiles.png" ,
931
+ "/images/Checkbox_unchecked.png" ,
932
+ "/images/Checkbox_checked.png" ,
933
+ ] ) ;
934
+
935
+ ( document . querySelector ( ".loader-wrapper" ) as HTMLElement ) . style . display = "none" ;
936
+
927
937
await initGame ( eventHandler , spawnManager , animationManager , undoManager , gameStorage ) ;
928
938
} catch ( e : any ) {
929
939
if ( typeof Sentry !== "undefined" ) Sentry . captureException ( e ) ;
930
940
const elem = createDialogContentFromTemplate ( "#error-dialog-content" ) ;
931
941
const errorContent = elem . querySelector ( ".error-text" ) as HTMLElement ;
932
942
933
- console . error ( "Unknown error occurred " , e ) ;
943
+ console . error ( "Could not initialize game due to error: " , e ) ;
934
944
errorContent . innerText = e . message ;
935
945
936
946
renderDialog ( elem , true , false ) ;
0 commit comments