Loading...
Loading...
Clone a game template from the gallery as a starting point. Use when the user says "use a template", "start from a template", "clone flappy-bird", "use the platformer template", or wants to quickly bootstrap a game from an existing example. Do NOT use for creating a game from scratch (use make-game).
npx skill4agent add opusgamelabs/game-creator use-template<template-id> [project-name]gallery/manifest.jsontemplate-idproject-nametemplate-idgallery/manifest.jsonidgame-creatorexamples/<project-name>/./<project-name>/node_modules/dist/output/.herenow/progress.mdtest-results/playwright-report/package.json"name"index.html<title>npm installTemplate cloned successfully!
cd <project-name>
npm run devconst fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Find game-creator root (contains gallery/manifest.json)
function findRoot(dir) {
let d = dir;
while (d !== path.dirname(d)) {
if (fs.existsSync(path.join(d, 'gallery', 'manifest.json'))) return d;
d = path.dirname(d);
}
return null;
}
const root = findRoot(process.cwd());
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'gallery', 'manifest.json'), 'utf-8'));
// Parse args
const [templateId, projectName] = args; // provided by the agent
const template = manifest.find(t => t.id === templateId);
const name = projectName || templateId;
// Determine target
const inGameCreator = process.cwd().startsWith(root);
const target = inGameCreator
? path.join(root, 'examples', name)
: path.join(process.cwd(), name);
// Copy with exclusions
const EXCLUDE = ['node_modules', 'dist', 'output', '.herenow', 'progress.md', 'test-results', 'playwright-report'];
function copyDir(src, dst) {
fs.mkdirSync(dst, { recursive: true });
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
if (EXCLUDE.includes(entry.name)) continue;
const s = path.join(src, entry.name);
const d = path.join(dst, entry.name);
if (entry.isDirectory()) copyDir(s, d);
else fs.copyFileSync(s, d);
}
}
copyDir(path.join(root, template.source), target);
// Update package.json
const pkgPath = path.join(target, 'package.json');
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
pkg.name = name;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
}
// Update index.html title
const indexPath = path.join(target, 'index.html');
if (fs.existsSync(indexPath)) {
let html = fs.readFileSync(indexPath, 'utf-8');
const prettyName = name.replace(/[-_]/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
html = html.replace(/<title>[^<]*<\/title>/, `<title>${prettyName}</title>`);
fs.writeFileSync(indexPath, html);
}
// Install
execSync('npm install', { cwd: target, stdio: 'inherit' });
// Fire-and-forget telemetry (respects DO_NOT_TRACK / DISABLE_TELEMETRY)
if (!process.env.DO_NOT_TRACK && !process.env.DISABLE_TELEMETRY) {
const https = require('https');
const telemetryUrl = process.env.TELEMETRY_URL || 'https://gallery-telemetry.up.railway.app';
https.get(`${telemetryUrl}/t?event=clone&template=${encodeURIComponent(templateId)}&source=skill&v=1`)
.on('error', () => {});
}/use-template flappy-bird my-game
/use-template threejs-3d-starter space-shooter
/use-template castle-siege/use-template/make-game