Save and open projects as JSON
A project is the whole setup as a small text file: the source paths, the effect chain with its params, the canvas and the seed. Reading and writing are driven by the effects' ParamSpecs rather than by whatever sits in a stage's values, so a new effect is saveable without touching this code, a key an effect does not declare is never written or read back, and an old project keeps the defaults for params that did not exist when it was saved. Paths under the project's own folder are written relative, so a folder of images and their project can be moved whole. src/core/project.cpp carries its own small JSON reader instead of a dependency, and names the line when a hand-edited file is wrong. The interface gets a header-bar menu: New, Open, Save, Save As, with Ctrl+N/O/S. The title shows the project name. Opening a project replaces the sources, discarding a decode still in flight rather than mixing it into the new project. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "core/chain.hpp"
|
||||
#include "core/params.hpp"
|
||||
|
||||
namespace effector {
|
||||
|
||||
// Everything needed to recreate a render: which images went in, the cascade
|
||||
// with its settings, the canvas and the seed. Deliberately no pixels — a
|
||||
// project is a small text file that points at the sources on disk.
|
||||
struct Project {
|
||||
std::vector<std::string> sources; // absolute paths
|
||||
std::vector<ChainStage> stages;
|
||||
int width = 1920;
|
||||
int height = 1080;
|
||||
std::optional<std::uint64_t> seed;
|
||||
};
|
||||
|
||||
// JSON, written for humans: two-space indent, one source path per line, and
|
||||
// the params of a stage spelled with the same keys the effect declares.
|
||||
// Source paths are written relative to `directory` when they live under it, so
|
||||
// a project folder can be moved or shared whole.
|
||||
std::string projectToJson(const Project& project, const std::string& directory = {});
|
||||
|
||||
// Throws EffectError on malformed JSON, an unknown effect or a missing chain.
|
||||
// Relative source paths are resolved against `directory`; params the effect
|
||||
// does not declare are dropped, and missing ones keep the effect's default.
|
||||
Project projectFromJson(const std::string& text, const std::string& directory = {});
|
||||
|
||||
// Both throw EffectError: the file is the user's, so failures are reported
|
||||
// rather than silently swallowed.
|
||||
void saveProject(const std::string& path, const Project& project);
|
||||
Project loadProject(const std::string& path);
|
||||
|
||||
} // namespace effector
|
||||
Reference in New Issue
Block a user