-
Notifications
You must be signed in to change notification settings - Fork 2
feat: scaffold react village generator #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: scaffold react village generator #1
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Gambitnl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've scaffolded a new React and TypeScript project to implement a village generator. This pull request sets up the foundational web UI, integrates the Wave Function Collapse (WFC) algorithm for procedural generation, and provides controls for customizing village features. The goal is to provide a functional and interactive tool for generating diverse village layouts.
Highlights
- Project Scaffolding: I've initialized a new React/TypeScript application within the
web/directory, setting up the basic project structure, dependencies, and build configuration. - Wave Function Collapse (WFC) Integration: I've implemented the core village generation logic using the Wave Function Collapse (WFC) algorithm, including defining specific WFC tiles and their adjacency rules to ensure coherent and varied village layouts.
- Interactive Web UI: I've developed a user interface with React components that allows users to configure village generation parameters, such as type (farming, fishing, fortified), size (small, medium), and toggle the inclusion of specific features like farmlands, markets, walls, and wells.
- Village Rendering Components: I've created reusable React components for rendering the procedurally generated village layout visually using SVG, displaying elements like roads, buildings, and walls.
- Build and Dependency Setup: I've established the necessary build and dependency management setup for the React application, including
package.json,package-lock.json,tsconfig.json, and.gitignore.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a solid foundation for a village generation feature using React and TypeScript with the Wave Function Collapse algorithm. The code is generally well-structured. I've provided some specific feedback on areas that could be improved, mainly focusing on enhancing type safety, removing redundant code, and handling potential errors. Key suggestions include improving type safety in event handlers and configuration files, adding error handling for asynchronous operations, and simplifying logic in the layout transformation service. Overall, great work on scaffolding this new feature.
| const handleSelect = ( | ||
| key: 'type' | 'size' | ||
| ) => (e: React.ChangeEvent<HTMLSelectElement>) => { | ||
| setOptions((prev) => ({ ...prev, [key]: e.target.value as any })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| generateWfcGrid(seed, options).then((grid) => { | ||
| setVillageLayout(transformGridToLayout(grid, options)); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The promise returned by generateWfcGrid is not being checked for errors. If the promise rejects (e.g., due to an issue in the WFC library), it will result in an unhandled promise rejection, which can crash the application. You should add a .catch() block to handle potential errors gracefully.
| generateWfcGrid(seed, options).then((grid) => { | |
| setVillageLayout(transformGridToLayout(grid, options)); | |
| }); | |
| generateWfcGrid(seed, options).then((grid) => { | |
| setVillageLayout(transformGridToLayout(grid, options)); | |
| }).catch(err => console.error('Failed to generate WFC grid', err)); |
| if (!allowWalls) layout.walls = []; | ||
| if (!allowFarmland) | ||
| layout.buildings = layout.buildings.filter((b) => b.type !== 'farmland'); | ||
| if (!allowMarket) | ||
| layout.buildings = layout.buildings.filter((b) => b.type !== 'market'); | ||
| if (!allowWells) | ||
| layout.buildings = layout.buildings.filter((b) => b.type !== 'well'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "scripts": { | ||
| "start": "npm run build -- --watch", | ||
| "build": "tsc", | ||
| "test": "echo 'No tests specified'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <label style={{ marginLeft: '1rem' }}> | ||
| <input | ||
| type="checkbox" | ||
| checked={options.includeFarmland !== false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expression options.includeFarmland !== false is a bit verbose. Since options.includeFarmland will hold a boolean value after initialization, you can simplify this to just checked={options.includeFarmland}. This simplification can be applied to the other similar checkboxes as well.
checked={!!options.includeFarmland}| } | ||
|
|
||
| export const SubmapPane: React.FC<Props> = ({ currentWorldBiomeId }) => { | ||
| const options: VillageOptions = { type: 'farming', size: 'small' }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| { id: 'well' } | ||
| ]; | ||
|
|
||
| export const adjacencyRules: Record<string, string[]> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve type safety and prevent typos, consider defining a string literal union type for the tile IDs from villageTiles. This type can then be used to strongly type adjacencyRules, ensuring that all keys and values are valid tile IDs.
For example:
export type VillageTileId =
| 'grass'
| 'dirt'
| 'road_center'
// ... etc.
export const villageTiles: { id: VillageTileId }[] = [
// ...
];
export const adjacencyRules: Record<VillageTileId, VillageTileId[]> = {
// ...
};| if (tile.id.startsWith('building_roof')) { | ||
| layout.buildings.push({ | ||
| id: `bldg_${x}_${y}`, | ||
| type: 'house', | ||
| polygon: [ | ||
| { x, y }, | ||
| { x: x + 1, y }, | ||
| { x: x + 1, y: y + 1 }, | ||
| { x, y: y + 1 } | ||
| ], | ||
| entryPoint: { x, y: y + 1 } | ||
| }); | ||
| } | ||
| if (tile.id.startsWith('road')) { | ||
| layout.roads.push({ | ||
| id: `road_${x}_${y}`, | ||
| pathPoints: [{ x, y }, { x: x + 1, y }] | ||
| }); | ||
| } | ||
| if (tile.id === 'farmland' && allowFarmland) { | ||
| layout.buildings.push({ | ||
| id: `farm_${x}_${y}`, | ||
| type: 'farmland', | ||
| polygon: [ | ||
| { x, y }, | ||
| { x: x + 1, y }, | ||
| { x: x + 1, y: y + 1 }, | ||
| { x, y: y + 1 } | ||
| ], | ||
| entryPoint: { x, y } | ||
| }); | ||
| } | ||
| if (tile.id === 'market_stall' && allowMarket) { | ||
| layout.buildings.push({ | ||
| id: `market_${x}_${y}`, | ||
| type: 'market', | ||
| polygon: [ | ||
| { x, y }, | ||
| { x: x + 1, y }, | ||
| { x: x + 1, y: y + 1 }, | ||
| { x, y: y + 1 } | ||
| ], | ||
| entryPoint: { x, y } | ||
| }); | ||
| } | ||
| if (tile.id === 'well' && allowWells) { | ||
| layout.buildings.push({ | ||
| id: `well_${x}_${y}`, | ||
| type: 'well', | ||
| polygon: [ | ||
| { x, y }, | ||
| { x: x + 1, y }, | ||
| { x: x + 1, y: y + 1 }, | ||
| { x, y: y + 1 } | ||
| ], | ||
| entryPoint: { x, y } | ||
| }); | ||
| } | ||
| if (tile.id.startsWith('town_wall') && allowWalls) { | ||
| layout.walls.push({ | ||
| id: `wall_${x}_${y}`, | ||
| pathPoints: [{ x, y }, { x: x + 1, y }] | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
Testing
npm --prefix web testnpm --prefix web run buildhttps://chatgpt.com/codex/tasks/task_e_688e523f6438832fa06a4bdd434be5d7