1package pdfexport23import (4 "encoding/json"5 "fmt"6 "strings"7)89type shikakuSave struct {10 Width int `json:"width"`11 Height int `json:"height"`12 Clues []shikakuClue `json:"clues"`13}1415type shikakuClue struct {16 X int `json:"x"`17 Y int `json:"y"`18 Value int `json:"value"`19}2021func ParseShikakuPrintData(saveData []byte) (*ShikakuData, error) {22 if len(strings.TrimSpace(string(saveData))) == 0 {23 return nil, nil24 }2526 var save shikakuSave27 if err := json.Unmarshal(saveData, &save); err != nil {28 return nil, fmt.Errorf("decode shikaku save: %w", err)29 }30 if save.Width <= 0 || save.Height <= 0 {31 return nil, nil32 }3334 clues := make([][]int, save.Height)35 for y := 0; y < save.Height; y++ {36 clues[y] = make([]int, save.Width)37 }3839 for _, clue := range save.Clues {40 if clue.X < 0 || clue.X >= save.Width || clue.Y < 0 || clue.Y >= save.Height {41 continue42 }43 if clue.Value <= 0 {44 continue45 }46 clues[clue.Y][clue.X] = clue.Value47 }4849 return &ShikakuData{50 Width: save.Width,51 Height: save.Height,52 Clues: clues,53 }, nil54}