imageset

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 11 Imported by: 0

README

imageset

imageset is a Go module for DayZ .imageset files.

It provides:

  • parser from file, reader, bytes, or string
  • canonical text formatter/writer
  • semantic validation with structured diagnostics
  • lintkit/lint provider registration (RegisterLintRules) and codes catalog
  • identifier normalization helpers
  • symbolic and numeric flags parsing
  • generated lint rules snapshot and docs: rules.yaml, RULES.md

Install

go get github.com/woozymasta/imageset

Quick Example

package main

import (
    "log"

    "github.com/woozymasta/imageset"
)

func main() {
    doc, err := imageset.ParseFile("ui.imageset")
    if err != nil {
        log.Fatal(err)
    }

    if err := imageset.Validate(doc); err != nil {
        log.Fatal(err)
    }

    err = imageset.WriteFile("ui_out.imageset", doc, &imageset.FormatOptions{
        UseCamelCaseNames: false,
    })
    if err != nil {
        log.Fatal(err)
    }
}

Documentation

Overview

Package imageset provides parser, formatter, and validation helpers for DayZ .imageset files.

The package centers around Document:

  • Parse/ParseBytes/ParseFile read .imageset text into Document
  • Write/Format serialize Document back to canonical text form
  • Validate checks semantic constraints with stable diagnostic codes
  • ValidateWithOptions enables optional checks such as padding

Common flow:

doc, err := imageset.ParseFile("ui.imageset")
if err != nil {
	// handle parse error
}
if err := imageset.Validate(doc); err != nil {
	// handle validation diagnostics
}

lintkit integration is included to expose stable rule metadata and register imageset diagnostics in shared lint pipelines.

Index

Constants

View Source
const (
	// CodeValidateRefSizeWidthNonPositive reports non-positive atlas width.
	CodeValidateRefSizeWidthNonPositive lint.Code = 2001

	// CodeValidateRefSizeHeightNonPositive reports non-positive atlas height.
	CodeValidateRefSizeHeightNonPositive lint.Code = 2002

	// CodeValidateRefSizeNonPowerOfTwo reports non-power-of-two ref_size side.
	CodeValidateRefSizeNonPowerOfTwo lint.Code = 2003

	// CodeValidateTexturesEmpty reports missing Textures section entries.
	CodeValidateTexturesEmpty lint.Code = 2004

	// CodeValidateTexturePathEmpty reports empty texture path.
	CodeValidateTexturePathEmpty lint.Code = 2005

	// CodeValidateTextureMpixNegative reports negative texture mpix.
	CodeValidateTextureMpixNegative lint.Code = 2006

	// CodeValidateImagesEmpty reports missing root Images section entries.
	CodeValidateImagesEmpty lint.Code = 2007

	// CodeValidateGroupNameEmpty reports empty group name.
	CodeValidateGroupNameEmpty lint.Code = 2008

	// CodeValidateGroupNameDuplicate reports duplicate group name.
	CodeValidateGroupNameDuplicate lint.Code = 2009

	// CodeValidateGroupImagesEmpty reports empty images list inside group.
	CodeValidateGroupImagesEmpty lint.Code = 2010

	// CodeValidateImageNameEmpty reports empty image name.
	CodeValidateImageNameEmpty lint.Code = 2011

	// CodeValidateImageNameDuplicate reports duplicate image name.
	CodeValidateImageNameDuplicate lint.Code = 2012

	// CodeValidateImageNameDuplicateGlobal reports duplicate image name globally.
	CodeValidateImageNameDuplicateGlobal lint.Code = 2013

	// CodeValidateImagePosXNegative reports negative image x coordinate.
	CodeValidateImagePosXNegative lint.Code = 2014

	// CodeValidateImagePosYNegative reports negative image y coordinate.
	CodeValidateImagePosYNegative lint.Code = 2015

	// CodeValidateImageWidthNonPositive reports non-positive image width.
	CodeValidateImageWidthNonPositive lint.Code = 2016

	// CodeValidateImageHeightNonPositive reports non-positive image height.
	CodeValidateImageHeightNonPositive lint.Code = 2017

	// CodeValidateImageOutOfBoundsWidth reports atlas width overflow.
	CodeValidateImageOutOfBoundsWidth lint.Code = 2018

	// CodeValidateImageOutOfBoundsHeight reports atlas height overflow.
	CodeValidateImageOutOfBoundsHeight lint.Code = 2019

	// CodeValidateImageFlagsUnsupportedMask reports unsupported image flags mask.
	CodeValidateImageFlagsUnsupportedMask lint.Code = 2020

	// CodeValidateImageOverlap reports overlapping image rectangles.
	CodeValidateImageOverlap lint.Code = 2021

	// CodeValidateImagePaddingTooSmall reports too small gap between images.
	CodeValidateImagePaddingTooSmall lint.Code = 2022
)
View Source
const (
	// LintModule is stable lint module namespace for imageset rules.
	LintModule = "imageset"
)
View Source
const (
	// StageValidate marks semantic validation diagnostics.
	StageValidate lint.Stage = "validate"
)

Variables

View Source
var (
	// ErrInvalidSyntax means input text does not match expected .imageset syntax.
	ErrInvalidSyntax = errors.New("imageset: invalid syntax")

	// ErrNilDocument means API was called with nil *Document.
	ErrNilDocument = errors.New("imageset: nil document")

	// ErrUnknownFlag means a flag token is not recognized.
	ErrUnknownFlag = errors.New("imageset: unknown flag")

	// ErrNilLintRuleRegistrar indicates nil lint rule registrar in registration.
	ErrNilLintRuleRegistrar = lint.ErrNilRuleRegistrar
)

Functions

func AttachLintDiagnostics added in v0.2.0

func AttachLintDiagnostics(run *lint.RunContext, diagnostics []lint.Diagnostic)

AttachLintDiagnostics stores diagnostics in run context values.

func DiagnosticByCode added in v0.2.0

func DiagnosticByCode(code lint.Code) (lint.CodeSpec, bool)

DiagnosticByCode returns diagnostic metadata for code.

func DiagnosticCatalog added in v0.2.0

func DiagnosticCatalog() []lint.CodeSpec

DiagnosticCatalog returns stable diagnostics metadata list.

func DiagnosticRuleSpec added in v0.2.0

func DiagnosticRuleSpec(spec lint.CodeSpec) (lint.RuleSpec, error)

DiagnosticRuleSpec converts one diagnostic spec into lint rule metadata.

func Format

func Format(document *Document, opts *FormatOptions) ([]byte, error)

Format serializes document and returns encoded bytes.

func LintRuleID added in v0.2.0

func LintRuleID(code lint.Code) string

LintRuleID returns lint rule ID mapped from stable imageset diagnostic code.

func LintRuleSpecs added in v0.2.0

func LintRuleSpecs() []lint.RuleSpec

LintRuleSpecs returns deterministic lint rule specs from diagnostics catalog.

func NormalizeName

func NormalizeName(input string, useCamelCase bool) string

NormalizeName converts a name to a safe imageset identifier.

Output contains only ASCII letters, digits, and underscore. If useCamelCase is true, tokens are joined as CamelCase. Otherwise tokens are joined as snake_case.

func RegisterLintRules added in v0.2.0

func RegisterLintRules(registrar lint.RuleRegistrar) error

RegisterLintRules registers stable imageset rules into registrar.

func RegisterLintRulesByScope added in v0.2.0

func RegisterLintRulesByScope(
	registrar lint.RuleRegistrar,
	scopes ...string,
) error

RegisterLintRulesByScope registers imageset rules filtered by scope tokens.

func RegisterLintRulesByStage added in v0.2.0

func RegisterLintRulesByStage(
	registrar lint.RuleRegistrar,
	stages ...lint.Stage,
) error

RegisterLintRulesByStage registers imageset rules filtered by stage tokens.

func Validate

func Validate(document *Document) error

Validate checks semantic constraints and returns aggregated error.

func ValidateWithOptions added in v0.2.0

func ValidateWithOptions(document *Document, options *ValidateOptions) error

ValidateWithOptions checks semantic constraints and returns aggregated error.

func Write

func Write(writer io.Writer, document *Document, opts *FormatOptions) error

Write serializes document into .imageset text form.

func WriteFile

func WriteFile(path string, document *Document, opts *FormatOptions) (err error)

WriteFile serializes document and writes the result to file path.

Types

type Document

type Document struct {
	Name     string    `json:"name,omitempty" yaml:"name,omitempty"`         // Set name.
	Textures []Texture `json:"textures,omitempty" yaml:"textures,omitempty"` // Textures list.
	Images   []Image   `json:"images,omitempty" yaml:"images,omitempty"`     // Root images.
	Groups   []Group   `json:"groups,omitempty" yaml:"groups,omitempty"`     // Groups list.
	RefSize  Size      `json:"ref_size" yaml:"ref_size"`                     // Atlas size.
}

Document is the root .imageset model.

func Parse

func Parse(reader io.Reader) (*Document, error)

Parse decodes .imageset text from reader into Document.

func ParseBytes

func ParseBytes(data []byte) (*Document, error)

ParseBytes decodes .imageset text bytes into Document.

func ParseFile

func ParseFile(path string) (*Document, error)

ParseFile decodes .imageset file from disk.

func ParseString

func ParseString(data string) (*Document, error)

ParseString decodes .imageset text from a string.

type Flags

type Flags int

Flags is a DayZ .imageset bitset.

const (
	// FlagHorizontalTile corresponds to ISHorizontalTile.
	FlagHorizontalTile Flags = 1

	// FlagVerticalTile corresponds to ISVerticalTile.
	FlagVerticalTile Flags = 2
)

func ParseFlagsExpr

func ParseFlagsExpr(expr string) (Flags, error)

ParseFlagsExpr parses numeric or symbolic flags expression.

func (Flags) Has

func (f Flags) Has(flag Flags) bool

Has reports whether a specific flag bit is set.

func (Flags) String

func (f Flags) String() string

String returns a stable symbolic representation.

type FormatOptions

type FormatOptions struct {
	// Indentation string for one level.
	Indent string `json:"indent,omitempty" yaml:"indent,omitempty"`

	// Normalize names as CamelCase.
	UseCamelCaseNames bool `json:"camel_case,omitempty" yaml:"camel_case,omitempty"`
}

FormatOptions controls .imageset formatting behavior.

type Group

type Group struct {
	Name   string  `json:"name" yaml:"name"`                         // Group name.
	Images []Image `json:"images,omitempty" yaml:"images,omitempty"` // Group images.
}

Group defines a named collection of images.

type Image

type Image struct {
	Name  string `json:"name" yaml:"name"`                       // Image name.
	Pos   Point  `json:"pos" yaml:"pos"`                         // Top-left position.
	Size  Size   `json:"size" yaml:"size"`                       // Sprite size.
	Flags Flags  `json:"flags,omitempty" yaml:"flags,omitempty"` // Tile flags bitset.
}

Image defines one sprite entry in .imageset.

type ImagePaddingRuleOptions added in v0.2.0

type ImagePaddingRuleOptions struct {
	// MinPadding stores minimum allowed gap between image rectangles.
	MinPadding int `json:"min_padding" yaml:"min_padding"`
}

ImagePaddingRuleOptions documents lint rule options for padding check.

type LintRulesProvider added in v0.2.0

type LintRulesProvider struct{}

LintRulesProvider registers imageset rules into any RuleRegistrar.

func (LintRulesProvider) RegisterRules added in v0.2.0

func (provider LintRulesProvider) RegisterRules(
	registrar lint.RuleRegistrar,
) error

RegisterRules adds provider-owned rules to target registrar.

func (LintRulesProvider) RegisterRulesByScope added in v0.2.0

func (provider LintRulesProvider) RegisterRulesByScope(
	registrar lint.RuleRegistrar,
	scopes ...string,
) error

RegisterRulesByScope adds provider-owned rules filtered by scope tokens.

func (LintRulesProvider) RegisterRulesByStage added in v0.2.0

func (provider LintRulesProvider) RegisterRulesByStage(
	registrar lint.RuleRegistrar,
	stages ...lint.Stage,
) error

RegisterRulesByStage adds provider-owned rules filtered by stage tokens.

type ParseError

type ParseError struct {
	Cause   error // Underlying parse error.
	Message string
	Line    int // 1-based line number.
}

ParseError reports parse failure with line context.

func (*ParseError) Error

func (e *ParseError) Error() string

Error formats the parse error.

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

Unwrap returns the underlying parse cause.

type Point

type Point struct {
	X int `json:"x" yaml:"x"` // Horizontal coordinate.
	Y int `json:"y" yaml:"y"` // Vertical coordinate.
}

Point represents a 2D pixel position.

type Size

type Size struct {
	Width  int `json:"width" yaml:"width"`   // Width in pixels.
	Height int `json:"height" yaml:"height"` // Height in pixels.
}

Size represents width and height in pixels.

type Texture

type Texture struct {
	Path string `json:"path" yaml:"path"`                     // Texture path.
	Mpix int    `json:"mpix,omitempty" yaml:"mpix,omitempty"` // Pixels per meter.
}

Texture defines a texture reference used by .imageset.

type ValidateOptions added in v0.2.0

type ValidateOptions struct {
	// EnablePaddingCheck enables optional minimum image-gap check.
	EnablePaddingCheck bool `json:"enable_padding_check,omitempty" yaml:"enable_padding_check,omitempty"`

	// MinPadding stores minimum allowed gap between image rectangles.
	// Used only when EnablePaddingCheck is true.
	MinPadding int `json:"min_padding,omitempty" yaml:"min_padding,omitempty"`
}

ValidateOptions configures optional semantic checks.

type ValidationError

type ValidationError struct {
	Diagnostics []lint.Diagnostic `json:"diagnostics" yaml:"diagnostics"` // Issues list.
}

ValidationError aggregates semantic validation diagnostics.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error formats validation diagnostics as one sentence.

Jump to

Keyboard shortcuts

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