From 22d4484293df5099530f7ef38f4f91a9dcf106a8 Mon Sep 17 00:00:00 2001 From: nextfu Date: Sun, 12 Apr 2020 16:56:00 +0800 Subject: [PATCH] add cache panel --- index.html | 39 ++++++++++++++++++++++++++++++++++--- libs/js/cc-console-utils.js | 13 +++++-------- preview.js | 31 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 6cb90fd..f9f0371 100644 --- a/index.html +++ b/index.html @@ -47,6 +47,7 @@ mdi-cloud-search mdi-forum + mdi-table mdi-home @@ -146,12 +147,44 @@ + + + + {{ cacheTitle }} + + + + + + + + + + + + + + Close + + + + + + - - - \ No newline at end of file + \ No newline at end of file diff --git a/libs/js/cc-console-utils.js b/libs/js/cc-console-utils.js index 64458f2..aac2380 100644 --- a/libs/js/cc-console-utils.js +++ b/libs/js/cc-console-utils.js @@ -115,13 +115,12 @@ const initConsoleUtil = function () { }, 2000); return target; } - cc.total = function () { + cc.cache = function () { let rawCacheData = cc.loader._cache; let cacheData = []; let totalTextureSize = 0; for (let k in rawCacheData) { let item = rawCacheData[k]; - // console.log(item) if (item.type !== 'js' && item.type !== 'json') { let itemName = '_'; let preview = ''; @@ -151,19 +150,17 @@ const initConsoleUtil = function () { } } cacheData.push({ - // queueId: item.queueId, + queueId: item.queueId, type: item.type, name: itemName, - // preview: preview, + preview: preview, id: item.id, content: content, size: formatSize }); } } - // let cacheTitle = `缓存 [文件总数:${cacheData.length}][纹理缓存:${totalTextureSize.toFixed(2) + 'M'}]`; - // console.log(cacheTitle); - // console.table(cacheData); - return totalTextureSize.toFixed(2) + 'M'; + let cacheTitle = `缓存 [文件总数:${cacheData.length}][纹理缓存:${totalTextureSize.toFixed(2) + 'M'}]`; + return [cacheData, cacheTitle]; } } \ No newline at end of file diff --git a/preview.js b/preview.js index 42a9a7a..7c84b65 100644 --- a/preview.js +++ b/preview.js @@ -5,6 +5,20 @@ const app = new Vue({ }), data: { drawer: false, + cacheDialog: false, + cacheTitle: '', + cacheHeaders: [ + { text: 'Type', value: 'type' }, + { text: 'Name', value: 'name' }, + { text: 'Preivew', value: 'preview' }, + { text: 'ID', value: 'id' }, + { text: 'Content', value: 'content' }, + { text: 'Size', value: 'size' }, + ], + cacheRawData: [], + cacheData: [], + cacheSearchText: null, + cacheOnlyTexture: true, treeData: [], selectedNodes: [], intervalId: -1, @@ -18,6 +32,11 @@ const app = new Vue({ initConsoleUtil(); }); }, + watch: { + cacheOnlyTexture() { + this.updateCacheData(); + } + }, computed: { treeFilter() { return (item, search, textKey) => item[textKey].indexOf(search) > -1; @@ -116,6 +135,18 @@ const app = new Vue({ drawNodeRect() { cc.where(this.selectedNode); }, + updateCacheData() { + if (this.$data.cacheOnlyTexture) { + this.$data.cacheData = this.$data.cacheRawData.filter(item => item.content === 'cc.Texture2D'); + } else { + this.$data.cacheData = this.$data.cacheRawData; + } + }, + openCacheDialog() { + [this.$data.cacheRawData, this.$data.cacheTitle] = cc.cache(); + this.updateCacheData(); + this.$data.cacheDialog = true; + }, openGithub() { window.open('https://github.com/potato47/ccc-devtools'); },