Skip to content

Commit

Permalink
perf: steam设置每行个数
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Nov 24, 2024
1 parent 8f86d12 commit ce68d52
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 41 deletions.
12 changes: 6 additions & 6 deletions apps/achievement.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const rule = {
name: achievementsByGame.gameName,
appid
}],
column: 2
size: 'large'
}
]
if (regRet[1] === '成就') {
Expand Down Expand Up @@ -80,13 +80,13 @@ export const rule = {
title: '已完成成就',
desc: `共${completeAchievements.length}个`,
games: completeAchievements,
column: 2
size: 'large'
},
{
title: '未完成成就',
desc: `共${unCompleteAchievements.length}个`,
games: unCompleteAchievements,
column: 2
size: 'large'
}
)
} else if (regRet[1] === '统计') {
Expand All @@ -112,7 +112,7 @@ export const rule = {
title: '已完成统计',
desc: `共${completeStats.length}个`,
games: completeStats,
column: 2
size: 'large'
}
)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ export const rule = {
name: achievementsByGame.gameName,
appid
}],
column: 2
size: 'large'
}
]
const games = []
Expand All @@ -171,7 +171,7 @@ export const rule = {
title: '全球成就统计',
desc: `共${games.length}个`,
games: _.orderBy(games, 'percent', 'desc'),
column: 2
size: 'large'
})
const img = await Render.render('inventory/index', { data })
if (img) {
Expand Down
2 changes: 1 addition & 1 deletion apps/discounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const rule = {
for (const item of items) {
const key = {
title: item.title,
column: 2,
size: 'large',
games: []
}
for (const i of res[item.key].items) {
Expand Down
6 changes: 3 additions & 3 deletions apps/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const rule = {
const screenshotOptions = {
title: '',
games: [],
column: 3,
size: 'small',
desc: ''
}
if (e.msg.includes('近')) {
Expand Down Expand Up @@ -73,7 +73,7 @@ export const rule = {
}
screenshotOptions.title = `${nickname} 愿望单共有 ${wishlist.length} 个游戏`
screenshotOptions.games = _.orderBy(wishlist, 'date_added', 'desc')
screenshotOptions.column = 2
screenshotOptions.size = 'large'
} else {
const games = await api.IPlayerService.GetOwnedGames(steamId)
if (!games.length) {
Expand All @@ -83,7 +83,7 @@ export const rule = {
screenshotOptions.games = _.orderBy(games, 'playtime_forever', 'desc')
screenshotOptions.title = `${nickname} 库存共有 ${games.length} 个游戏`
}
if (screenshotOptions.column === 3) {
if (screenshotOptions.size === 'small') {
let playtimeForever = 0
let playtime2weeks = 0
screenshotOptions.games.map(i => {
Expand Down
6 changes: 3 additions & 3 deletions apps/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const rule = {
title: `群${e.group_id}推送列表`,
desc: `共${list.length}个推送用户`,
games: userList,
column: 3
size: 'small'
}]
const img = await Render.render('inventory/index', { data })
if (img) {
Expand Down Expand Up @@ -149,13 +149,13 @@ export const rule = {
title: '正在玩游戏的群友',
desc: `共${playing.length}个`,
games: playing,
column: 3
size: 'small'
},
{
title: '没有在玩游戏的群友',
desc: `共${notPlaying.length}个`,
games: notPlaying,
column: 3
size: 'small'
}
]
const img = await Render.render('inventory/index', { data })
Expand Down
2 changes: 1 addition & 1 deletion apps/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const rule = {
const screenshotOptions = {
title: `${name} 搜索结果`,
games,
column: 2
size: 'large'
}
const img = await Render.render('inventory/index', { data: [screenshotOptions] })
if (img) {
Expand Down
11 changes: 10 additions & 1 deletion components/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ const Render = {
pageGotoParams: {
waitUntil: 'networkidle0' // +0.5s
},
hiddenLength: Config.other.hiddenLength,
...params
}
if (path === 'inventory/index') {
data.hiddenLength = Config.other.hiddenLength
const minLength = Math.min(
Math.max(...params.data.map(i => i.games.length)),
Math.max(1, Number(Config.other.itemLength) || 1)
)
const size = params.data.findIndex(i => i.size === 'large') >= 0 ? 370 : 300
const len = minLength === 1 ? (size === 370 ? 1 : 1.4) : minLength
data.style = `<style>\n#container,.games{\nwidth: ${len * size}px;\n}\n</style>`
}
return await puppeteer.screenshot(path, data)
},
async simpleRender (path, params) {
Expand Down
3 changes: 3 additions & 0 deletions config/default_config/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ renderScale: 130
# 截图时数量达到多少时隐藏剩余项目
# 比如库存有几千个游戏,截图时只截取游玩最多的前99个,那么后面的游戏就隐藏了
hiddenLength: 99

# 截图时每行显示的最大数量
itemLength: 3
9 changes: 9 additions & 0 deletions models/setting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export const cfgSchema = {
def: 99,
input: (n) => Math.max(1, n * 1 || 99),
desc: '比如库存等超过设置的长度后会隐藏剩余的游戏, 避免太多而导致截图失败'
},
itemLength: {
title: '每行最多显示数量',
key: '每行个数',
type: 'number',
min: 1,
def: 3,
input: (n) => Math.max(1, n * 1 || 3),
desc: '截图时每行最多显示的数量'
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions models/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ export function startTimer () {
data.push({
title: '开始玩游戏的群友',
games: i.start,
column: 2
size: 'large'
})
}
if (i.end.length) {
data.push({
title: '结束玩游戏的群友',
games: i.end,
column: 2
size: 'large'
})
}
if (!data.length) {
Expand Down
32 changes: 17 additions & 15 deletions resources/inventory/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
display: flex;
flex-direction: column;
align-items: center;
width: 900px;
}

.header {
Expand All @@ -14,7 +13,6 @@
display: flex;
justify-content: space-around;
flex-wrap: wrap;
width: 890px;
}

.games>div {
Expand All @@ -26,11 +24,11 @@
margin-bottom: 10px;
}

.column-2 {
width: 440px;
.size-large {
width: 360px;
}

.column-3 {
.size-small {
width: 290px;
}

Expand All @@ -55,29 +53,33 @@
height: 60px;
}

.column-2-info {
width: 200px;
.size-large-info {
width: 150px;
margin-right: 10px;
}

.column-3-info {
.size-small-info {
width: 150px;
}

.column-2-info-noprice {
width: 260px;
.size-large-info-noprice {
width: 210px;
}

.column-3-info-noprice {
.size-small-info-noprice {
width: 200px;
}

.column-full {
width: 350px;
.size-large-square {
width: 270px;
}

.size-full {
width: 300px;
}

.column-full-noimg {
width: 410px;
.size-full-noimg {
width: 360px;
}

.overflow {
Expand Down
23 changes: 14 additions & 9 deletions resources/inventory/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@

{{block 'css'}}
<link rel="stylesheet" type="text/css" href="{{pluResPath}}inventory/index.css" />
{{@ style}}
{{/block}}

{{block 'main'}}
{{each data item}}
<% const isHidden = item.games.length > hiddenLength %>
<!-- TODO: 放到Render中处理 -->
<% const isHidden=item.games.length> hiddenLength %>

<div class="header">
<h2>{{item.title}}</h2>
<h4 class="header-desc">
{{item.desc}}
{{if isHidden}}
<br/>
<% const len = item.games.length - hiddenLength %>
太多辣 ! 已隐藏{{len}}个项目
{{/if}}
<br />
<% const len=item.games.length - hiddenLength %>
太多辣 ! 已隐藏{{len}}个项目
{{/if}}
</h4>
</div>
<div class="games">
<% item.games.length = isHidden ? hiddenLength : item.games.length %>
<% item.games.length=isHidden ? hiddenLength : item.games.length %>
{{each item.games i}}
<div class="column-{{item.column}}">
<div class="size-{{item.size}}">
<div class="header-img">
{{if i.header_image}}
<img src="{{i.header_image}}" class="{{i.header_image_class || 'rectangle'}}">
{{else if !i.noImg}}
<img src="https://steamcdn-a.akamaihd.net/steam/{{i.header_image_type || 'apps'}}/{{i.appid}}/header.jpg">
<img
src="https://steamcdn-a.akamaihd.net/steam/{{i.header_image_type || 'apps'}}/{{i.appid}}/header.jpg">
{{/if}}
</div>
<!-- TODO: 待重构 屎一样 -->
<div
class="game-info overflow column-{{item.column}}-info{{!i.price? '-noprice' :''}} {{(!i.price && item.column === 2 ) ? `column-full${i.noImg ? '-noimg' : ''}` : '' }}">
class="game-info overflow size-{{item.size}}-info{{!i.price? '-noprice' :''}} {{(!i.price && item.size === 'large' ) ? `size-full${i.noImg ? '-noimg' : ''}` : '' }} {{(i.header_image_class === 'square' && item.size === 'large' && !i.price) ? 'size-large-square' : ''}}">
<div class="game-title">
{{i.name || ''}}
</div>
Expand Down

0 comments on commit ce68d52

Please sign in to comment.