1package pdfexport23import (4 "encoding/json"5 "fmt"6 "strings"7)89type hashiSave struct {10 Width int `json:"width"`11 Height int `json:"height"`12 Islands []hashiIsland `json:"islands"`13}1415type hashiIsland struct {16 X int `json:"x"`17 Y int `json:"y"`18 Required int `json:"required"`19}2021func ParseHashiPrintData(saveData []byte) (*HashiData, error) {22 if len(strings.TrimSpace(string(saveData))) == 0 {23 return nil, nil24 }2526 var save hashiSave27 if err := json.Unmarshal(saveData, &save); err != nil {28 return nil, fmt.Errorf("decode hashiwokakero save: %w", err)29 }30 if save.Width <= 0 || save.Height <= 0 {31 return nil, nil32 }3334 islands := make([]HashiIsland, 0, len(save.Islands))35 for _, island := range save.Islands {36 if island.X < 0 || island.X >= save.Width || island.Y < 0 || island.Y >= save.Height {37 continue38 }39 if island.Required <= 0 {40 continue41 }42 islands = append(islands, HashiIsland(island))43 }4445 return &HashiData{46 Width: save.Width,47 Height: save.Height,48 Islands: islands,49 }, nil50}