Commit ef9e00da authored by rockyl's avatar rockyl

保存一波

parent 5df2db02
......@@ -101,6 +101,7 @@
"Create project": "创建项目",
"Rename project": "重命名项目",
"Entry scene view": "入口场景视图",
"Loading view": "加载视图",
"Page title": "页面标题",
"Container ID": "容器ID",
"Design width": "设计宽度",
......
......@@ -18,14 +18,12 @@ import {
} from "../../utils"
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"
import {preprocess} from "../../views/Preview/preview-preprocess"
import {packageStore} from "./package"
import {fetchApi} from "../../api/common"
import {toZeroing} from "psd-parse-web"
import {arrayFind} from "element-ui/src/utils/util";
......@@ -35,6 +33,7 @@ const psStoreName = 'pack-history';
const defaultOptions = {
pageTitle: 'no title',
entrySceneView: '',
loadingView: '',
containerId: 'game-container',
designWidth: 750,
designHeight: 1334,
......@@ -143,9 +142,7 @@ export const projectStore = {
let explicitDepAssets;
for (let view of state.data.views) {
if (view.implicitDepAssets) {
view.implicitDepAssets.splice(0);
}else{
if (!view.implicitDepAssets) {
Vue.set(view, 'implicitDepAssets', []);
}
if (view.explicitDepAssets) {
......@@ -165,7 +162,6 @@ export const projectStore = {
let uuid = prop.replace(assetScheme, '');
let asset = assets.find(asset => asset.uuid === uuid);
if (asset) {
//Vue.set(asset.dep, view.uuid, view.implicitAsset.includes(uuid) ? 2 : 1);
if (!explicitDepAssets.includes(asset.uuid)){
explicitDepAssets.push(asset.uuid);
}
......@@ -915,7 +911,8 @@ export const projectStore = {
//if (!debug) {
packedAssets = await packAssetsGroups(state.data.views, state.data.assets);
//}
/*const packResult = await projectApi.pack(state.id, debug, packedAssets);
console.log(packedAssets);
const packResult = await projectApi.pack(state.id, debug, packedAssets);
console.log(packResult);
......@@ -927,7 +924,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();
......@@ -989,15 +986,6 @@ async function uploadFiles(files) {
}
}
async function getSheetUrlByUUID(uuid) {
const response = await fetchApi('/api/uuid2url', {
params: {uuid},
errMessage: 'Failed to get url',
});
return response.url
}
export async function updateMock(mocks) {
await db.clear('mock');
for (let mock of mocks) {
......
......@@ -5,53 +5,84 @@
import {packImages} from "./sheet-pack";
import {editorApi} from "../api";
import generateUUID from "uuid/v4";
import {fetchApi} from "../api/common";
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;
for (let depAsset of depAssets) {
if (!depCountingMap.hasOwnProperty(depAsset)) {
depCountingMap[depAsset] = [];
}
depCountingMap[depAsset]++;
depCountingMap[depAsset].push(view.uuid);
}
}
console.log(depCountingMap);
let assetsGroups = {
common: [],
};
for (let asset of assets) {
let depCountingViews = depCountingMap[asset.uuid];
if (!depCountingViews) {
continue;
}
let depCounting = depCountingViews.length;
if (depCounting > 0) {
if (depCounting > 1) { //依赖引用数大于1则放入通用分组
assetsGroups.common.push(asset);
} else {
let depView = depCountingViews[0];
if (!assetsGroups.hasOwnProperty(depView)) {
assetsGroups[depView] = [];
}
assetsGroups[depView].push(asset);
}
}
}
let ps = [];
for (let key in assetsGroups) {
let group = assetsGroups[key];
ps.push(packAssets(key, group));
}
const groups = await Promise.all(ps);
for (let group of groups) {
assetsGroups[group.key] = group.assets;
}
return assetsGroups;
}
async function packAssets(assets) {
let failedList = [];
async function getSheetUrlByUUID(uuid) {
const response = await fetchApi('/api/uuid2url', {
params: {uuid},
errMessage: 'Failed to get url',
});
return response.url
}
async function packAssets(key, assets) {
let newAssets = assets.concat();
if (assets.length === 0) {
return {
key,
assets,
};
}
let failedList = [];
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 => {
uploadSheet(asset).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();
......@@ -61,5 +92,26 @@ async function packAssets(assets) {
})
}));
return newAssets;
return {
key,
assets: newAssets,
};
}
async function uploadSheet(asset) {
const {url} = await editorApi.uploadFile(asset.file, true);
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);
asset.url = sheetConfigUrl;
asset.uuid = generateUUID();
delete asset.file;
delete asset.frames;
delete asset.sheetUUID;
}
......@@ -14,6 +14,19 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item prop="loadingView" :label="$t('Loading view')">
<el-select v-model="editData.loadingView">
<el-option
:value="''"
:label="'空'"
></el-option>
<el-option v-for="(view, index) in project.data.views"
:key="index"
:value="view.name"
:label="view.name"
></el-option>
</el-select>
</el-form-item>
<el-form-item prop="containerId" :label="$t('Container ID')">
<el-input v-model="editData.containerId"/>
</el-form-item>
......
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