mirror of
https://github.com/Shu-Ying/main_plugin_farm.git
synced 2026-10-31 23:09:58 +08:00
fixed # 新增本地部署脚本,一键生成对应平台的压缩包内容
This commit is contained in:
@@ -98,9 +98,10 @@ def details_text(rows, page, pages):
|
||||
|
||||
|
||||
def render_details(renderer, identity, snapshot, now, page,
|
||||
theme='default', image_format='AUTO', avatar=None):
|
||||
theme='default', image_format='AUTO', avatar=None,
|
||||
quality=75):
|
||||
rows, pages = detail_rows(renderer, identity, snapshot, now, page)
|
||||
options = RenderOptions(format=image_format, quality=85, theme=theme)
|
||||
options = RenderOptions(format=image_format, quality=quality, theme=theme)
|
||||
farm = renderer.render(identity, snapshot, now, options, avatar)
|
||||
height = 922 + max(1, len(rows))*92
|
||||
canvas = Canvas.new((1024, height), '#ac713c')
|
||||
@@ -166,6 +167,7 @@ def render_details(renderer, identity, snapshot, now, page,
|
||||
text(navigation, 40, footer, 22, width=940)
|
||||
codec = options.codec(('JPEG',))
|
||||
content = canvas.encode(codec, options.quality, options.method)
|
||||
logger.info('farm details page=%s pages=%s rows=%s bytes=%s codec=%s',
|
||||
page, pages, len(rows), len(content), codec)
|
||||
logger.info('farm details page=%s pages=%s rows=%s bytes=%s codec=%s '
|
||||
'quality=%s', page, pages, len(rows), len(content), codec,
|
||||
options.quality)
|
||||
return content
|
||||
|
||||
@@ -68,11 +68,12 @@ class RenderService:
|
||||
return await self._run_function(self.renderer.render, *args)
|
||||
|
||||
async def seed_shop(self, plants, account, page, pages,
|
||||
image_format='AUTO'):
|
||||
image_format='AUTO', quality=75):
|
||||
if self._closed:
|
||||
raise RuntimeError('Render service closed')
|
||||
key = 'shop:' + hashlib.sha256(
|
||||
repr((plants, account, page, pages, image_format)).encode(),
|
||||
repr((plants, account, page, pages, image_format,
|
||||
quality)).encode(),
|
||||
).hexdigest()
|
||||
task = self._pending.get(key)
|
||||
if task is None:
|
||||
@@ -80,7 +81,7 @@ class RenderService:
|
||||
raise RuntimeError('Render queue full')
|
||||
task = asyncio.create_task(self._run_function(
|
||||
render_shop, self.renderer, plants, account, page, pages,
|
||||
image_format,
|
||||
image_format, quality,
|
||||
))
|
||||
self._pending[key] = task
|
||||
|
||||
@@ -93,11 +94,11 @@ class RenderService:
|
||||
return await asyncio.shield(task)
|
||||
|
||||
async def farm_details(self, identity, snapshot, now, page, theme,
|
||||
image_format='AUTO', avatar=None):
|
||||
image_format='AUTO', avatar=None, quality=75):
|
||||
if self._closed:
|
||||
raise RuntimeError('Render service closed')
|
||||
key = 'details:' + hashlib.sha256(repr((
|
||||
identity, snapshot, now, page, theme, image_format, avatar,
|
||||
identity, snapshot, now, page, theme, image_format, avatar, quality,
|
||||
)).encode()).hexdigest()
|
||||
task = self._pending.get(key)
|
||||
if task is None:
|
||||
@@ -105,7 +106,7 @@ class RenderService:
|
||||
raise RuntimeError('Render queue full')
|
||||
task = asyncio.create_task(self._run_function(
|
||||
render_details, self.renderer, identity, snapshot, now,
|
||||
page, theme, image_format, avatar,
|
||||
page, theme, image_format, avatar, quality,
|
||||
))
|
||||
self._pending[key] = task
|
||||
|
||||
@@ -118,11 +119,11 @@ class RenderService:
|
||||
return await asyncio.shield(task)
|
||||
|
||||
async def warehouse(self, rows, snapshot, kind, page, pages,
|
||||
image_format='AUTO', high=False):
|
||||
image_format='AUTO', high=False, quality=75):
|
||||
if self._closed:
|
||||
raise RuntimeError('Render service closed')
|
||||
key = ('warehouse', rows, snapshot, kind, page, pages,
|
||||
image_format, high)
|
||||
image_format, high, quality)
|
||||
cached = self.renderer.results.get(key)
|
||||
if cached is not None:
|
||||
return cached
|
||||
@@ -132,7 +133,7 @@ class RenderService:
|
||||
raise RuntimeError('Render queue full')
|
||||
task = asyncio.create_task(self._run_function(
|
||||
render_warehouse, self.renderer, rows, snapshot, kind,
|
||||
page, pages, image_format, high,
|
||||
page, pages, image_format, high, quality,
|
||||
))
|
||||
self._pending[key] = task
|
||||
|
||||
|
||||
@@ -30,8 +30,9 @@ def duration(seconds):
|
||||
) if value) or '0秒'
|
||||
|
||||
|
||||
def render_shop(renderer, plants, account, page, pages, image_format='AUTO'):
|
||||
options = RenderOptions(format=image_format, quality=80)
|
||||
def render_shop(renderer, plants, account, page, pages, image_format='AUTO',
|
||||
quality=75):
|
||||
options = RenderOptions(format=image_format, quality=quality)
|
||||
codec = options.codec()
|
||||
canvas = Canvas(renderer.assets.image('webgl/shop-board.png', (1024, 1536)))
|
||||
|
||||
@@ -94,6 +95,7 @@ def render_shop(renderer, plants, account, page, pages, image_format='AUTO'):
|
||||
navigation += f' 上一页:种子商店 {page-1}'
|
||||
text(navigation, (263, 1420), 23, width=510)
|
||||
content = canvas.encode(codec, options.quality, options.method)
|
||||
logger.info('farm shop render width=%s height=%s bytes=%s codec=%s',
|
||||
*canvas.image.size, len(content), codec)
|
||||
logger.info('farm shop render width=%s height=%s bytes=%s codec=%s '
|
||||
'quality=%s', *canvas.image.size, len(content), codec,
|
||||
options.quality)
|
||||
return content
|
||||
|
||||
@@ -110,9 +110,10 @@ def warehouse_text(rows, snapshot, kind, page, pages):
|
||||
|
||||
|
||||
def render_warehouse(renderer, rows, snapshot, kind, page, pages,
|
||||
image_format='AUTO', high=False):
|
||||
image_format='AUTO', high=False, quality=75):
|
||||
options = RenderOptions(width=1024 if high else 768,
|
||||
format=image_format, quality=85 if high else 70)
|
||||
format=image_format,
|
||||
quality=max(85, quality) if high else quality)
|
||||
codec = options.codec()
|
||||
scale = options.width/1024
|
||||
s = lambda n: round(n*scale)
|
||||
|
||||
Reference in New Issue
Block a user