diff --git a/agent.py b/agent.py index 726ec08..fa749e2 100644 --- a/agent.py +++ b/agent.py @@ -27,8 +27,6 @@ from a2a_pack import ( RunContext, ) -ASSET_TYPES = ("character", "enemy", "item", "tile", "icon", "projectile") -STYLES = ("pixel", "flat", "outline", "neon") DB_OPTIONS = "-c statement_timeout=5000 -c lock_timeout=2000 -c idle_in_transaction_session_timeout=10000" DB_ENV_NAME = "DATABASE_URL" @@ -114,7 +112,6 @@ class GeneratesSvgVideoGame9jg9vdF0f510( style: Literal["pixel", "flat", "outline", "neon"] = "pixel", variant_count: Annotated[int, Field(ge=1, le=4)] = 1, ) -> SvgAssetResult: - """Create SVG game assets and save a DB receipt when production DB is configured.""" tenant = _tenant_key(ctx) clean_theme = _clean_text(theme, max_len=80) colors = _normalize_palette(palette) @@ -333,6 +330,10 @@ def _slugify(value: str) -> str: return slug or "game-asset" +def _scale(unit: float, n: float) -> str: + return f"{n * unit:.2f}" + + def _render_svg( *, asset_type: str, @@ -352,10 +353,6 @@ def _render_svg( title = html.escape(f"{theme} {asset_type} {style} variant {variant + 1}") label = html.escape(theme[:18]) pattern = int(seed[variant * 2 : variant * 2 + 2], 16) - - def px(n: float) -> str: - return f"{n * unit:.2f}" - bg_shape = ( f'' if style != "outline" @@ -363,58 +360,62 @@ def _render_svg( ) glow = "" if style == "neon": - glow = f'' - - body = _asset_body(asset_type, style, primary, accent, dark, stroke, px, pattern) - grid = "" + glow = '' + body = _asset_body(asset_type, style, primary, accent, dark, stroke, unit, pattern) + grid_parts: list[str] = [] if style == "pixel": - grid = "".join( - f'' - for i in range(5) - ) - + for i in range(5): + x = _scale(unit, (pattern + i * 3) % 14 + 1) + y = _scale(unit, (pattern // 3 + i * 5) % 14 + 1) + one = _scale(unit, 1) + grid_parts.append(f'') + filter_value = "url(#glow)" if style == "neon" else "none" return ( f'' f'{title}{glow}{bg_shape}' - f'{grid}{body}' + f'{"".join(grid_parts)}{body}' f'{label}' "" ) -def _asset_body(asset_type: str, style: str, primary: str, accent: str, dark: str, stroke: int, px: Any, pattern: int) -> str: +def _asset_body(asset_type: str, style: str, primary: str, accent: str, dark: str, stroke: int, unit: float, pattern: int) -> str: fill = "none" if style == "outline" else primary common = f'stroke="{dark}" stroke-width="{stroke}" stroke-linejoin="round" stroke-linecap="round"' + p = lambda n: _scale(unit, n) if asset_type == "character": return ( - f'' - f'' - f'' + f'' + f'' + f'' ) if asset_type == "enemy": - spikes = " ".join(f'{px(2 + i * 2)},{px(7 + ((pattern + i) % 3))}' for i in range(7)) + spike_points: list[str] = [] + for i in range(7): + spike_points.append(f'{p(2 + i * 2)},{p(7 + ((pattern + i) % 3))}') return ( - f'' - f'' - f'' + f'' + f'' + f'' ) if asset_type == "item": return ( - f'' - f'' + f'' + f'' ) if asset_type == "tile": - return "".join( - f'' - for x in (2, 5, 8, 11) - for y in (2, 5, 8, 11) - ) + tiles: list[str] = [] + for x in (2, 5, 8, 11): + for y in (2, 5, 8, 11): + color = primary if (x + y + pattern) % 2 else accent + tiles.append(f'') + return "".join(tiles) if asset_type == "projectile": return ( - f'' - f'' + f'' + f'' ) return ( - f'' - f'' + f'' + f'' )