Skip to content

Commit

Permalink
立繪性能優化
Browse files Browse the repository at this point in the history
  • Loading branch information
RimoChan committed Aug 15, 2020
1 parent ad37cc7 commit 48ef308
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions librian/librian本體/前端/dist/bundle.js

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions librian/librian本體/前端/src/psd處理.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PSD from 'psd.js'


psd緩存 = {}
圖層緩存 = {}
圖緩存 = {}

export default psd拆包 =
Expand All @@ -11,11 +12,14 @@ export default psd拆包 =
psd緩存[psd路徑] = await PSD.fromURL(psd路徑)
psd = psd緩存[psd路徑]

現層 = psd.tree().childrenAtPath(圖層名)[0]
return {
'位置': 現層.coords
'img': 現層.layer.image.toPng()
}
key = [psd路徑, 圖層名].toString()
if not 圖層緩存[key]
現層 = psd.tree().childrenAtPath(圖層名)[0]
圖層緩存[key] = {
'位置': 現層.coords
'img': 現層.layer.image.toPng()
}
return 圖層緩存[key]

獲取圖層組: (psd路徑, 圖層名組) ->
return (
Expand All @@ -24,7 +28,6 @@ export default psd拆包 =
)

圖層融合: (圖層組) ->
console.log 圖層組
m = 0

x = Math.max.apply(Math, (圖層.位置.right for 圖層 in 圖層組))
Expand All @@ -40,7 +43,6 @@ export default psd拆包 =
context.drawImage(圖層.img, left, top)

base64 = canvas.toDataURL('image/png')
console.log base64

return [極x, 極y, base64]

Expand Down
7 changes: 4 additions & 3 deletions librian/librian本體/前端/src/演出.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export default 演出 =
if this.當前人物組.indexOf(名字) == - 1
$('#立繪').append($("<div id='立繪--#{名字}'><div id='立繪--#{名字}--圖像'></div></div>"))
console.log "加入 #{名字}"
$("#立繪--#{名字}").attr('特效','淡入')

# 設定位置
for 立繪 in 立繪組
Expand All @@ -214,10 +213,12 @@ export default 演出 =
for 立繪 in 立繪組
if 立繪.使用png
png名 = "#{v.psd立繪路徑}/#{立繪.名字}.png"
psd處理.渲染png到div(png名, "立繪--#{立繪.名字}--圖像")
await psd處理.渲染png到div(png名, "立繪--#{立繪.名字}--圖像")
else
psd名 = "#{v.psd立繪路徑}/#{立繪.名字}.psd"
psd處理.渲染圖層組到div(psd名, 立繪.圖層, "立繪--#{立繪.名字}--圖像")
await psd處理.渲染圖層組到div(psd名, 立繪.圖層, "立繪--#{立繪.名字}--圖像")
if this.當前人物組.indexOf(立繪.名字) == -1
$("#立繪--#{立繪.名字}").attr('特效','淡入')

this.當前人物組 = 名字組

Expand Down

0 comments on commit 48ef308

Please sign in to comment.