KO
games/dmmotor / tools / site / make-pages.py · commit 9d248a4
import json, os, sysSITE = sys.argv[1]T = { 'fr': dict(  title='dmmotor – FPS rétro en PHP, jouer gratuitement en ligne',  desc="dmmotor : le moteur de FPS en vue subjective publié en GPL par id Software, porté en PHP, avec les niveaux libres de Freedoom. Jouez gratuitement dans le navigateur, sur ordinateur ou téléphone.",  h1='dmmotor', tag='Un FPS en vue subjective des années 90, réécrit en PHP, qui tourne dans votre navigateur.',  play='JOUER', play2='Lancer la partie',  about_h='Le jeu',  about=["Labyrinthes industriels, bases envahies, portes à carte, interrupteurs secrets, ascenseurs et pièges : <b>dmmotor</b> fait tourner <b>Freedoom Phase 1</b> (quatre épisodes de neuf niveaux) et <b>Freedoom Phase 2</b> (32 niveaux), avec leurs monstres, leurs armes, leurs sons et leur musique. Sauvegardes, carte automatique et commandes clavier, souris, manette ou tactile.",   "Le moteur est un <b>portage en PHP du code source publié sous licence GPL v2 par id Software</b> (linuxdoom-1.10) : rendu BSP des murs, sols et plafonds, sprites, IA des monstres, armes, portes et ascenseurs, traduits fichier par fichier. Il tourne avec <a href=\"https://jumphp.net\">JumPHP</a>, en PHP compilé en WebAssembly : rien à installer."],  shots_h='Captures', alts=['Un zombie abattu au pistolet dans le premier niveau','Une porte ouverte, des zombies arrivent','Le départ du deuxième niveau, en plein air','Une boule de feu lancée par un diablotin','Le tableau de fin de niveau : ennemis, objets, secrets, temps'],  ctrl_h='Commandes', ctrl=[('Clavier','Flèches ou ZQSD / WASD : avancer et tourner — Q/A, D : pas de côté — Ctrl, F ou clic : tirer — souris : tourner — Espace ou E : ouvrir, actionner — Maj : marcher — 1 à 7 : armes — Tab : carte — Échap : pause, sauvegarde'),('Manette','Stick : se déplacer — RT ou X : tirer — A : ouvrir — LB / RB : pas de côté — Y : arme suivante — Start : pause'),('Téléphone','Stick à l\'écran, boutons FIRE et USE, MENU pour la pause')],  cred_h='Licences et crédits',  cred=["Moteur : code source d'id Software publié sous <b>GNU GPL v2</b>, porté en PHP pour dmmotor ; le code de ce portage est sous la même licence et <a href=\"https://git.jumphp.net/duchnoun/dmmotor\">ses sources sont publiques</a>.",   "Contenu du jeu : <a href=\"https://freedoom.github.io\">Freedoom</a> (niveaux, graphismes, sons), licence BSD, © les contributeurs du projet Freedoom.",   "dmmotor n'est ni affilié à id Software, ZeniMax ou Bethesda, ni approuvé par eux."],  faq_h='Questions fréquentes',  faq=[('Faut-il installer quelque chose ?','Non : le jeu tourne dans le navigateur, sur ordinateur comme sur téléphone.'),('Est-ce gratuit ?','Oui, entièrement : le moteur est sous GPL et le contenu Freedoom sous licence BSD.'),('Y a-t-il de la musique ?','Oui : les morceaux de Freedoom sont joués en direct par un synthétiseur FM écrit en PHP, à la manière des cartes son de l\'époque.'),('Quels jeux sont inclus ?','Freedoom Phase 1 (quatre épisodes) et Freedoom Phase 2 (32 niveaux), au choix au lancement.')],  lang='fr', other='en', other_label='English'), 'en': dict(  title='dmmotor – retro FPS in PHP, play free online',  desc="dmmotor: the first-person shooter engine id Software released under the GPL, ported to PHP, playing the free Freedoom levels. Play free in the browser, on a computer or a phone.",  h1='dmmotor', tag='A 90s first-person shooter, rewritten in PHP, running in your browser.',  play='PLAY', play2='Start playing',  about_h='The game',  about=["Industrial mazes, overrun bases, key card doors, secret switches, lifts and traps: <b>dmmotor</b> plays <b>Freedoom Phase 1</b> (four episodes of nine levels) and <b>Freedoom Phase 2</b> (32 levels), with their monsters, weapons, sounds and music. Save games, automap, keyboard, mouse, gamepad or touch controls.",   "The engine is a <b>PHP port of the source code id Software released under the GPL v2</b> (linuxdoom-1.10): BSP rendering of walls, floors and ceilings, sprites, monster AI, weapons, doors and lifts, translated file by file. It runs on <a href=\"https://jumphp.net\">JumPHP</a>, PHP compiled to WebAssembly: nothing to install."],  shots_h='Screenshots', alts=['A zombie shot down with the pistol in the first level','An open door, zombies coming','The start of the second level, outdoors','A fireball thrown by an imp','The end of level stats: kills, items, secrets, time'],  ctrl_h='Controls', ctrl=[('Keyboard','Arrows or WASD / ZQSD: move and turn — A/Q, D: strafe — Ctrl, F or click: fire — mouse: turn — Space or E: open, use — Shift: walk — 1 to 7: weapons — Tab: map — Esc: pause, save'),('Gamepad','Stick: move — RT or X: fire — A: use — LB / RB: strafe — Y: next weapon — Start: pause'),('Phone','On-screen stick, FIRE and USE buttons, MENU to pause')],  cred_h='Licences and credits',  cred=["Engine: id Software's source code released under the <b>GNU GPL v2</b>, ported to PHP for dmmotor; the code of this port is under the same licence and <a href=\"https://git.jumphp.net/duchnoun/dmmotor\">its source is public</a>.",   "Game content: <a href=\"https://freedoom.github.io\">Freedoom</a> (levels, graphics, sounds), BSD licence, © the contributors to the Freedoom project.",   "dmmotor is not affiliated with or endorsed by id Software, ZeniMax or Bethesda."],  faq_h='FAQ',  faq=[('Do I need to install anything?','No: the game runs in the browser, on a computer or a phone.'),('Is it free?','Yes, completely: the engine is GPL and the Freedoom content is BSD.'),('Is there music?','Yes: the Freedoom songs are played live by an FM synthesizer written in PHP, like the sound cards of the time.'),('Which games are included?','Freedoom Phase 1 (four episodes) and Freedoom Phase 2 (32 levels), chosen at start.')],  lang='en', other='fr', other_label='Français'),}SHOTS = ['shot-zombie.png','shot-door.png','shot-e1m2.png','shot-imp.png','shot-stats.png']def page(t, sub):    up = '../' if sub else ''    url = 'https://{{DOMAIN}}/' + ('en/' if t['lang']=='en' else '')    ld = {"@context":"https://schema.org","@type":"VideoGame","name":"dmmotor","description":t['desc'],"url":url,          "genre":["First-person shooter","Action"],"gamePlatform":["Web browser","PC","Mobile"],"applicationCategory":"Game",          "operatingSystem":"Any","image":"https://{{DOMAIN}}/images/og.png",          "screenshot":["https://{{DOMAIN}}/images/"+s for s in SHOTS],"isAccessibleForFree":True,"inLanguage":t['lang'],          "license":"https://www.gnu.org/licenses/old-licenses/gpl-2.0.html",          "potentialAction":{"@type":"PlayAction","target":"https://{{DOMAIN}}/play/"}}    faq = {"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":q,"acceptedAnswer":{"@type":"Answer","text":a}} for q,a in t['faq']]}    shots = '\n'.join(f'      <figure><img src="{up}images/{s}" alt="{a}" width="640" height="480" loading="lazy"><figcaption>{a}</figcaption></figure>' for s,a in zip(SHOTS,t['alts']))    ctrl = '\n'.join(f'      <li><b>{k}</b> — {v}</li>' for k,v in t['ctrl'])    cred = '\n'.join(f'    <p>{c}</p>' for c in t['cred'])    faqh = '\n'.join(f'    <h3>{q}</h3>\n    <p>{a}</p>' for q,a in t['faq'])    about = '\n'.join(f'    <p>{p}</p>' for p in t['about'])    other_href = up + ('en/' if t['other']=='en' else '')    return f'''<!doctype html><html lang="{t['lang']}"><head>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <title>{t['title']}</title>  <meta name="description" content="{t['desc']}">  <link rel="canonical" href="{url}">  <link rel="alternate" hreflang="fr" href="https://{{{{DOMAIN}}}}/">  <link rel="alternate" hreflang="en" href="https://{{{{DOMAIN}}}}/en/">  <link rel="alternate" hreflang="x-default" href="https://{{{{DOMAIN}}}}/">  <link rel="icon" href="{up}images/favicon.png">  <meta property="og:type" content="website">  <meta property="og:title" content="dmmotor">  <meta property="og:description" content="{t['desc']}">  <meta property="og:url" content="{url}">  <meta property="og:image" content="https://{{{{DOMAIN}}}}/images/og.png">  <meta property="og:locale" content="{t['lang']}">  <meta name="twitter:card" content="summary_large_image">  <meta name="twitter:title" content="dmmotor">  <meta name="twitter:description" content="{t['desc']}">  <meta name="twitter:image" content="https://{{{{DOMAIN}}}}/images/og.png">  <script type="application/ld+json">{json.dumps(ld, ensure_ascii=False, indent=2)}  </script>  <script type="application/ld+json">{json.dumps(faq, ensure_ascii=False, indent=2)}  </script>  <style>    :root {{ --bg: #120806; --panel: #22100c; --text: #f4e6d8; --muted: #c9b29d; --red: #d82a1e; --gold: #f2b233; }}    * {{ box-sizing: border-box; }}    body {{ margin: 0; background: var(--bg); color: var(--text); font: 17px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; }}    a {{ color: var(--gold); }}    nav {{ max-width: 1000px; margin: 0 auto; padding: 12px 16px 0; text-align: right; font-size: 15px; }}    main {{ max-width: 1000px; margin: 0 auto; padding: 8px 16px 64px; }}    header {{ text-align: center; padding: 8px 0; }}    .hero {{ display: block; width: 100%; max-width: 800px; margin: 0 auto; image-rendering: pixelated; border: 3px solid #3a1b14; border-radius: 6px; }}    h1 {{ font-size: clamp(36px, 8vw, 64px); margin: 18px 0 4px; letter-spacing: 3px; color: var(--red); text-shadow: 3px 3px 0 #000; text-transform: uppercase; }}    .tag {{ color: var(--muted); font-size: 19px; margin: 0; }}    h2 {{ margin: 48px 0 12px; font-size: 26px; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; }}    h3 {{ margin: 20px 0 4px; font-size: 18px; }}    p, li {{ color: var(--muted); }}    b {{ color: var(--text); }}    .play {{ display: inline-block; margin: 22px 0 6px; padding: 16px 48px; border-radius: 10px; background: var(--red); color: #fff;      font-weight: 900; font-size: 24px; letter-spacing: 2px; text-decoration: none; box-shadow: 0 6px 0 #7a120b; }}    .play:active {{ transform: translateY(3px); box-shadow: 0 3px 0 #7a120b; }}    .shots {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }}    figure {{ margin: 0; background: var(--panel); border-radius: 8px; overflow: hidden; }}    figure img {{ display: block; width: 100%; height: auto; image-rendering: pixelated; }}    figcaption {{ padding: 8px 12px; font-size: 14px; color: var(--muted); }}    ul {{ padding-left: 20px; }}    .again {{ text-align: center; }}    footer {{ text-align: center; font-size: 14px; color: var(--muted); padding: 24px 16px 40px; }}  </style></head><body>  <nav><a href="{other_href}" hreflang="{t['other']}">{t['other_label']}</a></nav>  <main>    <header>      <img class="hero" src="{up}images/title.png" alt="dmmotor — Freedoom Phase 1" width="640" height="480">      <h1>{t['h1']}</h1>      <p class="tag">{t['tag']}</p>      <a class="play" href="{up}play/">{t['play']}</a>    </header>    <h2>{t['about_h']}</h2>{about}    <h2>{t['shots_h']}</h2>    <div class="shots">{shots}    </div>    <h2>{t['ctrl_h']}</h2>    <ul>{ctrl}    </ul>    <p class="again"><a class="play" href="{up}play/">{t['play2']}</a></p>    <h2>{t['cred_h']}</h2>{cred}    <h2>{t['faq_h']}</h2>{faqh}  </main>  <footer>dmmotor — GPL v2 · Freedoom — BSD · <a href="https://jumphp.net">JumPHP</a></footer></body></html>'''os.makedirs(os.path.join(SITE, 'en'), exist_ok=True)open(os.path.join(SITE, 'index.html'), 'w').write(page(T['fr'], False))open(os.path.join(SITE, 'en', 'index.html'), 'w').write(page(T['en'], True))open(os.path.join(SITE, 'sitemap.xml'), 'w').write('''<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">  <url>    <loc>https://{{DOMAIN}}/</loc>    <xhtml:link rel="alternate" hreflang="fr" href="https://{{DOMAIN}}/"/>    <xhtml:link rel="alternate" hreflang="en" href="https://{{DOMAIN}}/en/"/>  </url>  <url>    <loc>https://{{DOMAIN}}/en/</loc>    <xhtml:link rel="alternate" hreflang="fr" href="https://{{DOMAIN}}/"/>    <xhtml:link rel="alternate" hreflang="en" href="https://{{DOMAIN}}/en/"/>  </url></urlset>''')print('ok')