2023-08-03 21:07:58 +02:00
|
|
|
package reader
|
|
|
|
|
2023-08-11 12:30:37 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"image/color"
|
|
|
|
)
|
|
|
|
|
2023-08-03 21:07:58 +02:00
|
|
|
type Reader interface {
|
2023-08-05 16:36:49 +02:00
|
|
|
Read() (*RawMaze, error)
|
2023-08-03 21:07:58 +02:00
|
|
|
}
|
2023-08-11 12:30:37 +02:00
|
|
|
|
|
|
|
type ReaderFactory struct {
|
|
|
|
Type string
|
|
|
|
Filename *string
|
|
|
|
PathChar, WallChar, SolutionChar *string
|
|
|
|
CellWidth, CellHeight *int
|
|
|
|
WallColor, PathColor color.Color
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
_IMAGE = "image"
|
|
|
|
_TEXT = "text"
|
|
|
|
)
|
|
|
|
|
|
|
|
var TYPES = map[string]string{
|
|
|
|
".png": _IMAGE,
|
|
|
|
".txt": _TEXT,
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ReaderFactory) Get() Reader {
|
|
|
|
switch f.Type {
|
|
|
|
case _TEXT:
|
|
|
|
return &TextReader{
|
|
|
|
Filename: *f.Filename,
|
|
|
|
PathChar: byte((*f.PathChar)[0]),
|
|
|
|
WallChar: byte((*f.WallChar)[0]),
|
|
|
|
}
|
|
|
|
case _IMAGE:
|
|
|
|
return &ImageReader{
|
|
|
|
Filename: *f.Filename,
|
|
|
|
CellWidth: *f.CellWidth,
|
|
|
|
CellHeight: *f.CellHeight,
|
|
|
|
WallColor: f.WallColor,
|
|
|
|
PathColor: f.PathColor,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic(fmt.Sprintf("Unrecognized reader type %q", f.Type))
|
|
|
|
}
|