svgimport

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package svgimport turns an SVG drawing into map wall outlines, so a level's geometry can be drawn in Inkscape/Figma/Illustrator and imported instead of typed by hand.

The parser is adapted from kutta's stdlib-only foil/svg.go (same author). The difference is the coordinate handling: foil normalizes every shape into its [0,1] y-up ".dat" convention, whereas a Linefire map wants the drawing's own coordinates. The game world is Y-DOWN, exactly like SVG, so shapes import 1:1 with no flip and no rescale — what you draw is where it lands. Curves (cubic, quadratic, arc) are flattened to polylines, so a wall is always a plain polygon, which is all the collision/flood field needs.

Supported: path (M L H V C S Q T A Z and their relative forms), rect, circle, ellipse, polygon and polyline. Not interpreted: transform attributes, fill rules and strokes — flatten transforms in the editor before exporting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Centroid

func Centroid(pts []asset.Point) asset.Point

Centroid is the average of a shape's points — where a spawn marker drops its entity.

func Outlines

func Outlines(data []byte) ([][]asset.Point, error)

Outlines reads an SVG into closed outlines, dropping the marker labels (see Shapes).

func Paths

func Paths(data []byte) ([]asset.Path, error)

Paths reads an SVG into closed wall paths, dropping the marker labels: each shape becomes a move to its first point, a line to each subsequent point, and a close.

Types

type Shape

type Shape struct {
	Label  string
	Points []asset.Point
}

Shape is one imported closed outline plus its marker label — the element's inkscape:label or, failing that, its id. An empty label means the shape carries no marker (a plain wall).

func Shapes

func Shapes(data []byte) ([]Shape, error)

Shapes reads an SVG document into closed shapes, one per subpath or basic shape, each with its marker label, in the drawing's own coordinates (SVG user units, y-down). Degenerate shapes (fewer than three points) are dropped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL