Fantasy-Map-Generator/modules
Claude 20458e39e2
Add external API integration for wiki/web UI synchronization
This commit adds a comprehensive external API system that allows external tools
(wikis, web UIs, etc.) to control and synchronize with Fantasy Map Generator.

New Features:
- External API Bridge (modules/external-api.js)
  - Event-driven architecture with EventEmitter
  - Map lifecycle control (create, load, save)
  - Data access methods (rivers, cultures, states, burgs)
  - Data mutation methods with auto-redraw
  - Export support (SVG, PNG, JSON)
  - Change detection with automatic event emission

- PostMessage Communication Layer
  - Auto-enables when FMG is embedded in iframe
  - Bidirectional message passing
  - Request/response pattern with promise support
  - Automatic event forwarding to parent window

- REST API Server (api-server/)
  - Express.js server with full CRUD operations
  - WebSocket support via Socket.IO for real-time updates
  - File upload support for map and CSV import
  - In-memory storage (can be replaced with database)
  - CORS enabled for cross-origin requests
  - Comprehensive endpoints for all map data

- Client Library (api-server/client.js)
  - Simple JavaScript client for REST API
  - Promise-based async methods
  - Works in browser and Node.js

- Demo Pages (demos/)
  - PostMessage integration demo with full UI
  - REST API demo with interactive testing
  - WebSocket demo for real-time events

- Documentation
  - Comprehensive integration guide (EXTERNAL_API_INTEGRATION.md)
  - API reference with TypeScript interfaces
  - Multiple integration examples
  - Troubleshooting guide

Integration Methods:
1. PostMessage Bridge - For iframe embedding
2. REST API - For server-side integration
3. Direct JavaScript API - For same-origin apps

Use Cases:
- Wiki pages that need to display and control maps
- Web UIs that want to edit map data
- External tools that need to sync with FMG
- Real-time collaborative map editing
- Batch operations and automation

Technical Details:
- Zero dependencies for external-api.js (pure JS)
- Auto-initializes on DOMContentLoaded
- Throttled change detection (500ms debounce)
- Deep cloning for data access (prevents mutations)
- Error handling throughout
- Version tagged (v1.0.0)

Updated Files:
- index.html: Added script tag to load external-api module

All APIs are backward compatible and don't affect existing functionality.
2025-11-04 21:43:06 +00:00
..
dynamic fix: cultures editor - don't overwrite border color on color change 2023-12-05 02:45:55 +04:00
io Fully load river from save files 2024-01-16 16:43:05 +01:00
renderers hotfix: filename conflict 2023-08-11 19:03:21 +04:00
ui Fully load river from save files 2024-01-16 16:43:05 +01:00
biomes.js feat: move biomes code to a separate module, reduce deserts amount 2023-08-11 14:31:08 +04:00
burgs-and-states.js State labels: new label placing algorithm (#977) 2023-08-11 18:56:42 +04:00
coa-generator.js feat: add new emblem charges 2023-10-30 22:27:25 +04:00
coa-renderer.js Fix: rework texture data format (#1017) 2023-11-19 14:43:56 +04:00
cultures-generator.js fix(#932): priority queue to check correct attr 2023-04-15 14:09:06 +04:00
external-api.js Add external API integration for wiki/web UI synchronization 2025-11-04 21:43:06 +00:00
fonts.js refactor(1.89.18): cleanup fonts usage 2023-05-13 15:55:08 +04:00
heightmap-generator.js feat: heightmap brushes - linear edit option (1.88.00) 2022-10-31 00:24:54 +03:00
lakes.js replace old iife by a simpler ones 2021-08-04 23:49:02 +03:00
markers-generator.js fix: Chrome hides layers with dropShadow... 2023-09-24 02:56:19 +04:00
military-generator.js Dev submaps (#770) 2022-04-15 12:45:02 +03:00
names-generator.js Turkish culture fixes (#968) 2023-08-01 20:41:14 +04:00
ocean-layers.js feat: optimizeSpeed rendering (1.87.15) 2022-10-13 00:52:49 +03:00
relief-icons.js minmax util function 2021-10-10 17:59:27 +03:00
religions-generator.js fix: add missing religion name variants 2023-11-06 00:13:11 +04:00
river-generator.js fix(add river): get id as the biggest id + 1, not the last id + 1 2023-03-26 14:24:46 +04:00
routes-generator.js routes - don't break if feature is not found 2022-04-09 21:52:37 +05:00
submap.js fix: move scaleBar to the corner of svg export 2023-11-19 20:10:42 +04:00
voronoi.js Fix: flux calculation from area-propotional value instead of normal value. (#654) 2021-08-15 12:43:20 +03:00