MCPcopy Create free account
hub / github.com/SolarLune/masterplan / Serialize

Method Serialize

page.go:262–284  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

260}
261
262func (page *Page) Serialize() string {
263
264 pageData := "{}"
265
266 pageData, _ = sjson.Set(pageData, "id", page.ID)
267 pageData, _ = sjson.Set(pageData, "pan", page.Pan)
268 pageData, _ = sjson.Set(pageData, "zoom", page.Zoom)
269
270 // Sort the cards by their position so the serialization is more stable. (Otherwise, clicking on
271 // a Card adjusts the sort order, and therefore the order in which Cards are serialized.)
272 cards := append([]*Card{}, page.Cards...)
273
274 sort.Slice(cards, func(i, j int) bool {
275 return cards[i].Rect.Y < cards[j].Rect.Y || (cards[i].Rect.Y == cards[j].Rect.Y && cards[i].Rect.X < cards[j].Rect.X)
276 })
277
278 for _, card := range cards {
279 pageData, _ = sjson.SetRaw(pageData, "cards.-1", card.Serialize(true))
280 }
281
282 return pageData
283
284}
285
286func (page *Page) DeserializePageData(data string) {
287

Callers 5

CopyMethod · 0.45
NewUndoStateFunction · 0.45
SaveMethod · 0.45
OpenProjectFromFunction · 0.45
SaveSettingsFunction · 0.45

Calls 2

SetRawMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected