Commit 5df2db02 authored by rockyl's avatar rockyl

保存一波

parent 4a590bd4
......@@ -19,6 +19,7 @@ import {
import {template} from "../../template"
import events from "@/global-events"
import {packImages} from "../../utils/sheet-pack"
import {packAssetsGroups} from "../../utils/assets-pack"
import {addBehavior, deleteProcessMeta,} from "./behavior"
import db from "../../utils/db-storage"
......@@ -138,27 +139,18 @@ export const projectStore = {
updateMock(localData.mock);
},
updateAssetDep(state) {
console.log('updateAssetDep');
let assets = state.data.assets;
let explicitDepAssets;
/*for (let asset of assets) {
if (asset.dep) {
let keys = Object.keys(asset.dep);
for (let key of keys) {
Vue.delete(asset.dep, key);
}
} else {
Vue.set(asset, 'dep', {});
}
}*/
for (let view of state.data.views) {
if (!view.implicitDepAssets) {
if (view.implicitDepAssets) {
view.implicitDepAssets.splice(0);
}else{
Vue.set(view, 'implicitDepAssets', []);
}
if (!view.explicitDepAssets) {
if (view.explicitDepAssets) {
view.explicitDepAssets.splice(0);
}else{
Vue.set(view, 'explicitDepAssets', []);
}
explicitDepAssets = view.explicitDepAssets;
......@@ -921,9 +913,9 @@ export const projectStore = {
let debug = params.debug;
let packedAssets;
//if (!debug) {
packedAssets = await packAssets(state.data.assets);
packedAssets = await packAssetsGroups(state.data.views, state.data.assets);
//}
const packResult = await projectApi.pack(state.id, debug, packedAssets);
/*const packResult = await projectApi.pack(state.id, debug, packedAssets);
console.log(packResult);
......@@ -935,7 +927,7 @@ export const projectStore = {
packResult: {tpl, tplUrl},
remark: params.remark,
});
return packResult;
return packResult;*/
},
async getPackHistory({state}) {
return (await db.getAll(psStoreName, state.id, 'pid')).reverse();
......@@ -1006,46 +998,6 @@ async function getSheetUrlByUUID(uuid) {
return response.url
}
async function packAssets(assets) {
let failedList = [];
let newAssets = assets.concat();
await packImages(newAssets, {getSheetUrlByUUID});
await Promise.all(newAssets.map(asset => {
return new Promise(async (resolve, reject) => {
try {
if (asset.file) {
const {url} = await editorApi.uploadFile(asset.file, true).catch(e => {
failedList.push(asset);
});
let sheetConfig = {
file: url,
type: 'sheet',
frames: asset.frames,
};
let sheetConfigFile = new File([JSON.stringify(sheetConfig)], 'sheet.json', {type: 'plain/text'});
const {url: sheetConfigUrl} = await editorApi.uploadFile(sheetConfigFile, false, asset.sheetUUID).catch(e => {
failedList.push(asset)
});
asset.url = sheetConfigUrl;
asset.uuid = generateUUID();
delete asset.file;
delete asset.frames;
delete asset.sheetUUID;
}
resolve();
} catch (e) {
reject(e);
}
})
}));
return newAssets;
}
export async function updateMock(mocks) {
await db.clear('mock');
for (let mock of mocks) {
......
/**
* Created by rockyl on 2020-04-29.
*/
import {packImages} from "./sheet-pack";
import {editorApi} from "../api";
import generateUUID from "uuid/v4";
export async function packAssetsGroups(views, assets) {
for(let asset of assets){
}
let depCountingMap = {};
for (let view of views) {
const {explicitDepAssets, implicitDepAssets} = view;
let depAssets = [...explicitDepAssets, ...implicitDepAssets];
for(let depAsset of depAssets){
if(!depCountingMap.hasOwnProperty(depAsset)){
depCountingMap[depAsset] = 0;
}
depCountingMap[depAsset]++;
}
}
console.log(depCountingMap);
}
async function packAssets(assets) {
let failedList = [];
let newAssets = assets.concat();
await packImages(newAssets, {getSheetUrlByUUID});
await Promise.all(newAssets.map(asset => {
return new Promise(async (resolve, reject) => {
try {
if (asset.file) {
const {url} = await editorApi.uploadFile(asset.file, true).catch(e => {
failedList.push(asset);
});
let sheetConfig = {
file: url,
type: 'sheet',
frames: asset.frames,
};
let sheetConfigFile = new File([JSON.stringify(sheetConfig)], 'sheet.json', {type: 'plain/text'});
const {url: sheetConfigUrl} = await editorApi.uploadFile(sheetConfigFile, false, asset.sheetUUID).catch(e => {
failedList.push(asset)
});
asset.url = sheetConfigUrl;
asset.uuid = generateUUID();
delete asset.file;
delete asset.frames;
delete asset.sheetUUID;
}
resolve();
} catch (e) {
reject(e);
}
})
}));
return newAssets;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment