Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function load(wdbPath, param, state) {
var handleWhenLoadWholeWDBFunc = param[4];
var handleWhenDoneFunc = param[3];
var handleBeforeStartLoopFunc = param[2];
var handleWhenLoadingFunc = param[1];
var fetchFunc = param[0];
var match = ConvertStreamSystem$Wonderjs.getDefault11ImageUint8ArrayData(/* () */0);
return Most.flatMap((function (image) {
return Most.fromPromise(fetchFunc(wdbPath).then((function (response) {
var match = !response.ok;
if (match) {
var status = response.status;
var statusText = response.statusText;
return Log$WonderLog.fatal(Log$WonderLog.buildFatalMessage("streamLoad", "" + (String(status) + (" " + (String(statusText) + ""))), "", "", ""));
} else {
var match$1 = !FetchCommon$Wonderjs.isSupportStreamLoad(response);
if (match$1) {
return _handleNotSupportStreamLoad(response, wdbPath, /* tuple */[
handleWhenLoadingFunc,
handleWhenLoadWholeWDBFunc
], state);
} else {
return _streamLoad(response, /* tuple */[
wdbPath,
function _createWorkerLoopStream() {
return Most.continueWith((function () {
return _createWorkerLoopStream(/* () */0);
}), Most.flatMap((function (time) {
var state = _computeElapseTime(time, StateDataMainService$Wonderjs.unsafeGetState(StateDataMain$Wonderjs.stateData));
return Most.map((function () {
return /* () */0;
}), WorkerJobMainService$Wonderjs.getMainLoopJobStream(StateDataMain$Wonderjs.stateData, /* tuple */[
WorkerJobHandleSystem$Wonderjs.createMainLoopJobHandleMap,
WorkerJobHandleSystem$Wonderjs.getMainLoopJobHandle
], state));
}), WonderMostAnimationFrame.nextAnimationFrame()));
}
function convertGLTFToGLB(jsZipBlob, createJsZipFunc) {
var gltfJson = /* record */[/* contents */undefined];
var outerDataMap = MutableHashMapService$WonderCommonlib.createEmpty(/* () */0);
return Most.drain(Most.flatMap((function (zip) {
var streamArr = /* array */[];
Zip$WonderBsJszip.forEach(zip, (function (relativePath, zipEntry) {
var extName = FileNameService$WonderEditor.getExtName(relativePath);
if (extName === "") {
return /* () */0;
} else {
var exit = 0;
switch (extName) {
case ".gltf" :
ArrayService$WonderEditor.push(Most.fromPromise(ZipObject$WonderBsJszip.asyncString(zipEntry, undefined, /* () */0).then((function (content) {
gltfJson[0] = Caml_option.some(JSON.parse(content));
return Promise.resolve(/* () */0);
}))), streamArr);
return /* () */0;
case ".bin" :
case ".jpeg" :
function loadSceneWDB(dispatchFunc, $$event) {
DomHelper$WonderEditor.preventDefault($$event);
var wdbInfo = ArrayService$WonderEditor.getFirst(Js_dict.values($$event.target.files).map(AssetTreeNodeUtils$WonderEditor.convertFileJsObjectToFileInfoRecord));
Most.drain(Most.flatMap(handleSceneWdb, Most.flatMap((function (wdbInfo) {
return Most.fromPromise(new Promise((function (resolve, _) {
var reader = new FileReader();
Curry._2(FileReader$WonderEditor.onload, reader, (function (result) {
return resolve(/* record */[
/* name */wdbInfo[/* name */0],
/* type_ */AssetTreeNodeUtils$WonderEditor.getUploadFileType(wdbInfo[/* name */0]),
/* result */result
]);
}));
return AssetTreeNodeUtils$WonderEditor.readFileByTypeSync(reader, wdbInfo);
})));
}), Most.just(wdbInfo)))).then((function () {
Curry._1(dispatchFunc, [
AppStore$WonderEditor.SceneTreeAction,
/* SetSceneGraph */[StateLogicService$WonderEditor.getStateToGetData(SceneTreeUtils$WonderEditor.getSceneGraphDataFromEngine)]
]);
function _fileLoad(dispatchFunc, $$event) {
DomHelper$WonderEditor.preventDefault($$event);
var fileInfoArr = Js_dict.values($$event.target.files).map(AssetTreeNodeUtils$WonderEditor.convertFileJsObjectToFileInfoRecord);
return Most.drain(Most.flatMap((function (fileResult) {
return Most.fromPromise(AssetTreeNodeUtils$WonderEditor.handleFileByType(fileResult));
}), Most.flatMap((function (fileInfo) {
return Most.fromPromise(new Promise((function (resolve, _) {
var reader = new FileReader();
Curry._2(FileReader$WonderEditor.onload, reader, (function (result) {
return resolve(/* record */[
/* name */fileInfo[/* name */0],
/* type_ */AssetTreeNodeUtils$WonderEditor.getUploadFileType(fileInfo[/* type_ */1]),
/* result */result
]);
}));
return AssetTreeNodeUtils$WonderEditor.readFileByType(reader, fileInfo);
})));
}), Most.from(fileInfoArr)))).then((function () {
return Promise.resolve(Curry._1(dispatchFunc, [
AppStore$WonderEditor.UpdateAction,
/* Update */[/* array */[/* Asset */2]]
]));
function _createWorkerLoopStream(param) {
return Most.continueWith((function (param) {
return _createWorkerLoopStream(/* () */0);
}), Most.flatMap((function (time) {
var state = _computeElapseTime(time, StateDataMainService$Wonderjs.unsafeGetState(StateDataMain$Wonderjs.stateData));
return Most.map((function (e) {
return /* () */0;
}), WorkerJobMainService$Wonderjs.getMainLoopJobStream(StateDataMain$Wonderjs.stateData, /* tuple */[
WorkerJobHandleSystem$Wonderjs.createMainLoopJobHandleMap,
WorkerJobHandleSystem$Wonderjs.getMainLoopJobHandle
], state));
}), WonderMostAnimationFrame.nextAnimationFrame()));
}
function loadSABAndSetToState(sabRelativePath, wholeManifest, param) {
var fetchFunc = param[4];
var cacheAssetBundleArrayBufferFunc = param[3];
var getAssetBundleArrayBufferCacheFunc = param[2];
var isAssetBundleArrayBufferCachedFunc = param[1];
var getAssetBundlePathFunc = param[0];
return Most.flatMap((function (sabRelativePath) {
var state = StateDataMainService$Wonderjs.unsafeGetState(StateDataMain$Wonderjs.stateData);
var wholeDependencyRelationMap = ParseABSystem$Wonderjs.WAB[/* getWholeDependencyRelationMap */4](wholeManifest);
var match = OperateSABAssetBundleMainService$Wonderjs.isLoaded(sabRelativePath, state);
if (match) {
return Most.empty();
} else {
return Most.map((function (param) {
return /* () */0;
}), Most.tap((function (sab) {
var state = StateDataMainService$Wonderjs.unsafeGetState(StateDataMain$Wonderjs.stateData);
StateDataMainService$Wonderjs.setState(StateDataMain$Wonderjs.stateData, OperateSABAssetBundleMainService$Wonderjs.setLoadedSAB(sabRelativePath, sab, OperateSABAssetBundleMainService$Wonderjs.markLoaded(sabRelativePath, state)));
return /* () */0;
}), loadAB(sabRelativePath, wholeManifest, wholeDependencyRelationMap, /* tuple */[
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
getAssetBundleArrayBufferCacheFunc,
function importPackage(dispatchFunc, $$event) {
var editorState = StateEditorService$WonderEditor.getState(/* () */0);
var match = StateEditorService$WonderEditor.getIsRun(/* () */0);
if (match) {
return _handleIsRun(dispatchFunc, editorState);
} else {
EventHelper$WonderEditor.preventDefault($$event);
var match$1 = ArrayService$WonderEditor.getFirst(Js_dict.values($$event.target.files));
if (match$1 !== undefined) {
var fileInfo = FileReader$WonderEditor.convertFileJsObjectToFileInfoRecord(Caml_option.valFromOption(match$1));
return Most.drain(Most.flatMap((function (fileResult) {
return _import(fileResult[/* result */2]);
}), Most.fromPromise(new Promise((function (resolve, reject) {
return _readFile(fileInfo, resolve);
}))))).then((function (param) {
StackHistoryService$WonderEditor.clearAllStack(AllStateData$WonderEditor.getHistoryState(/* () */0));
StateEngineService$WonderEditor.unsafeGetState(/* () */0);
StateEditorService$WonderEditor.getState(/* () */0);
return Promise.resolve(_dispatch(dispatchFunc));
}));
} else {
return new Promise((function (resolve, reject) {
return resolve(Curry._1(dispatchFunc, [
AppStore$WonderEditor.UpdateAction,
/* Update */[/* array */[/* NoUpdate */0]]
]));
}));
function _loadData(useWorker, sceneGraphArrayBuffer, fetchFunc, createZipStream) {
return Most.flatMap((function (zip) {
return Most.fromPromise(loadAndWriteConfigData(useWorker, fetchFunc, zip));
}), Most.flatMap((function (zip) {
return Most.fromPromise(loadAndWriteResData(fetchFunc, zip));
}), Most.flatMap((function (zip) {
return Most.fromPromise(loadAndWriteIndexJsData(useWorker, fetchFunc, zip));
}), Most.flatMap((function (zip) {
return Most.fromPromise(loadAndWriteIndexHtmlData(useWorker, sceneGraphArrayBuffer, fetchFunc, zip));
}), createZipStream))));
}