()
| 364 | } |
| 365 | |
| 366 | func (project *Project) Save() { |
| 367 | |
| 368 | project.SendMessage(NewMessage(MessageProjectSaveInitiated, nil, nil)) |
| 369 | |
| 370 | if globals.ReleaseMode == ReleaseModeDemo { |
| 371 | globals.EventLog.Log("Cannot save in demo mode of MasterPlan.", true) |
| 372 | return |
| 373 | } |
| 374 | |
| 375 | saveData, _ := sjson.Set("{}", "version", globals.Version.String()) |
| 376 | |
| 377 | saveData, _ = sjson.Set(saveData, "pan", project.Camera.TargetPosition) |
| 378 | saveData, _ = sjson.Set(saveData, "zoom", project.Camera.TargetZoom) |
| 379 | saveData, _ = sjson.Set(saveData, "currentPage", project.CurrentPage.ID) |
| 380 | |
| 381 | if cache := project.Properties.Get(ProjectCacheDirectory); cache.AsString() != "" { |
| 382 | cache.Set(project.PathToRelative(cache.AsString(), true)) |
| 383 | } |
| 384 | |
| 385 | saveData, _ = sjson.SetRaw(saveData, "properties", project.Properties.Serialize(true)) |
| 386 | |
| 387 | if cache := project.Properties.Get(ProjectCacheDirectory); cache.AsString() != "" { |
| 388 | cache.Set(project.PathToAbsolute(cache.AsString(), true)) |
| 389 | } |
| 390 | |
| 391 | savedImages := map[string]string{} |
| 392 | |
| 393 | pageData := "[" |
| 394 | |
| 395 | pagesToSave := []*Page{project.Pages[0]} |
| 396 | |
| 397 | if len(project.Pages) > 1 { |
| 398 | |
| 399 | for _, page := range project.Pages[1:] { |
| 400 | // If a page is an orphan, then we can just skip saving it as long as it doesn't have any cards |
| 401 | if page.Valid() { |
| 402 | pagesToSave = append(pagesToSave, page) |
| 403 | } else if project.HasOrphanPages { |
| 404 | |
| 405 | valid := false |
| 406 | |
| 407 | // Orphan |
| 408 | |
| 409 | for _, card := range page.Cards { |
| 410 | if card.Valid { |
| 411 | valid = true |
| 412 | break |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | // else, page.PointingSubpageCard points to a card that has been deleted; if it hadn't been deleted, then the page would be valid |
| 417 | if !valid { |
| 418 | continue |
| 419 | } |
| 420 | |
| 421 | pagesToSave = append(pagesToSave, page) |
| 422 | |
| 423 | } |
no test coverage detected