1package wordsearch23import (4 "encoding/json"56 "github.com/FelineStateMachine/puzzletea/game"7)89type Save struct {10 Width int `json:"width"`11 Height int `json:"height"`12 Grid string `json:"grid"`13 Words []Word `json:"words"`14 CursorX int `json:"cursor_x"`15 CursorY int `json:"cursor_y"`16 Selection int `json:"selection"`17 SelectionX int `json:"selection_x"`18 SelectionY int `json:"selection_y"`19 Solved bool `json:"solved"`20}2122func ImportModel(data []byte) (*Model, error) {23 var exported Save24 if err := json.Unmarshal(data, &exported); err != nil {25 return nil, err26 }2728 return &Model{29 width: exported.Width,30 height: exported.Height,31 grid: newGrid(state(exported.Grid)),32 words: exported.Words,33 cursor: game.Cursor{X: exported.CursorX, Y: exported.CursorY},34 selection: selectionState(exported.Selection),35 selectionStart: game.Cursor{X: exported.SelectionX, Y: exported.SelectionY},36 keys: DefaultKeyMap,37 solved: exported.Solved,38 foundCells: buildFoundCells(exported.Width, exported.Height, exported.Words),39 }, nil40}4142func (m Model) GetSave() ([]byte, error) {43 data := Save{44 Width: m.width,45 Height: m.height,46 Grid: m.grid.String(),47 Words: m.words,48 CursorX: m.cursor.X,49 CursorY: m.cursor.Y,50 Selection: int(m.selection),51 SelectionX: m.selectionStart.X,52 SelectionY: m.selectionStart.Y,53 Solved: m.solved,54 }55 return json.Marshal(data)56}