Commit ef9e00da authored by rockyl's avatar rockyl

保存一波

parent 5df2db02
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
"Create project": "创建项目", "Create project": "创建项目",
"Rename project": "重命名项目", "Rename project": "重命名项目",
"Entry scene view": "入口场景视图", "Entry scene view": "入口场景视图",
"Loading view": "加载视图",
"Page title": "页面标题", "Page title": "页面标题",
"Container ID": "容器ID", "Container ID": "容器ID",
"Design width": "设计宽度", "Design width": "设计宽度",
......
...@@ -18,14 +18,12 @@ import { ...@@ -18,14 +18,12 @@ import {
} from "../../utils" } from "../../utils"
import {template} from "../../template" import {template} from "../../template"
import events from "@/global-events" import events from "@/global-events"
import {packImages} from "../../utils/sheet-pack"
import {packAssetsGroups} from "../../utils/assets-pack" import {packAssetsGroups} from "../../utils/assets-pack"
import {addBehavior, deleteProcessMeta,} from "./behavior" import {addBehavior, deleteProcessMeta,} from "./behavior"
import db from "../../utils/db-storage" import db from "../../utils/db-storage"
import {preprocess} from "../../views/Preview/preview-preprocess" import {preprocess} from "../../views/Preview/preview-preprocess"
import {packageStore} from "./package" import {packageStore} from "./package"
import {fetchApi} from "../../api/common"
import {toZeroing} from "psd-parse-web" import {toZeroing} from "psd-parse-web"
import {arrayFind} from "element-ui/src/utils/util"; import {arrayFind} from "element-ui/src/utils/util";
...@@ -35,6 +33,7 @@ const psStoreName = 'pack-history'; ...@@ -35,6 +33,7 @@ const psStoreName = 'pack-history';
const defaultOptions = { const defaultOptions = {
pageTitle: 'no title', pageTitle: 'no title',
entrySceneView: '', entrySceneView: '',
loadingView: '',
containerId: 'game-container', containerId: 'game-container',
designWidth: 750, designWidth: 750,
designHeight: 1334, designHeight: 1334,
...@@ -143,9 +142,7 @@ export const projectStore = { ...@@ -143,9 +142,7 @@ export const projectStore = {
let explicitDepAssets; let explicitDepAssets;
for (let view of state.data.views) { for (let view of state.data.views) {
if (view.implicitDepAssets) { if (!view.implicitDepAssets) {
view.implicitDepAssets.splice(0);
}else{
Vue.set(view, 'implicitDepAssets', []); Vue.set(view, 'implicitDepAssets', []);
} }
if (view.explicitDepAssets) { if (view.explicitDepAssets) {
...@@ -165,7 +162,6 @@ export const projectStore = { ...@@ -165,7 +162,6 @@ export const projectStore = {
let uuid = prop.replace(assetScheme, ''); let uuid = prop.replace(assetScheme, '');
let asset = assets.find(asset => asset.uuid === uuid); let asset = assets.find(asset => asset.uuid === uuid);
if (asset) { if (asset) {
//Vue.set(asset.dep, view.uuid, view.implicitAsset.includes(uuid) ? 2 : 1);
if (!explicitDepAssets.includes(asset.uuid)){ if (!explicitDepAssets.includes(asset.uuid)){
explicitDepAssets.push(asset.uuid); explicitDepAssets.push(asset.uuid);
} }
...@@ -915,7 +911,8 @@ export const projectStore = { ...@@ -915,7 +911,8 @@ export const projectStore = {
//if (!debug) { //if (!debug) {
packedAssets = await packAssetsGroups(state.data.views, state.data.assets); 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); console.log(packResult);
...@@ -927,7 +924,7 @@ export const projectStore = { ...@@ -927,7 +924,7 @@ export const projectStore = {
packResult: {tpl, tplUrl}, packResult: {tpl, tplUrl},
remark: params.remark, remark: params.remark,
}); });
return packResult;*/ return packResult;
}, },
async getPackHistory({state}) { async getPackHistory({state}) {
return (await db.getAll(psStoreName, state.id, 'pid')).reverse(); return (await db.getAll(psStoreName, state.id, 'pid')).reverse();
...@@ -989,15 +986,6 @@ async function uploadFiles(files) { ...@@ -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) { export async function updateMock(mocks) {
await db.clear('mock'); await db.clear('mock');
for (let mock of mocks) { for (let mock of mocks) {
......
...@@ -5,37 +5,101 @@ ...@@ -5,37 +5,101 @@
import {packImages} from "./sheet-pack"; import {packImages} from "./sheet-pack";
import {editorApi} from "../api"; import {editorApi} from "../api";
import generateUUID from "uuid/v4"; import generateUUID from "uuid/v4";
import {fetchApi} from "../api/common";
export async function packAssetsGroups(views, assets) { export async function packAssetsGroups(views, assets) {
for(let asset of assets){
}
let depCountingMap = {}; let depCountingMap = {};
for (let view of views) { for (let view of views) {
const {explicitDepAssets, implicitDepAssets} = view; const {explicitDepAssets, implicitDepAssets} = view;
let depAssets = [...explicitDepAssets, ...implicitDepAssets]; let depAssets = [...explicitDepAssets, ...implicitDepAssets];
for(let depAsset of depAssets){ for (let depAsset of depAssets) {
if(!depCountingMap.hasOwnProperty(depAsset)){ if (!depCountingMap.hasOwnProperty(depAsset)) {
depCountingMap[depAsset] = 0; depCountingMap[depAsset] = [];
}
depCountingMap[depAsset].push(view.uuid);
}
}
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);
}
}
} }
depCountingMap[depAsset]++;
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;
} }
console.log(depCountingMap);
return assetsGroups;
} }
async function packAssets(assets) { async function getSheetUrlByUUID(uuid) {
let failedList = []; 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(); let newAssets = assets.concat();
if (assets.length === 0) {
return {
key,
assets,
};
}
let failedList = [];
await packImages(newAssets, {getSheetUrlByUUID}); await packImages(newAssets, {getSheetUrlByUUID});
await Promise.all(newAssets.map(asset => { await Promise.all(newAssets.map(asset => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
if (asset.file) { if (asset.file) {
const {url} = await editorApi.uploadFile(asset.file, true).catch(e => { uploadSheet(asset).catch(e => {
failedList.push(asset); failedList.push(asset);
}); });
}
resolve();
} catch (e) {
reject(e);
}
})
}));
return {
key,
assets: newAssets,
};
}
async function uploadSheet(asset) {
const {url} = await editorApi.uploadFile(asset.file, true);
let sheetConfig = { let sheetConfig = {
file: url, file: url,
type: 'sheet', type: 'sheet',
...@@ -43,23 +107,11 @@ async function packAssets(assets) { ...@@ -43,23 +107,11 @@ async function packAssets(assets) {
}; };
let sheetConfigFile = new File([JSON.stringify(sheetConfig)], 'sheet.json', {type: 'plain/text'}); let sheetConfigFile = new File([JSON.stringify(sheetConfig)], 'sheet.json', {type: 'plain/text'});
const {url: sheetConfigUrl} = await editorApi.uploadFile(sheetConfigFile, false, asset.sheetUUID).catch(e => { const {url: sheetConfigUrl} = await editorApi.uploadFile(sheetConfigFile, false, asset.sheetUUID);
failedList.push(asset)
});
asset.url = sheetConfigUrl; asset.url = sheetConfigUrl;
asset.uuid = generateUUID(); asset.uuid = generateUUID();
delete asset.file; delete asset.file;
delete asset.frames; delete asset.frames;
delete asset.sheetUUID; delete asset.sheetUUID;
}
resolve();
} catch (e) {
reject(e);
}
})
}));
return newAssets;
} }
...@@ -14,6 +14,19 @@ ...@@ -14,6 +14,19 @@
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </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-form-item prop="containerId" :label="$t('Container ID')">
<el-input v-model="editData.containerId"/> <el-input v-model="editData.containerId"/>
</el-form-item> </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