### TODO List: Local Storage and Data Management for .szf Data **Phase 1: Local Storage and SZF Serialization Foundation** - **Task: Create a Local Storage Service** - **Description**: Implement a service to abstract browser `localStorage` interactions for storing and retrieving string data. This will likely involve Blazor JavaScript interop. - **Files Affected/Created**: - `Services/ILocalStorageService.cs` (new interface) - `Services/LocalStorageService.cs` (new implementation) - **Context**: This service will be the low-level API for `localStorage`. It will handle saving and loading the raw .szf string content. - **Task: Develop SZF Object Converter/Serializer Helper** - **Description**: Create a utility class or static methods to convert `Character`, `Dataset`, and `CharacterTemplate` objects to and from their string representations. This should leverage the existing `PopulateFromMetadata`, `ParseSections`, `GenerateMetadata`, and `GenerateContent` methods within these classes. `.szf` - **Files Affected/Created**: - `Utils/SzfConverter.cs` (new static class) - **Context**: , , all have methods for processing SZF sections. This helper will orchestrate using those methods for full object serialization/deserialization to/from a single string. The will be crucial here for understanding the file structure. `Character.cs``Dataset.cs``CharacterTemplate.cs``szf-documentation.md` **Phase 2: SZF Data Repository and Retrieval Logic** - **Task: Design and Implement SZF Data Repository** - **Description**: Create a central service that manages all loaded entities (`Character`, `Dataset`, `CharacterTemplate`). It will use the `ILocalStorageService` to persist data and the `SzfConverter` to handle object-to-string conversions. `.szf` - **Files Affected/Created**: - `Services/ISzfDataRepository.cs` (new interface) - `Services/SzfDataRepository.cs` (new implementation) - **Context**: This is the core of the data management. It will hold collections of all available entities and provide methods for querying them. - **Task: Implement Retrieval Methods in `SzfDataRepository`** - **Description**: Add methods to `SzfDataRepository` for retrieving stored entities based on various criteria. - **Methods to Implement**: - `Save(T entity)`: Persists a `Character`, `Dataset`, or `CharacterTemplate` instance to local storage. - `LoadAllSzfEntities()`: Loads all known data (characters, datasets, templates) from local storage into the repository's in-memory collections on application startup. `.szf` - `GetCharacter(Guid guid, Version version)`: Retrieves a specific `Character` by its template GUID and version. - `GetDataset(Guid guid, Version version)`: Retrieves a specific `Dataset` by its GUID and version (from metadata). - `GetCharacterTemplate(Guid guid, Version version)`: Retrieves a specific `CharacterTemplate` by its GUID and version (from metadata). - `GetDatasetsByType(string datasetType)`: Retrieves all `Dataset` instances of a specific type (e.g., "items", "spells"). - `FindCharactersByName(string name)`: Finds characters by name (may return multiple). - `FindDatasetsByName(string name)`: Finds datasets by name (may return multiple). - `FindCharacterTemplatesByName(string name)`: Finds character templates by name (may return multiple). - **Files Affected/Created**: `Services/SzfDataRepository.cs` - **Context**: The explicitly mentions GUID, version, name, and type for data management. , , and all contain the necessary metadata fields (like `Guid`, `TemplateGuid`, `Version`, `Name`, `DatasetType`) to support these retrieval methods. `technical-specifications.md``Character.cs``Dataset.cs``CharacterTemplate.cs` **Phase 3: Integration and Relationship Resolution** - **Task: Integrate Data Loading with Core Models** - **Description**: Modify `Character`, `CharacterTemplate`, and `Dataset` classes, or create factory methods for them, to use the `SzfDataRepository` for loading. - **Files Affected/Created**: - `Character.cs` - `Dataset.cs` - `CharacterTemplate.cs` - **Context**: When a `Character` is loaded, it will need to retrieve its associated `CharacterTemplate`. When a `CharacterTemplate` is loaded, it will need to resolve its `RequiredDatasets`. This is where the relationships outlined in and come into play. The `DatasetReference` class in and `RequiredDatasetReference` in are key for this. `technical-specifications.md``szf-documentation.md``Dataset.cs``CharacterTemplate.cs` - **Task: Implement Relationship Resolution Logic** - **Description**: Ensure that when a `Character` is loaded, its `TemplateGuid` and `TemplateVersion` are used to load the correct `CharacterTemplate` from the `SzfDataRepository`. Similarly, ensure `CharacterTemplate` objects correctly resolve their `RequiredDatasets`. - **Files Affected/Created**: - `Character.cs` - `CharacterTemplate.cs` - `Services/SzfDataRepository.cs` (might need helper methods for resolution) - **Context**: The user explicitly mentioned "relationship between character>character_template>dataset". This task addresses that. The `DatasetReference` class will be crucial for parsing the strings from the .szf files and then using the `SzfDataRepository` to fetch the actual `Dataset` objects. `Name|GUID|Version`