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
- Variables
- func AttachLintDiagnostics(run *lint.RunContext, diagnostics []lint.Diagnostic)
- func DiagnosticByCode(code lint.Code) (lint.CodeSpec, bool)
- func DiagnosticCatalog() []lint.CodeSpec
- func DiagnosticRuleSpec(spec lint.CodeSpec) (lint.RuleSpec, error)
- func Format(document *Document, opts *FormatOptions) ([]byte, error)
- func LintRuleID(code lint.Code) string
- func LintRuleSpecs() []lint.RuleSpec
- func NormalizeName(input string, useCamelCase bool) string
- func RegisterLintRules(registrar lint.RuleRegistrar) error
- func RegisterLintRulesByScope(registrar lint.RuleRegistrar, scopes ...string) error
- func RegisterLintRulesByStage(registrar lint.RuleRegistrar, stages ...lint.Stage) error
- func Validate(document *Document) error
- func ValidateWithOptions(document *Document, options *ValidateOptions) error
- func Write(writer io.Writer, document *Document, opts *FormatOptions) error
- func WriteFile(path string, document *Document, opts *FormatOptions) (err error)
- type Document
- type Flags
- type FormatOptions
- type Group
- type Image
- type ImagePaddingRuleOptions
- type LintRulesProvider
- func (provider LintRulesProvider) RegisterRules(registrar lint.RuleRegistrar) error
- func (provider LintRulesProvider) RegisterRulesByScope(registrar lint.RuleRegistrar, scopes ...string) error
- func (provider LintRulesProvider) RegisterRulesByStage(registrar lint.RuleRegistrar, stages ...lint.Stage) error
- type ParseError
- type Point
- type Size
- type Texture
- type ValidateOptions
- type ValidationError
Constants ¶
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 )
const (
// LintModule is stable lint module namespace for imageset rules.
LintModule = "imageset"
)
const ( // StageValidate marks semantic validation diagnostics. StageValidate lint.Stage = "validate" )
Variables ¶
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
DiagnosticByCode returns diagnostic metadata for code.
func DiagnosticCatalog ¶ added in v0.2.0
DiagnosticCatalog returns stable diagnostics metadata list.
func DiagnosticRuleSpec ¶ added in v0.2.0
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
LintRuleID returns lint rule ID mapped from stable imageset diagnostic code.
func LintRuleSpecs ¶ added in v0.2.0
LintRuleSpecs returns deterministic lint rule specs from diagnostics catalog.
func NormalizeName ¶
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 ValidateWithOptions ¶ added in v0.2.0
func ValidateWithOptions(document *Document, options *ValidateOptions) error
ValidateWithOptions checks semantic constraints and returns aggregated error.
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 ParseBytes ¶
ParseBytes decodes .imageset text bytes into Document.
func ParseString ¶
ParseString decodes .imageset text from a string.
type Flags ¶
type Flags int
Flags is a DayZ .imageset bitset.
func ParseFlagsExpr ¶
ParseFlagsExpr parses numeric or symbolic flags expression.
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) 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.