feat: implement daily character guessing game with local storage and hint system
- Added character selection and history management using local storage. - Implemented hint system that unlocks based on the number of guesses. - Enhanced UI with animations for hint unlocks and special win conditions. - Created a server endpoint to record wins in the database.
This commit is contained in:
84
scripts/set-daily-mode.ts
Normal file
84
scripts/set-daily-mode.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { createClient } from '@libsql/client';
|
||||
import { drizzle } from 'drizzle-orm/libsql';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import fs from 'fs';
|
||||
import { character } from '../src/lib/server/db/schema';
|
||||
|
||||
const DATABASE_URL = process.env.DATABASE_URL || 'file:local.db';
|
||||
|
||||
const client = createClient({ url: DATABASE_URL });
|
||||
const db = drizzle(client);
|
||||
|
||||
function readJsonFile(path: string): string[] | null {
|
||||
if (!fs.existsSync(path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(path, 'utf-8');
|
||||
return JSON.parse(content) as string[];
|
||||
}
|
||||
|
||||
function getErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
|
||||
async function setDailyCharacters(): Promise<void> {
|
||||
try {
|
||||
const dailyCharacterIds = readJsonFile('./scripts/daily-characters.json');
|
||||
|
||||
if (!dailyCharacterIds || dailyCharacterIds.length === 0) {
|
||||
console.error('❌ No daily characters found in daily-characters.json');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`\n=== Setting Daily Mode Characters ===\n`);
|
||||
console.log(`Found ${dailyCharacterIds.length} characters to set as daily\n`);
|
||||
|
||||
// Step 1: Disable isInDailyMode for all characters
|
||||
console.log('Step 1: Disabling isInDailyMode for all characters...');
|
||||
await db.update(character).set({ isInDailyMode: false });
|
||||
console.log('✓ All characters disabled from daily mode\n');
|
||||
|
||||
// Step 2: Enable isInDailyMode for characters in the list
|
||||
console.log('Step 2: Enabling isInDailyMode for daily characters...\n');
|
||||
|
||||
let successCount = 0;
|
||||
let errorCount = 0;
|
||||
|
||||
for (let i = 0; i < dailyCharacterIds.length; i++) {
|
||||
const charId = dailyCharacterIds[i];
|
||||
try {
|
||||
const result = await db
|
||||
.update(character)
|
||||
.set({ isInDailyMode: true })
|
||||
.where(eq(character.id, charId));
|
||||
|
||||
successCount++;
|
||||
process.stdout.write(`\rUpdated: ${successCount}/${dailyCharacterIds.length}`);
|
||||
} catch (error) {
|
||||
errorCount++;
|
||||
console.error(`\n✗ Error updating character ${i + 1}:`);
|
||||
console.error(` ID: ${charId}`);
|
||||
console.error(` Message: ${getErrorMessage(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\n\n✓ Daily characters updated!`);
|
||||
console.log(` Success: ${successCount}`);
|
||||
console.log(` Errors: ${errorCount}`);
|
||||
|
||||
if (errorCount === 0) {
|
||||
console.log(`\n✅ Successfully set ${successCount} characters as daily mode characters\n`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('✗ Operation failed:', getErrorMessage(error));
|
||||
process.exit(1);
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
setDailyCharacters().catch((error) => {
|
||||
console.error(getErrorMessage(error));
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user