#compdef rgbgfx

_depths() {
	local depths=(
		'1:1bpp'
		'2:2bpp (native)'
	)

	_describe 'bit depth' depths
}

_rgbgfx_warnings() {
	local warnings=(
		'error:Turn all warnings into errors'

		'all:Enable most warning messages'
		'everything:Enable literally everything'

		'embedded:Warn when using embedded PLTE without "-c embedded"'
		'obsolete:Warn when using deprecated features'
		'trim-nonempty:Warn when "-x" trims nonempty tiles'
	)
	_describe warning warnings
}

local args=(
	# Arguments are listed here in the same order as in the manual, except for the version and help
	'(- : * options)'{-V,--version}'[Print version number and exit]'
	'(- : * options)'{-h,--help}'[Print help text and exit]'

	'(-a --attr-map -A --auto-attr-map)'{-A,--auto-attr-map}'[Shortcut for -a <file>.attrmap]'
	'(-C --color-curve)'{-C,--color-curve}'[Generate palettes using GBC color curve]'
	'(-m --mirror-tiles)'{-m,--mirror-tiles}'[Eliminate mirrored tiles from output]'
	'(-O --group-outputs)'{-O,--group-outputs}'[Base "shortcut" options on the output path, not input]'
	'(-p --palette -P --auto-palette)'{-P,--auto-palette}'[Shortcut for -p <file>.pal]'
	'(-q --palette-map -Q --auto-palette-map)'{-Q,--auto-palette-map}'[Shortcut for -p <file>.palmap]'
	'(-t --tilemap -T --auto-tilemap)'{-T,--auto-tilemap}'[Shortcut for -t <file>.tilemap]'
	'(-u --unique-tiles)'{-u,--unique-tiles}'[Eliminate redundant tiles]'
	'(-v --verbose)'{-v,--verbose}'[Enable verbose output]'
	-w'[Disable all warnings]'
	'(-X --mirror-x)'{-X,--mirror-x}'[Eliminate horizontally mirrored tiles from output]'
	'(-Y --mirror-y)'{-Y,--mirror-y}'[Eliminate vertically mirrored tiles from output]'
	'(-Z --columns)'{-Z,--columns}'[Read the image in column-major order]'

	'(-a --attr-map -A --auto-attr-map)'{-a,--attr-map}'+[Generate a map of tile attributes (mirroring)]:attrmap file:_files'
	'(-B --background-color)'{-B,--background-color}'+[Ignore tiles containing only specified color]:color:'
	'(-b --base-tiles)'{-b,--base-tiles}'+[Base tile IDs for tile map output]:base tile IDs:'
	--color'[Whether to use color in output]:color:(auto always never)'
	'(-c --colors)'{-c,--colors}'+[Specify color palettes]:palette spec:'
	'(-d --depth)'{-d,--depth}'+[Set bit depth]:bit depth:_depths'
	'(-i --input-tileset)'{-i,--input-tileset}'+[Use specific tiles]:tileset file:_files -g "*.2bpp"'
	'(-L --slice)'{-L,--slice}'+[Only process a portion of the image]:input slice:'
	'(-N --nb-tiles)'{-N,--nb-tiles}'+[Limit number of tiles]:tile count:'
	'(-n --nb-palettes)'{-n,--nb-palettes}'+[Limit number of palettes]:palette count:'
	'(-o --output)'{-o,--output}'+[Set output file]:output file:_files'
	'(-p --palette -P --auto-palette)'{-p,--palette}"+[Output the image's palette in little-endian native RGB555 format]:palette file:_files"
	'(-q --palette-map -Q --auto-palette-map)'{-q,--palette-map}"+[Output the image's palette map]:palette map file:_files"
	'(-r --reverse)'{-r,--reverse}'+[Yield an image from binary data]:image width (in tiles):'
	'(-s --palette-size)'{-s,--palette-size}'+[Limit palette size]:palette size:'
	'(-t --tilemap -T --auto-tilemap)'{-t,--tilemap}'+[Generate a map of tile indices]:tilemap file:_files'
	'(-W --warning)'{-W,--warning}'+[Toggle warning flags]:warning flag:_rgbgfx_warnings'
	'(-x --trim-end)'{-x,--trim-end}'+[Trim end of output by this many tiles]:tile count:'

	":input png file:_files -g '*.png'"
)
_arguments -s -S : $args
