Skip to content

Commit

Permalink
explosion fix, update files fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Tańczyk committed Jul 10, 2024
1 parent 94dec2d commit 367538b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion games/nukes/codegen/update-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export function updateFiles(functionCalls) {
fs.unlinkSync(filePath);
} else {
console.log(`Updating file: ${filePath}`);
fs.writeFileSync(filePath, newContent, 'utf-8');
fs.writeFileSync(
filePath,
// Fixing a problem caused by vertex function calling. Possible not a good fix
newContent.replace(/\\n/g, '\n').replace(/\\'/g, "'"),
'utf-8',
);
}
}
}
8 changes: 7 additions & 1 deletion games/nukes/codegen/vertex-ai.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'node:assert';
import { VertexAI } from '@google-cloud/vertexai';

// A function to generate content using the generative model
Expand Down Expand Up @@ -28,7 +29,7 @@ export async function generateContent(systemPrompt, prompt) {
},
newContent: {
type: 'STRING',
description: 'The content to update the file with.',
description: 'The content to update the file with, empty string means the file will be deleted.',
},
},
required: ['filePath', 'newContent'],
Expand All @@ -46,6 +47,11 @@ export async function generateContent(systemPrompt, prompt) {
.flat()
.filter((functionCall) => !!functionCall);

assert(
functionCalls.every((call) => call.name === 'updateFile'),
'Only updateFile function is allowed',
);

return functionCalls.filter((call) => call.name === 'updateFile').map((call) => call.args);
}

Expand Down
3 changes: 2 additions & 1 deletion games/nukes/src/world-render/explosion-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function ExplosionRender({ explosion, worldTimestamp }: { explosion: Expl
'--x': explosion.position.x,
'--y': explosion.position.y,
'--radius': explosion.radius * progress,
'--color': `rgb(${255 * progress}, ${255 * (1-progress)}, 0)`
} as React.CSSProperties
}
/>
Expand All @@ -31,7 +32,7 @@ const ExplosionContainer = styled.div`
width: calc(var(--radius) * 1px);
height: calc(var(--radius) * 1px);
border-radius: 50%;
background: rgb(255, 255, 255);
background: var(--color);
pointer-events: none;
`;

0 comments on commit 367538b

Please sign in to comment.