Files
devplacepy/devplacepy/routers/game/_shared.py
T
retoor ebf6bf7f82 feat: add Code Farm cooperative idle game with plot-based crop system and pub/sub notifications
Implement a Farmville-style cooperative idle game mounted at `/game` with member-only play and public farm viewing. The data layer is pure and timestamp-driven with no background tick: plot states are derived from `ready_at` vs current time, never stored. Key features include plantable software projects (shell script through kernel) that build over real time, harvest for coins and XP, CI tier upgrades for faster builds, plot purchasing with doubling cost, watering mechanics for friends' builds, daily quests, and prestige system. All game endpoints negotiate HTML or JSON and return full farm state for single-request client refresh. Pub/sub notifications broadcast farm updates on `public.game.farm.{username}` topics. Database schema adds `game_farms`, `game_plots`, and `game_quests` tables with appropriate indexes.
2026-06-22 16:41:53 +00:00

45 lines
1.1 KiB
Python

# retoor <retoor@molodetz.nl>
from fastapi import Request
from devplacepy.database import get_table
from devplacepy.services.game import store
from devplacepy.services.pubsub import publish
def farm_topic(username: str) -> str:
return f"public.game.farm.{username}"
async def notify_farm(username: str) -> None:
if not username:
return
try:
await publish(farm_topic(username), {"kind": "update", "username": username})
except Exception:
pass
def owner_by_username(username: str) -> dict | None:
return get_table("users").find_one(username=username)
def state_payload(user: dict, viewer: dict | None = None) -> dict:
farm = store.ensure_farm(user["uid"])
return store.serialize_farm(farm, viewer=viewer or user, owner=user)
def game_seo(request: Request, title: str, description: str) -> dict:
from devplacepy.seo import base_seo_context
return base_seo_context(
request,
title=title,
description=description,
robots="noindex,follow",
breadcrumbs=[
{"name": "Home", "url": "/feed"},
{"name": "Code Farm", "url": "/game"},
],
)