Skip to content

Implement Godot project import/export and GIF encoding features#16

Merged
wernerbihl merged 4 commits intomainfrom
feature/2026-05-05
May 5, 2026
Merged

Implement Godot project import/export and GIF encoding features#16
wernerbihl merged 4 commits intomainfrom
feature/2026-05-05

Conversation

@wernerbihl
Copy link
Copy Markdown
Collaborator

Introduce functionality for importing and exporting Godot projects, including project metadata and scene management. Enhance tileset image import and management features, and implement GIF encoding capabilities. Add tests to validate the new functionalities and improve overall code maintainability.

wernerbihl added 3 commits May 5, 2026 21:49
- Add hooks and utilities for handling project import/export actions.
- Implement export functionality for Godot projects, including project metadata and scene management.
- Create utilities for managing dialog properties and handling missing resources during import.
- Introduce tests for validating the export and import processes of Godot projects.
- Add support for tileset image import and merging, ensuring proper handling of image assets.
- Implemented functions to validate and normalize tileset image files.
- Added hooks for managing tileset image import state and placement.
- Created new components for tileset deletion and import choice dialogs.
- Developed placement controls for positioning imported tileset images.
- Introduced a toolbar for managing tileset settings and actions.
- Added tests for tileset image import and merge functionalities.
- Refactored existing code for improved readability and maintainability.
Copilot AI review requested due to automatic review settings May 5, 2026 20:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds end-to-end Godot 4 project import/export support (zipped archives and folder-based imports), refactors tileset image import to support creating new tilesets or placing/merging into an existing tileset, and centralizes GIF encoding into a shared service with new tests.

Changes:

  • Implement Godot project archive generation + project import preparation/flow (including missing-resource resolution and warnings).
  • Add a shared encodeGifFrames() service and switch raster/image-editor GIF exports to use it, with tests covering transparency palette behavior.
  • Introduce tileset image import/placement UX and supporting merge logic, plus texture-cache improvements when a tileset’s asset changes.

Reviewed changes

Copilot reviewed 39 out of 41 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
TODO.txt Updates roadmap items (adds terrain brush, palette import notes, etc.).
tests/services/gif.test.ts Adds unit tests for encodeGifFrames() transparency/opaque behavior.
tests/features/map-editor/lib/tileset-image-merge.test.ts Tests snapping, canvas sizing, and merge-to-asset behavior.
tests/features/map-editor/lib/tileset-image-import.test.ts Tests MIME/extension detection and name derivation for tileset imports.
tests/features/map-editor/components/MapCanvas/texture-cache.test.ts Adds regression test for reloading when tileset id points to a new asset.
tests/features/import-export/lib/imported-godot-project-session.test.ts Tests the imported Godot project session replacement flow.
tests/features/import-export/lib/import-export-godot-project.test.ts Tests Godot project export layout + re-import and zip rebasing + missing-resource dedupe.
src/types/index.ts Re-exports new GIF-related types.
src/types/gifenc.d.ts Extends gifenc type declarations for additional options used by the app.
src/types/gif.ts Adds public types for GIF encoding inputs/options.
src/services/gif.ts New shared GIF encoding service using gifenc, with transparency handling.
src/features/map-editor/types/tileset-panel.ts Extracts tileset panel prop/types into a dedicated types module.
src/features/map-editor/types/tileset-import.ts Adds types for queued image imports, placement, and merge results.
src/features/map-editor/types/editor-ui.ts Extends TilesetCanvasProps for placement preview + placement updates.
src/features/map-editor/lib/tileset-image-merge.ts Implements canvas-based merge of an imported image into a tileset asset.
src/features/map-editor/lib/tileset-image-import.ts Adds helpers for recognizing/normalizing tileset image imports and decoding images.
src/features/map-editor/hooks/use-tileset-image-import.ts Adds state machine hook for tileset image import flow (idle/choice/placement).
src/features/map-editor/components/TilesetToolbar.tsx Extracts tileset toolbar UI into its own component.
src/features/map-editor/components/TilesetPlacementControls.tsx Adds UI controls for tile-grid placement before committing a merge.
src/features/map-editor/components/TilesetPanel.tsx Integrates new tileset image import flow, placement preview, merge commit, and dialogs.
src/features/map-editor/components/TilesetImportChoiceDialog.tsx Adds dialog to choose “new tileset” vs “add to active tileset”.
src/features/map-editor/components/TilesetDeleteDialog.tsx Extracts delete confirmation dialog into a standalone component.
src/features/map-editor/components/TilesetCanvas.tsx Adds placement preview rendering + drag-to-position behavior.
src/features/map-editor/components/MapCanvas/texture-cache.ts Tracks assetId per tileset cache entry; reloads when asset changes; adds inflight assetId tracking.
src/features/map-editor/components/MapCanvas/index.tsx Adjusts types/props wiring (removes unused TileRef import; adds paintBuffer pass-through).
src/features/import-export/types/index.ts Adds Godot project import/export types and pending import dialog state.
src/features/import-export/lib/imported-godot-project-session.ts Adds “replace editor project with imported Godot project” orchestration + optional tileset dedupe.
src/features/import-export/lib/import-export-raster.ts Switches GIF encoding to the shared encodeGifFrames() service.
src/features/import-export/lib/import-export-options.ts Adds “project-godot” option definition + helper.
src/features/import-export/lib/import-export-godot-project.ts Implements Godot project zip import prep, scene detection, metadata parsing, and export entry planning.
src/features/import-export/lib/godot-project-warning-utils.ts Adds helper to alert + log Godot project import warnings.
src/features/import-export/lib/godot-project-action-utils.ts Adds export action for Godot project archives.
src/features/import-export/lib/dialog-prop-utils.ts Adds selectOpenDialogProps() helper to simplify dialog prop selection.
src/features/import-export/hooks/use-project-import-export-action.ts Centralizes project import/export option selection logic (native/tiled/godot).
src/features/import-export/hooks/use-import-export-actions.ts Wires in Godot project import flow + uses dialog selection helper.
src/features/import-export/hooks/use-godot-project-import.ts Implements zip/file/folder Godot project import UX including missing-resource resolution.
src/features/import-export/components/GodotProjectFilesDialog.tsx Adds dialog prompting for a Godot project folder when importing .godot alone.
src/features/image-editor/hooks/use-image-editor.ts Switches image editor GIF export to shared encodeGifFrames().
src/features/app-shell/components/AppShell.tsx Lazily loads and renders the new Godot project files dialog.
AGENTS.md Removes prior “code search” guidance and keeps ARIA/accessibility rule.
.gitignore Fixes coverage ignore rule to ignore the full coverage directory.

Comment on lines +24 to +31
for (const tileset of draft.project.tilesets) {
const key = `${tileset.name}__${tileset.tileSize}__${tileset.imageWidth}__${tileset.imageHeight}`;
const canonical = seen.get(key);
if (canonical !== undefined) {
remapIds.set(tileset.id as string, canonical);
} else {
seen.set(key, tileset.id);
}
Comment on lines +5 to +9
export function isTilesetImageFile(file: File): boolean {
return (
file.type.startsWith("image/") ||
RASTER_IMAGE_EXTENSION_PATTERN.test(file.name)
);
Comment on lines +326 to +327
point.x <= placementPreview.position.x + placementPreview.width &&
point.y <= placementPreview.position.y + placementPreview.height;
Comment on lines 37 to +44
const inflight = loadingTilesetPromises.get(tilesetId);
if (inflight) return inflight;
if (inflight && loadingTilesetAssetIds.get(tilesetId) === assetId) {
return inflight;
}
if (inflight) {
loadingTilesetPromises.delete(tilesetId);
}
loadingTilesetAssetIds.set(tilesetId, assetId);
@wernerbihl
Copy link
Copy Markdown
Collaborator Author

@copilot apply changes based on the comments in this thread

…unds, URL leak

Agent-Logs-Url: https://github.com/2dtiler/app/sessions/ee9fb69b-c815-4be6-aadc-150cc9a63612

Co-authored-by: wernerbihl <1950410+wernerbihl@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

@copilot apply changes based on the comments in this thread

Applied all 4 review fixes in commit 04b92f1:

  1. deduplicateProjectTilesets() — Added assetId to the deduplication key so only tilesets that reference the exact same image asset are considered duplicates.
  2. isTilesetImageFile() — Replaced the broad image/* check with an explicit allowlist (image/png, image/jpeg, image/gif, image/bmp, image/webp) so SVG and other non-raster formats are excluded.
  3. TilesetCanvas.tsx hit-test — Changed <= to < on the right/bottom edge bounds to fix the off-by-one.
  4. texture-cache.ts URL leak — When replacing an in-flight load with a different assetId, any blob URL that the old in-flight load already stored in tilesetBlobUrls is now revoked and removed before starting the new load.

@wernerbihl wernerbihl merged commit a326280 into main May 5, 2026
4 checks passed
@wernerbihl wernerbihl deleted the feature/2026-05-05 branch May 5, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants