@@ -21,6 +21,8 @@ import { settingsStore } from "@stores/settings-store";
21
21
import { modelSetFileRefIds } from "@core/model-effects-configuration" ;
22
22
import { renderComposer } from "@render/render-composer" ;
23
23
import { loadDatFilesRemote } from "@ipc/files" ;
24
+ import { parseDDS } from "./formats/parse-dds" ;
25
+ import { b2ba } from "@utils/bin-utils" ;
24
26
25
27
if ( module . hot ) {
26
28
module . hot . accept ( "@core/model-effects-configuration" )
@@ -40,31 +42,39 @@ const setHDMipMaps = (hd: AnimAtlas, hd2: AnimAtlas) => {
40
42
41
43
export type Assets = Awaited < ReturnType < typeof initializeAssets > > & {
42
44
envMap ?: Texture ,
43
- bwDat : BwDAT
44
- } & Awaited < ReturnType < typeof generateAllIcons > > ;
45
+ bwDat : BwDAT ;
46
+ wireframeIcons ?: Blob [ ] ,
47
+ } & Partial < Awaited < ReturnType < typeof generateAllIcons > > > ;
45
48
46
49
export type UIStateAssets = Pick < Assets , "bwDat" | "gameIcons" | "cmdIcons" | "raceInsetIcons" | "workerIcons" | "wireframeIcons" > ;
47
50
51
+ const _hardfiles = [ ".glb" , ".hdr" , ".png" , ".exr" , ".js" , ".wasm" ] ;
52
+
48
53
export const initializeAssets = async ( directories : Settings [ "directories" ] ) => {
49
54
50
- electronFileLoader ( ( file : string ) => {
55
+ electronFileLoader ( ( file : string , directory : string ) => {
56
+
51
57
log . debug ( file ) ;
52
58
53
- if ( file . includes ( ".glb" ) || file . includes ( ".hdr" ) || file . includes ( ".png" ) || file . includes ( ".exr" ) ) {
54
- return fsPromises . readFile ( file ) ;
59
+ if ( file . startsWith ( "blob:" ) ) {
60
+
61
+ return fetch ( file ) . then ( r => r . arrayBuffer ( ) ) ;
62
+ }
63
+ if ( _hardfiles . some ( ( ext ) => file . endsWith ( ext ) ) ) {
64
+
65
+ const fullPath = path . join ( directory ?? "" , file ) ;
66
+ return file . endsWith ( ".js" ) ? fsPromises . readFile ( fullPath , { encoding : "utf-8" } ) : fsPromises . readFile ( fullPath ) . then ( buffer => buffer . buffer ) ;
67
+
55
68
} else {
69
+
56
70
return readCascFile ( file ) ;
71
+
57
72
}
73
+
58
74
} ) ;
59
75
60
76
await openCascStorage ( directories . starcraft ) ;
61
77
62
- loadDatFilesRemote ( ) . then ( dat => {
63
- setAsset ( "bwDat" , dat ) ;
64
- // preload some assets that will not be loaded otherwise?
65
- loadImageAtlas ( imageTypes . warpInFlash , dat ) ;
66
- } )
67
-
68
78
log . debug ( "@load-assets/images" ) ;
69
79
const sdAnimBuf = await readCascFile ( "SD/mainSD.anim" ) ;
70
80
const sdAnim = parseAnim ( sdAnimBuf ) ;
@@ -83,33 +93,22 @@ export const initializeAssets = async (directories: Settings["directories"]) =>
83
93
}
84
94
85
95
const minimapConsole = {
86
- clock : createDDSTexture ( await readCascFile ( "game/observer/UIObserverSquareRight.DDS" ) ) ,
87
- square : createDDSTexture ( await readCascFile ( "game/observer/UIObserverSquareFull.DDS" ) ) ,
96
+ clock : createDDSTexture ( parseDDS ( b2ba ( await readCascFile ( "game/observer/UIObserverSquareRight.DDS" ) ) ) ) ,
97
+ square : createDDSTexture ( parseDDS ( b2ba ( await readCascFile ( "game/observer/UIObserverSquareFull.DDS" ) ) ) ) ,
88
98
}
89
99
90
- log . debug ( "@load-assets/envmap" ) ;
91
100
const envEXRAssetFilename = path . join (
92
101
directories . assets ,
93
102
"envmap.exr"
94
103
)
95
104
const envMapFilename = await fileExists ( envEXRAssetFilename ) ? envEXRAssetFilename : path . join ( __static , "./envmap.hdr" )
105
+ log . debug ( `@load-assets/envmap: ${ envMapFilename } ` ) ;
96
106
loadEnvironmentMap ( envMapFilename ) . then ( tex => {
97
107
setAsset ( "envMap" , tex ) ;
98
-
108
+ renderComposer . getWebGLRenderer ( ) . initTexture ( tex ) ;
99
109
} ) ;
100
110
101
- generateAllIcons ( readCascFile ) . then ( icons => {
102
-
103
- setAsset ( "gameIcons" , icons . gameIcons ) ;
104
- setAsset ( "cmdIcons" , icons . cmdIcons ) ;
105
- setAsset ( "raceInsetIcons" , icons . raceInsetIcons ) ;
106
- setAsset ( "workerIcons" , icons . workerIcons ) ;
107
- setAsset ( "wireframeIcons" , icons . wireframeIcons ) ;
108
- setAsset ( "arrowIconsGPU" , icons . arrowIconsGPU ) ;
109
- setAsset ( "hoverIconsGPU" , icons . hoverIconsGPU ) ;
110
- setAsset ( "dragIconsGPU" , icons . dragIconsGPU ) ;
111
-
112
- } ) ;
111
+ const someIcons = await generateAllIcons ( readCascFile ) ;
113
112
114
113
const refId = ( id : number ) => {
115
114
if ( sdAnim ?. [ id ] ?. refId !== undefined ) {
@@ -141,10 +140,6 @@ export const initializeAssets = async (directories: Settings["directories"]) =>
141
140
const glbRefImageId = modelSetFileRefIds . get ( refImageId ) ?? refImageId
142
141
const settings = settingsStore ( ) . data . graphics . useHD2 as "auto" | "ignore" | "force" ;
143
142
144
- if ( imageId === imageTypes . warpInFlash ) {
145
- console . log ( imageId , refImageId ) ;
146
- }
147
-
148
143
let res = UnitTileScale . HD2 ;
149
144
if ( loadingHD . has ( refImageId ) ) {
150
145
@@ -218,8 +213,6 @@ export const initializeAssets = async (directories: Settings["directories"]) =>
218
213
219
214
}
220
215
221
-
222
-
223
216
log . debug ( "@load-assets/skybox" ) ;
224
217
const loader = new CubeTextureLoader ( ) ;
225
218
const rootPath = path . join ( __static , "/skybox/sparse" ) ;
@@ -236,8 +229,15 @@ export const initializeAssets = async (directories: Settings["directories"]) =>
236
229
"back.png" ,
237
230
] , res ) ) as CubeTexture ;
238
231
232
+ loadDatFilesRemote ( ) . then ( dat => {
233
+ setAsset ( "bwDat" , dat ) ;
234
+ // preload some assets that will not be loaded otherwise?
235
+ loadImageAtlas ( imageTypes . warpInFlash , dat ) ;
236
+ } )
237
+
239
238
const r = {
240
- remaining : 10 ,
239
+ remaining : 3 ,
240
+ ...someIcons ,
241
241
atlases,
242
242
selectionCircles : selectionCirclesHD ,
243
243
minimapConsole,
0 commit comments