{
  "openapi": "3.1.1",
  "info": {
    "title": "Autotile Generator (blob 47 and Wang 16 rules) API",
    "version": "1.0.0",
    "summary": "Turn a terrain grid into autotiled tile ids, a TMX map and a PNG preview.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://fliplineautotilegenerator.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Turn a terrain grid into autotiled tile ids, a TMX map and a PNG preview.",
        "description": "Draw terrain as # and . rows and choose the 47-tile blob set or the 16-tile Wang edge or corner set. The rule engine picks each tile variant from its neighbours and returns tile indices, a Tiled TMX map, a rendered PNG and merged collision rectangles.\n\nMethodology:\n- Blob (47): the 8-neighbour mask uses N=1, NE=2, E=4, SE=8, S=16, SW=32, W=64, NW=128; a corner only counts when both adjacent edges are terrain, which leaves 47 distinct masks. Flipline slot order is the ascending mask value (slot 0 = mask 0, slot 46 = mask 255).\n- Wang edge (16): mask N=1, E=2, S=4, W=8 of terrain cells. Wang corner (16): a vertex is terrain when any of its four cells is terrain; each cell’s mask is NE=1, SE=2, SW=4, NW=8, so terrain gains a one-cell ring of corner pieces. The slot equals the mask.\n- Missing variants fall back to the same edges without corners (blob), then to the full-terrain tile, and are listed as warnings. Wang sets are exported to Tiled as mixed, edge or corner sets with matching wangids.\n- The built-in tileset is drawn procedurally (original artwork) with a full-tile collision rectangle per tile (corner tiles: the covered quadrants), so collision rectangles are merged by greedy meshing.\n- Flipline’s Tilemap Desk autotile brush uses the same rule engine; painting the same cells there gives the same tile ids.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "flipline_autotile_generator",
        "x-owner-app": "flipline",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FliplineAutotileGeneratorInput"
              },
              "examples": {
                "example1": {
                  "summary": "Two islands with a lake (blob 47)",
                  "value": {
                    "terrain": "....................\n..######......###...\n.########....#####..\n.###..###....##.##..\n.########.....###...\n..######............\n....##.....#######..\n....##.....#######..\n..........##.....#..\n.#####.....#######..\n.#####..............\n....................",
                    "mode": "blob47",
                    "tileSize": 16,
                    "outside": "empty",
                    "orientation": "orthogonal",
                    "encoding": "csv",
                    "mapping": ""
                  }
                },
                "example2": {
                  "summary": "A cave edge with Wang edge tiles and zlib layers",
                  "value": {
                    "terrain": "##########\n#........#\n#..###...#\n#..#.#...#\n#..###..##\n#.......##\n##########",
                    "mode": "edge16",
                    "tileSize": 16,
                    "outside": "terrain",
                    "orientation": "orthogonal",
                    "encoding": "base64-zlib",
                    "mapping": ""
                  }
                },
                "example3": {
                  "summary": "Isometric pond with Wang corner tiles",
                  "value": {
                    "terrain": ".#####.\n#######\n##...##\n##...##\n##...##\n#######\n.#####.",
                    "mode": "corner16",
                    "tileSize": 32,
                    "outside": "empty",
                    "orientation": "isometric",
                    "encoding": "csv",
                    "mapping": ""
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FliplineAutotileGeneratorResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "FliplineAutotileGeneratorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "terrain": {
            "title": "Terrain rows (# = terrain, . = empty)",
            "type": "string",
            "maxLength": 70000,
            "default": "....................\n..######......###...\n.########....#####..\n.###..###....##.##..\n.########.....###...\n..######............\n....##.....#######..\n....##.....#######..\n..........##.....#..\n.#####.....#######..\n.#####..............\n...................."
          },
          "mode": {
            "title": "Rule set",
            "type": "string",
            "enum": [
              "blob47",
              "edge16",
              "corner16"
            ],
            "default": "blob47"
          },
          "tileSize": {
            "title": "Tile size (px)",
            "type": "integer",
            "minimum": 4,
            "maximum": 128,
            "default": 16
          },
          "outside": {
            "title": "Cells beyond the grid",
            "type": "string",
            "enum": [
              "empty",
              "terrain"
            ],
            "default": "empty"
          },
          "orientation": {
            "title": "Map orientation",
            "type": "string",
            "enum": [
              "orthogonal",
              "isometric"
            ],
            "default": "orthogonal"
          },
          "encoding": {
            "title": "TMX layer encoding",
            "type": "string",
            "enum": [
              "csv",
              "base64",
              "base64-zlib",
              "base64-gzip"
            ],
            "default": "csv"
          },
          "tileset": {
            "title": "Own tileset PNG (optional; tiles in slot order unless mapped)",
            "type": "object",
            "description": "Upload as {filename, contentType?, contentBase64}. Max 7813 KiB. Accepts .png.",
            "additionalProperties": false,
            "required": [
              "filename",
              "contentBase64"
            ],
            "properties": {
              "filename": {
                "type": "string"
              },
              "contentType": {
                "type": "string"
              },
              "contentBase64": {
                "type": "string"
              }
            }
          },
          "mapping": {
            "title": "Slot → tile mapping (optional; 47 or 16 numbers, −1 = missing)",
            "type": "string",
            "maxLength": 400,
            "default": ""
          }
        },
        "required": []
      },
      "FliplineAutotileGeneratorResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "width",
              "height",
              "mode",
              "terrainCells",
              "placed",
              "slots",
              "tiles",
              "gids",
              "missing",
              "tmx",
              "tmxFile",
              "png",
              "project",
              "collision"
            ],
            "properties": {
              "width": {
                "type": "integer"
              },
              "height": {
                "type": "integer"
              },
              "mode": {
                "type": "string"
              },
              "terrainCells": {
                "type": "integer"
              },
              "placed": {
                "type": "integer"
              },
              "slots": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "tiles": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "gids": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "missing": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "tmx": {
                "type": "string"
              },
              "tmxFile": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              },
              "png": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              },
              "project": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              },
              "collision": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "solidCells",
                  "mergedRects",
                  "oneWayRuns",
                  "shapes",
                  "skippedShapes",
                  "rects"
                ],
                "properties": {
                  "solidCells": {
                    "type": "integer"
                  },
                  "mergedRects": {
                    "type": "integer"
                  },
                  "oneWayRuns": {
                    "type": "integer"
                  },
                  "shapes": {
                    "type": "integer"
                  },
                  "skippedShapes": {
                    "type": "integer"
                  },
                  "rects": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "x",
                        "y",
                        "width",
                        "height"
                      ],
                      "properties": {
                        "x": {
                          "type": "number"
                        },
                        "y": {
                          "type": "number"
                        },
                        "width": {
                          "type": "number"
                        },
                        "height": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}