Release / build (push) Failing after 1m29s
- shared: the whole UI moves to Compose Multiplatform (Android + Kotlin/Wasm). Platform pieces (card images, storage, links, back button) come in through a Platform interface; fonts, logo and suit icons are compose resources; images are reduced by halving so they stay sharp everywhere. - web: the browser app (bela.mariosem.es), with 1x card faces, localStorage and room links (?soba=KOD). - Online play: lobby (name, open a room, join by code), waiting room with seats, then the usual table. The server runs every game with the engine and sends each player only their own view; bots fill empty seats; same pacing as the local game. Reconnect with a saved token (also after closing the app or reloading the page), 10 s grace before a bot plays for an absent player, heartbeat so dead connections are noticed. - server: Ktor (WebSocket /ws, /health, serves the web app with pre-compressed files). Tests cover a whole two-player game, resume and leaving. - Dockerfile (one image: web + server, tests run in the build), docker-compose.yml and a Gitea Actions workflow like Keep's (build, Trivy scan, push msemes/bela:<sha> and :latest). - Android talks to the server with Ktor CIO; the update section stays Android-only. The QR code is precomputed (QrMatrix) and checked against ZXing in a unit test. - -PbelaNoAndroid=true builds without the Android SDK; -PbelaDownloadNode=false reuses the local Node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
4.5 KiB
Python
93 lines
4.5 KiB
Python
"""
|
|
Turn icon.png (square artwork, full bleed) into the Android launcher icon and the in-app logo.
|
|
|
|
python tools/make_icon.py
|
|
|
|
Android adaptive icons are 108 dp layers that the launcher masks to a circle, squircle or rounded square,
|
|
showing only about the middle 72 dp. Placed full size, the artwork would lose the "B" and the card corners.
|
|
So the artwork is scaled to fit the mask, and the space around it is filled with a blurred, enlarged copy of
|
|
plain felt in the artwork's edge colour, blended in with soft edges so no square seam shows.
|
|
|
|
Writes:
|
|
app/src/main/res/mipmap-<density>/ic_launcher_foreground.webp (adaptive icon, all densities)
|
|
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml (adaptive icon definition)
|
|
app/src/main/res/values/ic_launcher_background.xml (colour behind the layer)
|
|
shared/src/commonMain/composeResources/drawable/logo.webp (the artwork for the home screen, both apps)
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageFilter
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
SOURCE = ROOT / "icon.png"
|
|
RES = ROOT / "app" / "src" / "main" / "res"
|
|
|
|
DENSITIES = {"mdpi": 1.0, "hdpi": 1.5, "xhdpi": 2.0, "xxhdpi": 3.0, "xxxhdpi": 4.0}
|
|
LAYER_DP = 108
|
|
ART_DP = 68 # artwork size inside the 108 dp layer; its content then stays inside a 72 dp circle
|
|
FEATHER = 0.03 # fraction of the artwork, at its edges, faded into the surround
|
|
LOGO_PX = 900
|
|
|
|
|
|
def edge_colour(art: Image.Image) -> tuple:
|
|
"""Average colour of the artwork's outer border: the felt the surround has to continue."""
|
|
w, h = art.size
|
|
band = max(2, w // 60)
|
|
strips = [art.crop((0, 0, w, band)), art.crop((0, h - band, w, h)), art.crop((0, 0, band, h)), art.crop((w - band, 0, w, h))]
|
|
means = [strip.resize((1, 1), Image.BOX).getpixel((0, 0)) for strip in strips]
|
|
return tuple(sum(m[i] for m in means) // len(means) for i in range(3))
|
|
|
|
|
|
def adaptive_layer(art: Image.Image, size: int) -> Image.Image:
|
|
# Surround: plain felt in the artwork's edge colour, a little darker towards the corners.
|
|
edge = edge_colour(art)
|
|
dark = tuple(int(c * 0.6) for c in edge)
|
|
gradient = Image.radial_gradient("L").resize((size, size), Image.BICUBIC) # black centre -> white rim
|
|
surround = Image.composite(Image.new("RGB", (size, size), dark), Image.new("RGB", (size, size), edge), gradient)
|
|
art_px = round(size * ART_DP / LAYER_DP)
|
|
sharp = art.resize((art_px, art_px), Image.LANCZOS)
|
|
# Alpha: opaque in the middle, fading out over the outer FEATHER of each side so no square edge shows.
|
|
fade = max(1, round(art_px * FEATHER))
|
|
mask = Image.new("L", (art_px, art_px), 0)
|
|
mask.paste(Image.new("L", (art_px - 2 * fade, art_px - 2 * fade), 255), (fade, fade))
|
|
mask = mask.filter(ImageFilter.GaussianBlur(fade / 2))
|
|
offset = (size - art_px) // 2
|
|
surround.paste(sharp, (offset, offset), mask)
|
|
return surround
|
|
|
|
|
|
def main() -> None:
|
|
art = Image.open(SOURCE).convert("RGB")
|
|
for name, scale in DENSITIES.items():
|
|
size = round(LAYER_DP * scale)
|
|
folder = RES / f"mipmap-{name}"
|
|
folder.mkdir(parents=True, exist_ok=True)
|
|
adaptive_layer(art, size).save(folder / "ic_launcher_foreground.webp", "WEBP", quality=95, method=6)
|
|
print(f"mipmap-{name}/ic_launcher_foreground.webp {size}px")
|
|
|
|
(RES / "mipmap-anydpi-v26").mkdir(parents=True, exist_ok=True)
|
|
(RES / "mipmap-anydpi-v26" / "ic_launcher.xml").write_text(
|
|
'<?xml version="1.0" encoding="utf-8"?>\n'
|
|
"<!-- Generated by tools/make_icon.py from icon.png. -->\n"
|
|
'<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">\n'
|
|
' <background android:drawable="@color/ic_launcher_background" />\n'
|
|
' <foreground android:drawable="@mipmap/ic_launcher_foreground" />\n'
|
|
"</adaptive-icon>\n",
|
|
encoding="utf-8",
|
|
)
|
|
edge = art.getpixel((0, 0)) # the dark felt at the artwork's edge
|
|
(RES / "values" / "ic_launcher_background.xml").write_text(
|
|
'<?xml version="1.0" encoding="utf-8"?>\n<resources>\n'
|
|
f' <color name="ic_launcher_background">#{edge[0]:02X}{edge[1]:02X}{edge[2]:02X}</color>\n'
|
|
"</resources>\n",
|
|
encoding="utf-8",
|
|
)
|
|
logo = ROOT / "shared" / "src" / "commonMain" / "composeResources" / "drawable" / "logo.webp"
|
|
art.resize((LOGO_PX, LOGO_PX), Image.LANCZOS).save(logo, "WEBP", quality=92, method=6)
|
|
print("shared composeResources/drawable/logo.webp", LOGO_PX, "px")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|