Separate logic into Core and add a basic cli - #253
Open
ZehMatt wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors shared non-UI logic out of the Avalonia GUI into a new Core library and introduces a new Cli executable (locoobj) that reuses that core logic for headless/batch operations on Locomotion .dat objects.
Changes:
- Added
Coreproject for shared functionality (palette loading, object I/O, validation, image table import/export, batch operations). - Updated GUI and tests to reference
Coreand use core helpers instead of GUI-local implementations. - Added
Cliproject implementing several object/image operations via a minimal custom argument parser and batch processor.
Reviewed changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Tests.csproj | Adds Core reference for test compilation. |
| Tests/IdempotenceTests.cs | Switches palette loading to Core.PaletteMapLoader. |
| ObjectEditor.sln | Adds Core and Cli projects to the solution. |
| Gui/ViewModels/MainWindowViewModel.cs | Uses PaletteMapLoader instead of Avalonia asset loading for default palette. |
| Gui/ViewModels/Loco/ObjectEditorViewModel.cs | Moves validation/save logic to Core (ObjectValidation, ObjectFile). |
| Gui/ViewModels/Graphics/ImageViewModel.cs | Delegates crop-region computation to Core.GraphicsElementOperations. |
| Gui/ViewModels/Graphics/ImageTableViewModel.cs | Delegates sprites.json and image import/export work to Core.ImageTableIo. |
| Gui/Models/ObjectEditorContext.cs | Delegates image-table group config bootstrapping/loading to Core.ImageTableGroupsConfig. |
| Gui/Gui.csproj | Removes embedded resource previously used for image table grouping; adds Core reference. |
| Core/Validation/ObjectValidation.cs | New shared object validation and OpenGraphics rules validation. |
| Core/PaletteMapLoader.cs | New embedded-palette loader for GUI/tests/CLI reuse. |
| Core/Operations/ObjectOperations.cs | New shared image-table operations (strip/crop/offset edits). |
| Core/Operations/BatchProcessor.cs | New batch runner for applying operations across many .dat files. |
| Core/Objects/ObjectFile.cs | New shared object file load/save and .dat enumeration helpers. |
| Core/Objects/LocoObjectFile.cs | New shared “loaded file” record tying filename/header/object together. |
| Core/ImageTableGroupsConfig.cs | New shared loader/installer for image-table grouping config. |
| Core/Graphics/ImageTableIo.cs | New shared sprites.json + PNG import/export and offset-apply helpers. |
| Core/Graphics/GraphicsElementOperations.cs | New shared GraphicsElement image/data operations (decode/crop/offset edits). |
| Core/Graphics/GraphicsElementJson.cs | Moves sprites.json DTO into Core.Graphics. |
| Core/Core.csproj | New Core project definition; embeds palette and default grouping config. |
| Core/Assets/palette.png | Adds embedded default palette for non-GUI usage. |
| Cli/Program.cs | New locoobj entrypoint and command dispatch/help output. |
| Cli/ICommand.cs | New command interface for CLI subcommands. |
| Cli/ExitCodes.cs | Defines standard process exit codes for CLI. |
| Cli/ConsoleLogger.cs | Minimal ILogger implementation for console output. |
| Cli/Commands/ValidateCommand.cs | Adds validate command (optionally OpenGraphics rules). |
| Cli/Commands/StripImagesCommand.cs | Adds strip-images command using BatchProcessor + ObjectOperations. |
| Cli/Commands/ReencodeCommand.cs | Adds reencode command (rewrite with new Sawyer encoding). |
| Cli/Commands/OffsetsCommand.cs | Adds offsets command (zero/center/translate). |
| Cli/Commands/InfoCommand.cs | Adds info command (text or JSON summary of headers/images/strings). |
| Cli/Commands/ImportImagesCommand.cs | Adds import-images command (sprites.json + PNGs into a .dat). |
| Cli/Commands/ExportImagesCommand.cs | Adds export-images command (PNG export + sprites.json). |
| Cli/Commands/CropCommand.cs | Adds crop command (crop transparent borders and adjust offsets). |
| Cli/CommandLine.cs | New lightweight --option/--flag command line parser. |
| Cli/CommandContext.cs | Centralizes common option handling, input discovery, palette/encoding resolution, reporting. |
| Cli/Cli.csproj | New CLI project definition referencing Core and other shared projects. |
Comment on lines
+58
to
+73
| if (File.Exists(pathName)) | ||
| { | ||
| var jsonVersion = ImageTableGrouper.ReadImageTableGroupVersion(logger, pathName); | ||
| if (jsonVersion == null || jsonVersion < VersionHelpers.GetCurrentAppVersion()) | ||
| { | ||
| currentImageTableGroups = defaultImageTableGroups; | ||
| } | ||
| else | ||
| { | ||
| await File.WriteAllTextAsync(pathName, defaultImageTableGroups); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| await File.WriteAllTextAsync(pathName, defaultImageTableGroups); | ||
| } |
Comment on lines
+54
to
+65
| var header = file.DatInfo.S5Header; | ||
|
|
||
| SawyerStreamWriter.Save( | ||
| fileName, | ||
| objectName ?? header.Name, | ||
| objectSource ?? header.ObjectSource.Convert(header.Name, header.Checksum), | ||
| encoding ?? file.DatInfo.ObjectHeader.Encoding, | ||
| file.LocoObject, | ||
| logger, | ||
| allowSavingAsVanillaObject); | ||
|
|
||
| return true; |
Comment on lines
+17
to
+21
| if (!ReferenceEquals(element.Image, image)) | ||
| { | ||
| element.Image?.Dispose(); | ||
| element.Image = image; | ||
| } |
Comment on lines
+24
to
+28
| foreach (var element in group.GraphicsElements) | ||
| { | ||
| element.Image?.Dispose(); | ||
| element.Image = null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.